| Revision 351,
1.5 KB
checked in by xi, 4 years ago
(diff) |
|
Fixed emitting of invalid BOM for UTF-16.
|
| Line | |
|---|
| 1 | |
|---|
| 2 | import yaml |
|---|
| 3 | import test_constructor |
|---|
| 4 | import pprint |
|---|
| 5 | |
|---|
| 6 | def test_representer_types(code_filename, verbose=False): |
|---|
| 7 | test_constructor._make_objects() |
|---|
| 8 | for allow_unicode in [False, True]: |
|---|
| 9 | for encoding in ['utf-8', 'utf-16-be', 'utf-16-le']: |
|---|
| 10 | native1 = test_constructor._load_code(open(code_filename, 'rb').read()) |
|---|
| 11 | native2 = None |
|---|
| 12 | try: |
|---|
| 13 | output = yaml.dump(native1, Dumper=test_constructor.MyDumper, |
|---|
| 14 | allow_unicode=allow_unicode, encoding=encoding) |
|---|
| 15 | native2 = yaml.load(output, Loader=test_constructor.MyLoader) |
|---|
| 16 | try: |
|---|
| 17 | if native1 == native2: |
|---|
| 18 | continue |
|---|
| 19 | except TypeError: |
|---|
| 20 | pass |
|---|
| 21 | value1 = test_constructor._serialize_value(native1) |
|---|
| 22 | value2 = test_constructor._serialize_value(native2) |
|---|
| 23 | if verbose: |
|---|
| 24 | print "SERIALIZED NATIVE1:" |
|---|
| 25 | print value1 |
|---|
| 26 | print "SERIALIZED NATIVE2:" |
|---|
| 27 | print value2 |
|---|
| 28 | assert value1 == value2, (native1, native2) |
|---|
| 29 | finally: |
|---|
| 30 | if verbose: |
|---|
| 31 | print "NATIVE1:" |
|---|
| 32 | pprint.pprint(native1) |
|---|
| 33 | print "NATIVE2:" |
|---|
| 34 | pprint.pprint(native2) |
|---|
| 35 | print "OUTPUT:" |
|---|
| 36 | print output |
|---|
| 37 | |
|---|
| 38 | test_representer_types.unittest = ['.code'] |
|---|
| 39 | |
|---|
| 40 | if __name__ == '__main__': |
|---|
| 41 | import test_appliance |
|---|
| 42 | test_appliance.run(globals()) |
|---|
| 43 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.