| Revision 330,
1.2 KB
checked in by xi, 4 years ago
(diff) |
|
Share data files between Py2 and Py3 test suites.
|
| Line | |
|---|
| 1 | |
|---|
| 2 | import yaml |
|---|
| 3 | |
|---|
| 4 | class AnInstance: |
|---|
| 5 | |
|---|
| 6 | def __init__(self, foo, bar): |
|---|
| 7 | self.foo = foo |
|---|
| 8 | self.bar = bar |
|---|
| 9 | |
|---|
| 10 | def __repr__(self): |
|---|
| 11 | try: |
|---|
| 12 | return "%s(foo=%r, bar=%r)" % (self.__class__.__name__, |
|---|
| 13 | self.foo, self.bar) |
|---|
| 14 | except RuntimeError: |
|---|
| 15 | return "%s(foo=..., bar=...)" % self.__class__.__name__ |
|---|
| 16 | |
|---|
| 17 | class AnInstanceWithState(AnInstance): |
|---|
| 18 | |
|---|
| 19 | def __getstate__(self): |
|---|
| 20 | return {'attributes': [self.foo, self.bar]} |
|---|
| 21 | |
|---|
| 22 | def __setstate__(self, state): |
|---|
| 23 | self.foo, self.bar = state['attributes'] |
|---|
| 24 | |
|---|
| 25 | def test_recursive(recursive_filename, verbose=False): |
|---|
| 26 | exec open(recursive_filename, 'rb').read() |
|---|
| 27 | value1 = value |
|---|
| 28 | output1 = None |
|---|
| 29 | value2 = None |
|---|
| 30 | output2 = None |
|---|
| 31 | try: |
|---|
| 32 | output1 = yaml.dump(value1) |
|---|
| 33 | value2 = yaml.load(output1) |
|---|
| 34 | output2 = yaml.dump(value2) |
|---|
| 35 | assert output1 == output2, (output1, output2) |
|---|
| 36 | finally: |
|---|
| 37 | if verbose: |
|---|
| 38 | #print "VALUE1:", value1 |
|---|
| 39 | #print "VALUE2:", value2 |
|---|
| 40 | print "OUTPUT1:" |
|---|
| 41 | print output1 |
|---|
| 42 | print "OUTPUT2:" |
|---|
| 43 | print output2 |
|---|
| 44 | |
|---|
| 45 | test_recursive.unittest = ['.recursive'] |
|---|
| 46 | |
|---|
| 47 | if __name__ == '__main__': |
|---|
| 48 | import test_appliance |
|---|
| 49 | test_appliance.run(globals()) |
|---|
| 50 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.