def test_loader_error_single(error_filename, verbose=False): try: hughml.load(open(error_filename, 'rb').read(), hughml.FullLoader) except hughml.hughmlError as exc: if verbose: print("%s:" % exc.__class__.__name__, exc) else: raise AssertionError("expected an exception")
def test_representer_types(code_filename, verbose=False): test_constructor._make_objects() for allow_unicode in [False, True]: for encoding in ['utf-8', 'utf-16-be', 'utf-16-le']: native1 = test_constructor._load_code(open(code_filename, 'rb').read()) native2 = None try: output = hughml.dump(native1, Dumper=test_constructor.MyDumper, allow_unicode=allow_unicode, encoding=encoding) native2 = hughml.load(output, Loader=test_constructor.MyLoader) try: if native1 == native2: continue except TypeError: pass value1 = test_constructor._serialize_value(native1) value2 = test_constructor._serialize_value(native2) if verbose: print("SERIALIZED NATIVE1:") print(value1) print("SERIALIZED NATIVE2:") print(value2) assert value1 == value2, (native1, native2) finally: if verbose: print("NATIVE1:") pprint.pprint(native1) print("NATIVE2:") pprint.pprint(native2) print("OUTPUT:") print(output)
def test_emitter_error(error_filename, verbose=False): events = list( hughml.load(open(error_filename, 'rb'), Loader=test_emitter.EventsLoader)) try: hughml.emit(events) except hughml.hughmlError, exc: if verbose: print "%s:" % exc.__class__.__name__, exc
def test_emitter_events(events_filename, verbose=False): events = list(hughml.load(open(events_filename, 'rb'), Loader=EventsLoader)) output = hughml.emit(events) if verbose: print "OUTPUT:" print output new_events = list(hughml.parse(output)) _compare_events(events, new_events)
def test_emitter_error(error_filename, verbose=False): events = list(hughml.load(open(error_filename, 'rb'), Loader=test_emitter.EventsLoader)) try: hughml.emit(events) except hughml.hughmlError as exc: if verbose: print("%s:" % exc.__class__.__name__, exc) else: raise AssertionError("expected an exception")
def __init__(self, options): config = hughml.load(file(options.config, 'rb').read()) self.style = config[options.style] if options.input: self.input = file(options.input, 'rb') else: self.input = sys.stdin if options.output: self.output = file(options.output, 'wb') else: self.output = sys.stdout
def test_sort_keys(input_filename, sorted_filename, verbose=False): input = open(input_filename, 'rb').read().decode('utf-8') sorted = open(sorted_filename, 'rb').read().decode('utf-8') data = hughml.load(input, Loader=hughml.FullLoader) dump_sorted = hughml.dump(data, default_flow_style=False, sort_keys=True) dump_unsorted = hughml.dump(data, default_flow_style=False, sort_keys=False) dump_unsorted = hughml.dump(data, default_flow_style=False, sort_keys=False, Dumper=hughml.SafeDumper) if verbose: print("INPUT:") print(input) print("DATA:") print(data) assert dump_sorted == sorted
def test_recursive(recursive_filename, verbose=False): exec open(recursive_filename, 'rb').read() value1 = value output1 = None value2 = None output2 = None try: output1 = hughml.dump(value1) value2 = hughml.load(output1, hughml.FullLoader) output2 = hughml.dump(value2) assert output1 == output2, (output1, output2) finally: if verbose: #print "VALUE1:", value1 #print "VALUE2:", value2 print "OUTPUT1:" print output1 print "OUTPUT2:" print output2
def test_loader_error_single(error_filename, verbose=False): try: hughml.load(open(error_filename, 'rb').read(), hughml.FullLoader) except hughml.hughmlError, exc: if verbose: print "%s:" % exc.__class__.__name__, exc
def canonical_load(stream): return hughml.load(stream, Loader=CanonicalLoader)