Changeset 995 for tester/tester.py


Ignore:
Timestamp:
07/09/20 16:35:19 (4 years ago)
Author:
Maciej Komosinski
Message:

Added support for utf-8 in tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester/tester.py

    r994 r995  
    8989        else:
    9090                print("\r", globals.ANSI_SETRED + " FAIL\7" + globals.ANSI_RESET)
    91                 print(compare.result)
     91                try:
     92                        print(compare.result)
     93                except UnicodeEncodeError:
     94                        print(compare.result.encode("utf-8")) #only encode as utf8 when it is actually used, but this looks incorrect and perhaps should not be needed if the console supports utf8?
     95                        #sys.stdout.buffer.write(compare.result.encode("utf-8")) #prints nothing (on cygwin)
    9296                failed_result_filename = compare.list2_file + was_compared_to
    9397                if failed_result_filename == '':
    9498                        failed_result_filename = '_test'
    95                 f = open(os.path.join(globals.THISDIR, failed_result_filename + '.Failed-output'), 'w')  # files are easier to compare than stdout
     99                f = open(os.path.join(globals.THISDIR, failed_result_filename + '.Failed-output'), 'w',  encoding='utf8')  # files are easier to compare than stdout
    96100                print('\n'.join(jest)+'\n', end="", file=f) # not sure why one last empty line is always lost (or one too much is expected?), adding here...
    97                 f = open(os.path.join(globals.THISDIR, failed_result_filename + '.Failed-goal'), 'w')  # files are easier to compare than stdout
     101                f = open(os.path.join(globals.THISDIR, failed_result_filename + '.Failed-goal'), 'w',  encoding='utf8')  # files are easier to compare than stdout
    98102                print('\n'.join(goal), end="", file=f)
    99103        return compare.equal
     
    173177
    174178
    175 def print_exception():
     179def print_exception(exc):
    176180        print("\n"+("-"*60),'begin exception')
     181        print(exc) # some exceptions have an empty traceback, they only provide one-line exception name
    177182        traceback.print_exc()
    178183        print("-"*60,'end exception')
     
    223228        globals.init_colors(args)
    224229
    225         fin = open(os.path.join(globals.THISDIR, args.file))
     230        fin = open(os.path.join(globals.THISDIR, args.file), encoding='utf8')
    226231        reset_values()
    227232        exe_prog = "default"  # no longer in reset_values (exe: persists across tests)
     
    264269                                try:
    265270                                        contents = []
    266                                         with open(os.path.join(globals.FILESDIR, line[1]), 'r') as main_test_filename:
     271                                        with open(os.path.join(globals.FILESDIR, line[1]), 'r', encoding='utf8') as main_test_filename:
    267272                                                for line in main_test_filename:
    268273                                                        contents.append(globals.stripEOL(line))
    269274                                        ok = compare(contents, outfile, '_file') # +line[1]
    270275                                except Exception as e: # could also 'raise' for some types of exceptions if we wanted
    271                                         print_exception()
     276                                        print_exception(e)
    272277                                        ok = 0
    273278                                tests_failed += int(not ok)
     
    279284                                        ok = test(args, test_name, input_text, output_net, output_msg, exe_prog, exeargs)
    280285                                except Exception as e: # could also 'raise' for some types of exceptions if we wanted
    281                                         print_exception()
     286                                        print_exception(e)
    282287                                        ok = 0
    283288                                tests_failed += int(not ok)
Note: See TracChangeset for help on using the changeset viewer.