diff options
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_multiprocessing.py | 32 | ||||
-rw-r--r-- | Lib/test/test_unittest.py | 23 |
2 files changed, 54 insertions, 1 deletions
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index 69309ba..100738e 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -1832,7 +1832,37 @@ class OtherTest(unittest.TestCase): multiprocessing.connection.answer_challenge, _FakeConnection(), b'abc') -testcases_other = [OtherTest, TestInvalidHandle] +# +# Test Manager.start()/Pool.__init__() initializer feature - see issue 5585 +# + +def initializer(ns): + ns.test += 1 + +class TestInitializers(unittest.TestCase): + def setUp(self): + self.mgr = multiprocessing.Manager() + self.ns = self.mgr.Namespace() + self.ns.test = 0 + + def tearDown(self): + self.mgr.shutdown() + + def test_manager_initializer(self): + m = multiprocessing.managers.SyncManager() + self.assertRaises(TypeError, m.start, 1) + m.start(initializer, (self.ns,)) + self.assertEqual(self.ns.test, 1) + m.shutdown() + + def test_pool_initializer(self): + self.assertRaises(TypeError, multiprocessing.Pool, initializer=1) + p = multiprocessing.Pool(1, initializer, (self.ns,)) + p.close() + p.join() + self.assertEqual(self.ns.test, 1) + +testcases_other = [OtherTest, TestInvalidHandle, TestInitializers] # # diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py index aaa3dc5..d0d2049 100644 --- a/Lib/test/test_unittest.py +++ b/Lib/test/test_unittest.py @@ -2311,6 +2311,16 @@ class Test_TestCase(TestCase, TestEquality, TestHashing): # from this TestCase instance but since its a local nothing else # will ever notice that. + def testAssertIs(self): + thing = object() + self.assertIs(thing, thing) + self.assertRaises(self.failureException, self.assertIs, thing, object()) + + def testAssertIsNot(self): + thing = object() + self.assertIsNot(thing, object()) + self.assertRaises(self.failureException, self.assertIsNot, thing, thing) + def testAssertIn(self): animals = {'monkey': 'banana', 'cow': 'grass', 'seal': 'fish'} @@ -2454,6 +2464,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing): # Test that sequences of unhashable objects can be tested for sameness: self.assertSameElements([[1, 2], [3, 4]], [[3, 4], [1, 2]]) + self.assertSameElements([{'a': 1}, {'b': 2}], [{'b': 2}, {'a': 1}]) self.assertRaises(self.failureException, self.assertSameElements, [[1]], [[2]]) @@ -2988,6 +2999,18 @@ class TestLongMessage(TestCase): "^unexpectedly None$", "^unexpectedly None : oops$"]) + def testAssertIs(self): + self.assertMessages('assertIs', (None, 'foo'), + ["^None is not 'foo'$", "^oops$", + "^None is not 'foo'$", + "^None is not 'foo' : oops$"]) + + def testAssertIsNot(self): + self.assertMessages('assertIsNot', (None, None), + ["^unexpectedly identical: None$", "^oops$", + "^unexpectedly identical: None$", + "^unexpectedly identical: None : oops$"]) + ###################################################################### ## Main |