diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-04-14 12:23:50 +0100 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-04-14 12:23:50 +0100 |
commit | 5daa4a0a673c122bd3ba8e7582bad2e02d141d8a (patch) | |
tree | a72838004614291df3ef8d57b9619b1cd175bf80 | |
parent | f658411128c16d8e50d451a7adde3e830339cb6c (diff) | |
download | mock-5daa4a0a673c122bd3ba8e7582bad2e02d141d8a.tar.gz |
Committed failing test for pickling
-rw-r--r-- | tests/testmock.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/testmock.py b/tests/testmock.py index 0517eac..1f3bdf9 100644 --- a/tests/testmock.py +++ b/tests/testmock.py @@ -7,6 +7,7 @@ from tests.support import ( ) import copy +import pickle import sys import mock @@ -37,6 +38,15 @@ class Iter(object): __next__ = next +class Subclass(MagicMock): + pass + + +class Thing(object): + attribute = 6 + foo = 'bar' + + class MockTest(unittest2.TestCase): @@ -1311,5 +1321,21 @@ class MockTest(unittest2.TestCase): self.assertIsInstance(mock, int) + @unittest2.expectedFailure + def test_pickle(self): + for Klass in (MagicMock, Mock, Subclass, NonCallableMagicMock): + mock = Klass(name='foo', attribute=3) + mock.foo(1, 2, 3) + data = pickle.dumps(mock) + new = pickle.loads(data) + + new.foo.assert_called_once_with(1, 2, 3) + self.assertFalse(new.called) + self.assertTrue(is_instance(new, Klass)) + self.assertIsInstance(new, Thing) + self.assertIn('name="foo"', repr(new)) + self.assertEqual(new.attribute, 3) + + if __name__ == '__main__': unittest2.main() |