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