diff options
| author | Clark Willison <clarkgwillison@gmail.com> | 2020-07-15 12:00:47 -0700 |
|---|---|---|
| committer | Clark Willison <clarkgwillison@gmail.com> | 2020-07-15 12:00:47 -0700 |
| commit | 0cd5d5c1f45d652a693e1a221d0a125eece93c58 (patch) | |
| tree | 6e6a1ed81bd154c67a63334d22f49700eada61b7 /pint/testsuite/test_errors.py | |
| parent | 4b7171b2f899e05ca32a85eaafcd256173de303c (diff) | |
| parent | 03be0544b749ee55fbd1253d18e2a84151dce716 (diff) | |
| download | pint-0cd5d5c1f45d652a693e1a221d0a125eece93c58.tar.gz | |
Merge branch 'master' into log-units WIP branch
fix merge conflicts with upstream master, and bring
this branch up-to-date with present work
Diffstat (limited to 'pint/testsuite/test_errors.py')
| -rw-r--r-- | pint/testsuite/test_errors.py | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/pint/testsuite/test_errors.py b/pint/testsuite/test_errors.py index 57f6633..c89677e 100644 --- a/pint/testsuite/test_errors.py +++ b/pint/testsuite/test_errors.py @@ -117,24 +117,28 @@ class TestErrors(BaseTestCase): ureg = UnitRegistry(filename=None) ureg.define("foo = [bar]") ureg.define("bar = 2 foo") - pik = pickle.dumps(ureg.Quantity("1 foo")) - with self.assertRaises(UndefinedUnitError): - pickle.loads(pik) q1 = ureg.Quantity("1 foo") q2 = ureg.Quantity("1 bar") - for ex in [ - DefinitionSyntaxError("foo", filename="a.txt", lineno=123), - RedefinitionError("foo", "bar"), - UndefinedUnitError("meter"), - DimensionalityError("a", "b", "c", "d", extra_msg=": msg"), - OffsetUnitCalculusError(Quantity("1 kg")._units, Quantity("1 s")._units), - OffsetUnitCalculusError(q1._units, q2._units), - ]: - with self.subTest(etype=type(ex)): - # assert False, ex.__reduce__() - ex2 = pickle.loads(pickle.dumps(ex)) - assert type(ex) is type(ex2) - self.assertEqual(ex.args, ex2.args) - self.assertEqual(ex.__dict__, ex2.__dict__) - self.assertEqual(str(ex), str(ex2)) + for protocol in range(pickle.HIGHEST_PROTOCOL + 1): + for ex in [ + DefinitionSyntaxError("foo", filename="a.txt", lineno=123), + RedefinitionError("foo", "bar"), + UndefinedUnitError("meter"), + DimensionalityError("a", "b", "c", "d", extra_msg=": msg"), + OffsetUnitCalculusError( + Quantity("1 kg")._units, Quantity("1 s")._units + ), + OffsetUnitCalculusError(q1._units, q2._units), + ]: + with self.subTest(protocol=protocol, etype=type(ex)): + pik = pickle.dumps(ureg.Quantity("1 foo"), protocol) + with self.assertRaises(UndefinedUnitError): + pickle.loads(pik) + + # assert False, ex.__reduce__() + ex2 = pickle.loads(pickle.dumps(ex, protocol)) + assert type(ex) is type(ex2) + self.assertEqual(ex.args, ex2.args) + self.assertEqual(ex.__dict__, ex2.__dict__) + self.assertEqual(str(ex), str(ex2)) |
