• Home
  • Raw
  • Download

Lines Matching refs:self

33         def runTest(self): pass  argument
34 def test1(self): pass argument
37 def test2(self): pass argument
42 def __init__(self, events): argument
43 super(Test.LoggingTestCase, self).__init__('test')
44 self.events = events
46 def setUp(self): argument
47 self.events.append('setUp')
49 def test(self): argument
50 self.events.append('test')
52 def tearDown(self): argument
53 self.events.append('tearDown')
82 def test_init__no_test_name(self): argument
84 def runTest(self): raise MyException() argument
85 def test(self): pass argument
87 self.assertEqual(Test().id()[-13:], '.Test.runTest')
96 with self.assertRaises(AttributeError):
103 def test_init__test_name__valid(self): argument
105 def runTest(self): raise MyException() argument
106 def test(self): pass argument
108 self.assertEqual(Test('test').id()[-10:], '.Test.test')
114 def test_init__test_name__invalid(self): argument
116 def runTest(self): raise MyException() argument
117 def test(self): pass argument
124 self.fail("Failed to raise ValueError")
128 def test_countTestCases(self): argument
130 def test(self): pass argument
132 self.assertEqual(Foo('test').countTestCases(), 1)
138 def test_defaultTestResult(self): argument
140 def runTest(self): argument
144 self.assertEqual(type(result), unittest.TestResult)
153 def test_run_call_order__error_in_setUp(self): argument
158 def setUp(self): argument
159 super(Foo, self).setUp()
164 self.assertEqual(events, expected)
167 def test_run_call_order__error_in_setUp_default_result(self): argument
171 def defaultTestResult(self): argument
172 return LoggingResult(self.events)
174 def setUp(self): argument
175 super(Foo, self).setUp()
181 self.assertEqual(events, expected)
190 def test_run_call_order__error_in_test(self): argument
195 def test(self): argument
196 super(Foo, self).test()
202 self.assertEqual(events, expected)
206 def test_run_call_order__error_in_test_default_result(self): argument
210 def defaultTestResult(self): argument
211 return LoggingResult(self.events)
213 def test(self): argument
214 super(Foo, self).test()
220 self.assertEqual(events, expected)
229 def test_run_call_order__failure_in_test(self): argument
234 def test(self): argument
235 super(Foo, self).test()
236 self.fail('raised by Foo.test')
241 self.assertEqual(events, expected)
244 def test_run_call_order__failure_in_test_default_result(self): argument
247 def defaultTestResult(self): argument
248 return LoggingResult(self.events)
249 def test(self): argument
250 super(Foo, self).test()
251 self.fail('raised by Foo.test')
257 self.assertEqual(events, expected)
266 def test_run_call_order__error_in_tearDown(self): argument
271 def tearDown(self): argument
272 super(Foo, self).tearDown()
278 self.assertEqual(events, expected)
281 def test_run_call_order__error_in_tearDown_default_result(self): argument
284 def defaultTestResult(self): argument
285 return LoggingResult(self.events)
286 def tearDown(self): argument
287 super(Foo, self).tearDown()
294 self.assertEqual(events, expected)
298 def test_run_call_order_default_result(self): argument
301 def defaultTestResult(self): argument
303 def test(self): argument
308 def _check_call_order__subtests(self, result, events, expected_events): argument
310 def test(self): argument
311 super(Foo, self).test()
313 with self.subTest(i=i):
315 self.fail('failure')
317 with self.subTest(j=j):
330 self.assertEqual(events, expected_events)
332 def test_run_call_order__subtests(self): argument
339 self._check_call_order__subtests(result, events, expected)
341 def test_run_call_order__subtests_legacy(self): argument
348 self._check_call_order__subtests(result, events, expected)
350 def _check_call_order__subtests_success(self, result, events, expected_events): argument
352 def test(self): argument
353 super(Foo, self).test()
355 with self.subTest(i=i):
357 with self.subTest(j=j):
361 self.assertEqual(events, expected_events)
363 def test_run_call_order__subtests_success(self): argument
371 self._check_call_order__subtests_success(result, events, expected)
373 def test_run_call_order__subtests_success_legacy(self): argument
379 self._check_call_order__subtests_success(result, events, expected)
381 def test_run_call_order__subtests_failfast(self): argument
387 def test(self): argument
388 super(Foo, self).test()
389 with self.subTest(i=1):
390 self.fail('failure')
391 with self.subTest(i=2):
392 self.fail('failure')
393 self.fail('failure')
398 self.assertEqual(events, expected)
400 def test_subtests_failfast(self): argument
405 def test_a(self): argument
406 with self.subTest():
410 def test_b(self): argument
411 with self.subTest():
413 with self.subTest():
414 self.fail('failure')
417 def test_c(self): argument
426 self.assertEqual(events, expected)
428 def test_subtests_debug(self): argument
433 def test_a(self): argument
435 with self.subTest():
440 self.assertEqual(events, ['test case', 'subtest 1'])
447 def test_failureException__default(self): argument
449 def test(self): argument
452 self.assertIs(Foo('test').failureException, AssertionError)
460 def test_failureException__subclassing__explicit_raise(self): argument
465 def test(self): argument
470 self.assertIs(Foo('test').failureException, RuntimeError)
475 self.assertEqual(events, expected)
483 def test_failureException__subclassing__implicit_raise(self): argument
488 def test(self): argument
489 self.fail("foo")
493 self.assertIs(Foo('test').failureException, RuntimeError)
498 self.assertEqual(events, expected)
501 def test_setUp(self): argument
503 def runTest(self): argument
510 def test_tearDown(self): argument
512 def runTest(self): argument
524 def test_id(self): argument
526 def runTest(self): argument
529 self.assertIsInstance(Foo().id(), str)
536 def test_run__uses_defaultTestResult(self): argument
541 def test(self): argument
544 def defaultTestResult(self): argument
550 self.assertIs(result, defaultResult)
553 self.assertEqual(events, expected)
557 def test_run__returns_given_result(self): argument
560 def test(self): argument
566 self.assertIs(retval, result)
571 def test_call__invoking_an_instance_delegates_to_run(self): argument
576 def test(self): argument
579 def run(self, result): argument
580 self.assertIs(result, resultIn)
585 self.assertIs(retval, resultOut)
588 def testShortDescriptionWithoutDocstring(self): argument
589 self.assertIsNone(self.shortDescription())
593 def testShortDescriptionWithOneLineDocstring(self): argument
595 self.assertEqual(
596 self.shortDescription(),
601 def testShortDescriptionWithMultiLineDocstring(self): argument
608 self.assertEqual(
609 self.shortDescription(),
613 def testAddTypeEqualityFunc(self): argument
617 self.assertFalse(s1 == s2)
620 self.addTypeEqualityFunc(SadSnake, AllSnakesCreatedEqual)
621 self.assertEqual(s1, s2)
626 def testAssertIs(self): argument
628 self.assertIs(thing, thing)
629 self.assertRaises(self.failureException, self.assertIs, thing, object())
631 def testAssertIsNot(self): argument
633 self.assertIsNot(thing, object())
634 self.assertRaises(self.failureException, self.assertIsNot, thing, thing)
636 def testAssertIsInstance(self): argument
638 self.assertIsInstance(thing, list)
639 self.assertRaises(self.failureException, self.assertIsInstance,
642 def testAssertNotIsInstance(self): argument
644 self.assertNotIsInstance(thing, dict)
645 self.assertRaises(self.failureException, self.assertNotIsInstance,
648 def testAssertIn(self): argument
651 self.assertIn('a', 'abc')
652 self.assertIn(2, [1, 2, 3])
653 self.assertIn('monkey', animals)
655 self.assertNotIn('d', 'abc')
656 self.assertNotIn(0, [1, 2, 3])
657 self.assertNotIn('otter', animals)
659 self.assertRaises(self.failureException, self.assertIn, 'x', 'abc')
660 self.assertRaises(self.failureException, self.assertIn, 4, [1, 2, 3])
661 self.assertRaises(self.failureException, self.assertIn, 'elephant',
664 self.assertRaises(self.failureException, self.assertNotIn, 'c', 'abc')
665 self.assertRaises(self.failureException, self.assertNotIn, 1, [1, 2, 3])
666 self.assertRaises(self.failureException, self.assertNotIn, 'cow',
669 def testAssertDictContainsSubset(self): argument
673 self.assertDictContainsSubset({}, {})
674 self.assertDictContainsSubset({}, {'a': 1})
675 self.assertDictContainsSubset({'a': 1}, {'a': 1})
676 self.assertDictContainsSubset({'a': 1}, {'a': 1, 'b': 2})
677 self.assertDictContainsSubset({'a': 1, 'b': 2}, {'a': 1, 'b': 2})
679 with self.assertRaises(self.failureException):
680 self.assertDictContainsSubset({1: "one"}, {})
682 with self.assertRaises(self.failureException):
683 self.assertDictContainsSubset({'a': 2}, {'a': 1})
685 with self.assertRaises(self.failureException):
686 self.assertDictContainsSubset({'c': 1}, {'a': 1})
688 with self.assertRaises(self.failureException):
689 self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1})
691 with self.assertRaises(self.failureException):
692 self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1})
696 with self.assertRaises(self.failureException):
697 self.assertDictContainsSubset({'foo': one}, {'foo': '\uFFFD'})
699 def testAssertEqual(self): argument
710 self.assertEqual(a, b)
711 except self.failureException:
712 self.fail('assertEqual(%r, %r) failed' % (a, b))
714 self.assertEqual(a, b, msg='foo')
715 except self.failureException:
716 self.fail('assertEqual(%r, %r) with msg= failed' % (a, b))
718 self.assertEqual(a, b, 'foo')
719 except self.failureException:
720 self.fail('assertEqual(%r, %r) with third parameter failed' %
730 self.assertRaises(self.failureException, self.assertEqual, a, b)
731 self.assertRaises(self.failureException, self.assertEqual, a, b,
733 self.assertRaises(self.failureException, self.assertEqual, a, b,
736 def testEquality(self): argument
737 self.assertListEqual([], [])
738 self.assertTupleEqual((), ())
739 self.assertSequenceEqual([], ())
743 self.assertRaises(unittest.TestCase.failureException,
744 self.assertListEqual, a, b)
745 self.assertRaises(unittest.TestCase.failureException,
746 self.assertListEqual, tuple(a), tuple(b))
747 self.assertRaises(unittest.TestCase.failureException,
748 self.assertSequenceEqual, a, tuple(b))
751 self.assertListEqual(a, b)
752 self.assertTupleEqual(tuple(a), tuple(b))
753 self.assertSequenceEqual(a, tuple(b))
754 self.assertSequenceEqual(tuple(a), b)
756 self.assertRaises(self.failureException, self.assertListEqual,
758 self.assertRaises(self.failureException, self.assertTupleEqual,
760 self.assertRaises(self.failureException, self.assertListEqual, None, b)
761 self.assertRaises(self.failureException, self.assertTupleEqual, None,
763 self.assertRaises(self.failureException, self.assertSequenceEqual,
765 self.assertRaises(self.failureException, self.assertListEqual, 1, 1)
766 self.assertRaises(self.failureException, self.assertTupleEqual, 1, 1)
767 self.assertRaises(self.failureException, self.assertSequenceEqual,
770 self.assertDictEqual({}, {})
774 self.assertRaises(unittest.TestCase.failureException,
775 self.assertDictEqual, c, d)
778 self.assertDictEqual(c, d)
781 self.assertRaises(unittest.TestCase.failureException,
782 self.assertDictEqual, c, d, 'These are unequal')
784 self.assertRaises(self.failureException, self.assertDictEqual, None, d)
785 self.assertRaises(self.failureException, self.assertDictEqual, [], d)
786 self.assertRaises(self.failureException, self.assertDictEqual, 1, 1)
788 def testAssertSequenceEqualMaxDiff(self): argument
789 self.assertEqual(self.maxDiff, 80*8)
797 self.maxDiff = len(diff)//2
800 self.assertSequenceEqual(seq1, seq2)
801 except self.failureException as e:
804 self.fail('assertSequenceEqual did not fail.')
805 self.assertLess(len(msg), len(diff))
806 self.assertIn(omitted, msg)
808 self.maxDiff = len(diff) * 2
810 self.assertSequenceEqual(seq1, seq2)
811 except self.failureException as e:
814 self.fail('assertSequenceEqual did not fail.')
815 self.assertGreater(len(msg), len(diff))
816 self.assertNotIn(omitted, msg)
818 self.maxDiff = None
820 self.assertSequenceEqual(seq1, seq2)
821 except self.failureException as e:
824 self.fail('assertSequenceEqual did not fail.')
825 self.assertGreater(len(msg), len(diff))
826 self.assertNotIn(omitted, msg)
828 def testTruncateMessage(self): argument
829 self.maxDiff = 1
830 message = self._truncateMessage('foo', 'bar')
832 self.assertEqual(message, 'foo' + omitted)
834 self.maxDiff = None
835 message = self._truncateMessage('foo', 'bar')
836 self.assertEqual(message, 'foobar')
838 self.maxDiff = 4
839 message = self._truncateMessage('foo', 'bar')
840 self.assertEqual(message, 'foobar')
842 def testAssertDictEqualTruncates(self): argument
849 except self.failureException as e:
850 self.assertEqual(str(e), 'foo')
852 self.fail('assertDictEqual did not fail')
854 def testAssertMultiLineEqualTruncates(self): argument
861 except self.failureException as e:
862 self.assertEqual(str(e), 'foo')
864 self.fail('assertMultiLineEqual did not fail')
866 def testAssertEqual_diffThreshold(self): argument
868 self.assertEqual(self._diffThreshold, 2**16)
870 self.maxDiff = None
873 old_threshold = self._diffThreshold
874 self._diffThreshold = 2**5
875 self.addCleanup(lambda: setattr(self, '_diffThreshold', old_threshold))
879 with self.assertRaises(self.failureException) as cm:
880 self.assertEqual(s + 'a', s + 'b')
881 self.assertIn('^', str(cm.exception))
882 self.assertEqual(s + 'a', s + 'a')
891 old_truncate = self._truncateMessage
892 self._truncateMessage = explodingTruncation
893 self.addCleanup(lambda: setattr(self, '_truncateMessage', old_truncate))
896 with self.assertRaises(self.failureException) as cm:
897 self.assertEqual(s1, s2)
898 self.assertNotIn('^', str(cm.exception))
899 self.assertEqual(str(cm.exception), '%r != %r' % (s1, s2))
900 self.assertEqual(s + 'a', s + 'a')
902 def testAssertEqual_shorten(self): argument
904 old_threshold = self._diffThreshold
905 self._diffThreshold = 0
906 self.addCleanup(lambda: setattr(self, '_diffThreshold', old_threshold))
910 with self.assertRaises(self.failureException) as cm:
911 self.assertEqual(s1, s2)
913 self.assertEqual(str(cm.exception), "'%sa' != '%sb'" % (c, c))
914 self.assertEqual(s + 'a', s + 'a')
918 with self.assertRaises(self.failureException) as cm:
919 self.assertEqual(s1, s2)
921 self.assertEqual(str(cm.exception), "'%sa%s' != '%sb%s'" % (c, p, c, p))
925 with self.assertRaises(self.failureException) as cm:
926 self.assertEqual(s1, s2)
929 self.assertEqual(str(cm.exception), "'%sa%s' != '%sb%s'" % (c, d, c, d))
931 def testAssertCountEqual(self): argument
933 self.assertCountEqual([1, 2, 3], [3, 2, 1])
934 self.assertCountEqual(['foo', 'bar', 'baz'], ['bar', 'baz', 'foo'])
935 self.assertCountEqual([a, a, 2, 2, 3], (a, 2, 3, a, 2))
936 self.assertCountEqual([1, "2", "a", "a"], ["a", "2", True, "a"])
937 self.assertRaises(self.failureException, self.assertCountEqual,
939 self.assertRaises(self.failureException, self.assertCountEqual,
941 self.assertRaises(self.failureException, self.assertCountEqual,
943 self.assertRaises(self.failureException, self.assertCountEqual,
945 self.assertRaises(self.failureException, self.assertCountEqual,
949 self.assertCountEqual([[1, 2], [3, 4], 0], [False, [3, 4], [1, 2]])
951 self.assertCountEqual(iter([1, 2, [], 3, 4]),
955 self.assertRaises(self.failureException, self.assertCountEqual,
958 self.assertCountEqual([{'a': 1}, {'b': 2}], [{'b': 2}, {'a': 1}])
960 self.assertCountEqual([1, 'x', divmod, []], [divmod, [], 'x', 1])
961 self.assertRaises(self.failureException, self.assertCountEqual,
963 self.assertRaises(self.failureException, self.assertCountEqual,
967 self.assertRaises(self.failureException, self.assertCountEqual,
969 self.assertRaises(self.failureException, self.assertCountEqual,
971 self.assertRaises(self.failureException, self.assertCountEqual,
978 self.assertCountEqual(a, b)
984 self.assertEqual(diffs, expected)
987 self.assertEqual(diffs, [(1, 0, [])])
991 self.assertEqual(diffs, expected)
993 def testAssertSetEqual(self): argument
996 self.assertSetEqual(set1, set2)
998 self.assertRaises(self.failureException, self.assertSetEqual, None, set2)
999 self.assertRaises(self.failureException, self.assertSetEqual, [], set2)
1000 self.assertRaises(self.failureException, self.assertSetEqual, set1, None)
1001 self.assertRaises(self.failureException, self.assertSetEqual, set1, [])
1005 self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
1009 self.assertSetEqual(set1, set2)
1013 self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
1017 self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
1021 self.assertSetEqual(set1, set2)
1025 self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
1026 self.assertRaises(self.failureException, self.assertSetEqual, set2, set1)
1031 self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
1033 def testInequality(self): argument
1035 self.assertGreater(2, 1)
1036 self.assertGreaterEqual(2, 1)
1037 self.assertGreaterEqual(1, 1)
1038 self.assertLess(1, 2)
1039 self.assertLessEqual(1, 2)
1040 self.assertLessEqual(1, 1)
1041 self.assertRaises(self.failureException, self.assertGreater, 1, 2)
1042 self.assertRaises(self.failureException, self.assertGreater, 1, 1)
1043 self.assertRaises(self.failureException, self.assertGreaterEqual, 1, 2)
1044 self.assertRaises(self.failureException, self.assertLess, 2, 1)
1045 self.assertRaises(self.failureException, self.assertLess, 1, 1)
1046 self.assertRaises(self.failureException, self.assertLessEqual, 2, 1)
1049 self.assertGreater(1.1, 1.0)
1050 self.assertGreaterEqual(1.1, 1.0)
1051 self.assertGreaterEqual(1.0, 1.0)
1052 self.assertLess(1.0, 1.1)
1053 self.assertLessEqual(1.0, 1.1)
1054 self.assertLessEqual(1.0, 1.0)
1055 self.assertRaises(self.failureException, self.assertGreater, 1.0, 1.1)
1056 self.assertRaises(self.failureException, self.assertGreater, 1.0, 1.0)
1057 self.assertRaises(self.failureException, self.assertGreaterEqual, 1.0, 1.1)
1058 self.assertRaises(self.failureException, self.assertLess, 1.1, 1.0)
1059 self.assertRaises(self.failureException, self.assertLess, 1.0, 1.0)
1060 self.assertRaises(self.failureException, self.assertLessEqual, 1.1, 1.0)
1063 self.assertGreater('bug', 'ant')
1064 self.assertGreaterEqual('bug', 'ant')
1065 self.assertGreaterEqual('ant', 'ant')
1066 self.assertLess('ant', 'bug')
1067 self.assertLessEqual('ant', 'bug')
1068 self.assertLessEqual('ant', 'ant')
1069 self.assertRaises(self.failureException, self.assertGreater, 'ant', 'bug')
1070 self.assertRaises(self.failureException, self.assertGreater, 'ant', 'ant')
1071 self.assertRaises(self.failureException, self.assertGreaterEqual, 'ant', 'bug')
1072 self.assertRaises(self.failureException, self.assertLess, 'bug', 'ant')
1073 self.assertRaises(self.failureException, self.assertLess, 'ant', 'ant')
1074 self.assertRaises(self.failureException, self.assertLessEqual, 'bug', 'ant')
1077 self.assertGreater(b'bug', b'ant')
1078 self.assertGreaterEqual(b'bug', b'ant')
1079 self.assertGreaterEqual(b'ant', b'ant')
1080 self.assertLess(b'ant', b'bug')
1081 self.assertLessEqual(b'ant', b'bug')
1082 self.assertLessEqual(b'ant', b'ant')
1083 self.assertRaises(self.failureException, self.assertGreater, b'ant', b'bug')
1084 self.assertRaises(self.failureException, self.assertGreater, b'ant', b'ant')
1085 self.assertRaises(self.failureException, self.assertGreaterEqual, b'ant',
1087 self.assertRaises(self.failureException, self.assertLess, b'bug', b'ant')
1088 self.assertRaises(self.failureException, self.assertLess, b'ant', b'ant')
1089 self.assertRaises(self.failureException, self.assertLessEqual, b'bug', b'ant')
1091 def testAssertMultiLineEqual(self): argument
1114 self.maxDiff = None
1116 self.assertMultiLineEqual(sample_text, revised_sample_text)
1117 except self.failureException as e:
1120 self.assertEqual(sample_text_error, error)
1122 def testAssertEqualSingleLine(self): argument
1132 self.assertEqual(sample_text, revised_sample_text)
1133 except self.failureException as e:
1136 self.assertEqual(sample_text_error, error)
1138 def testEqualityBytesWarning(self): argument
1141 return self.assertWarnsRegex(BytesWarning,
1147 with bytes_warning(), self.assertRaises(self.failureException):
1148 self.assertEqual('a', b'a')
1150 self.assertNotEqual('a', b'a')
1154 with bytes_warning(), self.assertRaises(self.failureException):
1155 self.assertListEqual(a, b)
1156 with bytes_warning(), self.assertRaises(self.failureException):
1157 self.assertTupleEqual(tuple(a), tuple(b))
1158 with bytes_warning(), self.assertRaises(self.failureException):
1159 self.assertSequenceEqual(a, tuple(b))
1160 with bytes_warning(), self.assertRaises(self.failureException):
1161 self.assertSequenceEqual(tuple(a), b)
1162 with bytes_warning(), self.assertRaises(self.failureException):
1163 self.assertSequenceEqual('a', b'a')
1164 with bytes_warning(), self.assertRaises(self.failureException):
1165 self.assertSetEqual(set(a), set(b))
1167 with self.assertRaises(self.failureException):
1168 self.assertListEqual(a, tuple(b))
1169 with self.assertRaises(self.failureException):
1170 self.assertTupleEqual(tuple(a), b)
1174 with self.assertRaises(self.failureException):
1175 self.assertListEqual(a, b)
1176 with self.assertRaises(self.failureException):
1177 self.assertTupleEqual(tuple(a), tuple(b))
1178 with self.assertRaises(self.failureException):
1179 self.assertSequenceEqual(a, tuple(b))
1180 with self.assertRaises(self.failureException):
1181 self.assertSequenceEqual(tuple(a), b)
1182 with self.assertRaises(self.failureException):
1183 self.assertSetEqual(set(a), set(b))
1187 with self.assertRaises(self.failureException):
1188 self.assertListEqual(a, b)
1189 with self.assertRaises(self.failureException):
1190 self.assertTupleEqual(tuple(a), tuple(b))
1191 with self.assertRaises(self.failureException):
1192 self.assertSequenceEqual(a, tuple(b))
1193 with self.assertRaises(self.failureException):
1194 self.assertSequenceEqual(tuple(a), b)
1195 with self.assertRaises(self.failureException):
1196 self.assertSetEqual(set(a), set(b))
1198 with bytes_warning(), self.assertRaises(self.failureException):
1199 self.assertDictEqual({'a': 0}, {b'a': 0})
1200 with self.assertRaises(self.failureException):
1201 self.assertDictEqual({}, {b'a': 0})
1202 with self.assertRaises(self.failureException):
1203 self.assertDictEqual({b'a': 0}, {})
1205 with self.assertRaises(self.failureException):
1206 self.assertCountEqual([b'a', b'a'], [b'a', b'a', b'a'])
1208 self.assertCountEqual(['a', b'a'], ['a', b'a'])
1209 with bytes_warning(), self.assertRaises(self.failureException):
1210 self.assertCountEqual(['a', 'a'], [b'a', b'a'])
1211 with bytes_warning(), self.assertRaises(self.failureException):
1212 self.assertCountEqual(['a', 'a', []], [b'a', b'a', []])
1214 def testAssertIsNone(self): argument
1215 self.assertIsNone(None)
1216 self.assertRaises(self.failureException, self.assertIsNone, False)
1217 self.assertIsNotNone('DjZoPloGears on Rails')
1218 self.assertRaises(self.failureException, self.assertIsNotNone, None)
1220 def testAssertRegex(self): argument
1221 self.assertRegex('asdfabasdf', r'ab+')
1222 self.assertRaises(self.failureException, self.assertRegex,
1225 def testAssertRaisesCallable(self): argument
1230 self.assertRaises(ExceptionMock, Stub)
1232 self.assertRaises((ValueError, ExceptionMock), Stub)
1234 self.assertRaises(ValueError, int, '19', base=8)
1236 with self.assertRaises(self.failureException):
1237 self.assertRaises(ExceptionMock, lambda: 0)
1239 with self.assertWarns(DeprecationWarning):
1240 self.assertRaises(ExceptionMock, None)
1242 with self.assertRaises(ExceptionMock):
1243 self.assertRaises(ValueError, Stub)
1245 def testAssertRaisesContext(self): argument
1250 with self.assertRaises(ExceptionMock):
1253 with self.assertRaises((ValueError, ExceptionMock)) as cm:
1256 self.assertIsInstance(cm.exception, ExceptionMock)
1257 self.assertEqual(cm.exception.args[0], 'We expect')
1259 with self.assertRaises(ValueError):
1262 with self.assertRaises(self.failureException):
1263 with self.assertRaises(ExceptionMock):
1266 with self.assertRaisesRegex(self.failureException, 'foobar'):
1267 with self.assertRaises(ExceptionMock, msg='foobar'):
1270 with self.assertWarnsRegex(DeprecationWarning, 'foobar'), \
1271 self.assertRaises(AssertionError):
1272 with self.assertRaises(ExceptionMock, foobar=42):
1275 with self.assertRaises(ExceptionMock):
1276 self.assertRaises(ValueError, Stub)
1278 def testAssertRaisesNoExceptionType(self): argument
1279 with self.assertRaises(TypeError):
1280 self.assertRaises()
1281 with self.assertRaises(TypeError):
1282 self.assertRaises(1)
1283 with self.assertRaises(TypeError):
1284 self.assertRaises(object)
1285 with self.assertRaises(TypeError):
1286 self.assertRaises((ValueError, 1))
1287 with self.assertRaises(TypeError):
1288 self.assertRaises((ValueError, object))
1290 def testAssertRaisesRefcount(self): argument
1300 self.assertRaises(ValueError, func)
1301 self.assertEqual(refcount, sys.getrefcount(func))
1303 def testAssertRaisesRegex(self): argument
1310 self.assertRaisesRegex(ExceptionMock, re.compile('expect$'), Stub)
1311 self.assertRaisesRegex(ExceptionMock, 'expect$', Stub)
1312 with self.assertWarns(DeprecationWarning):
1313 self.assertRaisesRegex(ExceptionMock, 'expect$', None)
1315 def testAssertNotRaisesRegex(self): argument
1316 self.assertRaisesRegex(
1317 self.failureException, '^Exception not raised by <lambda>$',
1318 self.assertRaisesRegex, Exception, re.compile('x'),
1320 self.assertRaisesRegex(
1321 self.failureException, '^Exception not raised by <lambda>$',
1322 self.assertRaisesRegex, Exception, 'x',
1325 with self.assertRaisesRegex(self.failureException, 'foobar'):
1326 with self.assertRaisesRegex(Exception, 'expect', msg='foobar'):
1329 with self.assertWarnsRegex(DeprecationWarning, 'foobar'), \
1330 self.assertRaises(AssertionError):
1331 with self.assertRaisesRegex(Exception, 'expect', foobar=42):
1334 def testAssertRaisesRegexInvalidRegex(self): argument
1338 self.assertRaises(TypeError, self.assertRaisesRegex, MyExc, lambda: True)
1340 def testAssertWarnsRegexInvalidRegex(self): argument
1344 self.assertRaises(TypeError, self.assertWarnsRegex, MyWarn, lambda: True)
1346 def testAssertRaisesRegexMismatch(self): argument
1350 self.assertRaisesRegex(
1351 self.failureException,
1353 self.assertRaisesRegex, Exception, '^Expected$',
1355 self.assertRaisesRegex(
1356 self.failureException,
1358 self.assertRaisesRegex, Exception,
1361 def testAssertRaisesExcValue(self): argument
1369 ctx = self.assertRaises(ExceptionMock)
1373 self.assertIsInstance(e, ExceptionMock)
1374 self.assertEqual(e.args[0], v)
1376 def testAssertRaisesRegexNoExceptionType(self): argument
1377 with self.assertRaises(TypeError):
1378 self.assertRaisesRegex()
1379 with self.assertRaises(TypeError):
1380 self.assertRaisesRegex(ValueError)
1381 with self.assertRaises(TypeError):
1382 self.assertRaisesRegex(1, 'expect')
1383 with self.assertRaises(TypeError):
1384 self.assertRaisesRegex(object, 'expect')
1385 with self.assertRaises(TypeError):
1386 self.assertRaisesRegex((ValueError, 1), 'expect')
1387 with self.assertRaises(TypeError):
1388 self.assertRaisesRegex((ValueError, object), 'expect')
1390 def testAssertWarnsCallable(self): argument
1394 self.assertWarns(RuntimeWarning, _runtime_warn)
1395 self.assertWarns(RuntimeWarning, _runtime_warn)
1397 self.assertWarns((DeprecationWarning, RuntimeWarning), _runtime_warn)
1399 self.assertWarns(RuntimeWarning,
1402 with self.assertRaises(self.failureException):
1403 self.assertWarns(RuntimeWarning, lambda: 0)
1405 with self.assertWarns(DeprecationWarning):
1406 self.assertWarns(RuntimeWarning, None)
1411 with self.assertRaises(self.failureException):
1412 self.assertWarns(DeprecationWarning, _runtime_warn)
1416 with self.assertRaises(RuntimeWarning):
1417 self.assertWarns(DeprecationWarning, _runtime_warn)
1419 def testAssertWarnsContext(self): argument
1425 with self.assertWarns(RuntimeWarning) as cm:
1428 with self.assertWarns((DeprecationWarning, RuntimeWarning)) as cm:
1431 self.assertIsInstance(cm.warning, RuntimeWarning)
1432 self.assertEqual(cm.warning.args[0], "foo")
1433 self.assertIn("test_case.py", cm.filename)
1434 self.assertEqual(cm.lineno, _runtime_warn_lineno + 1)
1436 with self.assertWarns(RuntimeWarning):
1439 with self.assertWarns(RuntimeWarning):
1442 with self.assertRaises(self.failureException):
1443 with self.assertWarns(RuntimeWarning):
1446 with self.assertRaisesRegex(self.failureException, 'foobar'):
1447 with self.assertWarns(RuntimeWarning, msg='foobar'):
1450 with self.assertWarnsRegex(DeprecationWarning, 'foobar'), \
1451 self.assertRaises(AssertionError):
1452 with self.assertWarns(RuntimeWarning, foobar=42):
1458 with self.assertRaises(self.failureException):
1459 with self.assertWarns(DeprecationWarning):
1464 with self.assertRaises(RuntimeWarning):
1465 with self.assertWarns(DeprecationWarning):
1468 def testAssertWarnsNoExceptionType(self): argument
1469 with self.assertRaises(TypeError):
1470 self.assertWarns()
1471 with self.assertRaises(TypeError):
1472 self.assertWarns(1)
1473 with self.assertRaises(TypeError):
1474 self.assertWarns(object)
1475 with self.assertRaises(TypeError):
1476 self.assertWarns((UserWarning, 1))
1477 with self.assertRaises(TypeError):
1478 self.assertWarns((UserWarning, object))
1479 with self.assertRaises(TypeError):
1480 self.assertWarns((UserWarning, Exception))
1482 def testAssertWarnsRegexCallable(self): argument
1485 self.assertWarnsRegex(RuntimeWarning, "o+",
1488 with self.assertRaises(self.failureException):
1489 self.assertWarnsRegex(RuntimeWarning, "o+",
1492 with self.assertWarns(DeprecationWarning):
1493 self.assertWarnsRegex(RuntimeWarning, "o+", None)
1498 with self.assertRaises(self.failureException):
1499 self.assertWarnsRegex(DeprecationWarning, "o+",
1502 with self.assertRaises(self.failureException):
1503 self.assertWarnsRegex(RuntimeWarning, "o+",
1511 with self.assertRaises((RuntimeWarning, self.failureException)):
1512 self.assertWarnsRegex(RuntimeWarning, "o+",
1515 def testAssertWarnsRegexContext(self): argument
1520 with self.assertWarnsRegex(RuntimeWarning, "o+") as cm:
1522 self.assertIsInstance(cm.warning, RuntimeWarning)
1523 self.assertEqual(cm.warning.args[0], "foox")
1524 self.assertIn("test_case.py", cm.filename)
1525 self.assertEqual(cm.lineno, _runtime_warn_lineno + 1)
1527 with self.assertRaises(self.failureException):
1528 with self.assertWarnsRegex(RuntimeWarning, "o+"):
1531 with self.assertRaisesRegex(self.failureException, 'foobar'):
1532 with self.assertWarnsRegex(RuntimeWarning, 'o+', msg='foobar'):
1535 with self.assertWarnsRegex(DeprecationWarning, 'foobar'), \
1536 self.assertRaises(AssertionError):
1537 with self.assertWarnsRegex(RuntimeWarning, 'o+', foobar=42):
1543 with self.assertRaises(self.failureException):
1544 with self.assertWarnsRegex(DeprecationWarning, "o+"):
1547 with self.assertRaises(self.failureException):
1548 with self.assertWarnsRegex(RuntimeWarning, "o+"):
1556 with self.assertRaises((RuntimeWarning, self.failureException)):
1557 with self.assertWarnsRegex(RuntimeWarning, "o+"):
1560 def testAssertWarnsRegexNoExceptionType(self): argument
1561 with self.assertRaises(TypeError):
1562 self.assertWarnsRegex()
1563 with self.assertRaises(TypeError):
1564 self.assertWarnsRegex(UserWarning)
1565 with self.assertRaises(TypeError):
1566 self.assertWarnsRegex(1, 'expect')
1567 with self.assertRaises(TypeError):
1568 self.assertWarnsRegex(object, 'expect')
1569 with self.assertRaises(TypeError):
1570 self.assertWarnsRegex((UserWarning, 1), 'expect')
1571 with self.assertRaises(TypeError):
1572 self.assertWarnsRegex((UserWarning, object), 'expect')
1573 with self.assertRaises(TypeError):
1574 self.assertWarnsRegex((UserWarning, Exception), 'expect')
1577 def assertNoStderr(self): argument
1580 self.assertEqual(buf.getvalue(), "")
1582 def assertLogRecords(self, records, matches): argument
1583 self.assertEqual(len(records), len(matches))
1585 self.assertIsInstance(rec, logging.LogRecord)
1587 self.assertEqual(getattr(rec, k), v)
1589 def testAssertLogsDefaults(self): argument
1591 with self.assertNoStderr():
1592 with self.assertLogs() as cm:
1595 self.assertEqual(cm.output, ["INFO:foo:1"])
1596 self.assertLogRecords(cm.records, [{'name': 'foo'}])
1598 def testAssertLogsTwoMatchingMessages(self): argument
1600 with self.assertNoStderr():
1601 with self.assertLogs() as cm:
1605 self.assertEqual(cm.output, ["INFO:foo:1", "WARNING:quux:3"])
1606 self.assertLogRecords(cm.records,
1609 def checkAssertLogsPerLevel(self, level): argument
1611 with self.assertNoStderr():
1612 with self.assertLogs(level=level) as cm:
1616 self.assertEqual(cm.output, ["ERROR:foo.bar:2", "CRITICAL:quux:3"])
1617 self.assertLogRecords(cm.records,
1620 def testAssertLogsPerLevel(self): argument
1621 self.checkAssertLogsPerLevel(logging.ERROR)
1622 self.checkAssertLogsPerLevel('ERROR')
1624 def checkAssertLogsPerLogger(self, logger): argument
1626 with self.assertNoStderr():
1627 with self.assertLogs(level='DEBUG') as outer_cm:
1628 with self.assertLogs(logger, level='DEBUG') as cm:
1632 self.assertEqual(cm.output, ["INFO:foo:1", "DEBUG:foo.bar:2"])
1633 self.assertLogRecords(cm.records,
1636 self.assertEqual(outer_cm.output, ["WARNING:quux:3"])
1638 def testAssertLogsPerLogger(self): argument
1639 self.checkAssertLogsPerLogger(logging.getLogger('foo'))
1640 self.checkAssertLogsPerLogger('foo')
1642 def testAssertLogsFailureNoLogs(self): argument
1644 with self.assertNoStderr():
1645 with self.assertRaises(self.failureException):
1646 with self.assertLogs():
1649 def testAssertLogsFailureLevelTooHigh(self): argument
1651 with self.assertNoStderr():
1652 with self.assertRaises(self.failureException):
1653 with self.assertLogs(level='WARNING'):
1656 def testAssertLogsFailureMismatchingLogger(self): argument
1659 with self.assertLogs('quux', level='ERROR'):
1660 with self.assertRaises(self.failureException):
1661 with self.assertLogs('foo'):
1664 def testDeprecatedMethodNames(self): argument
1669 (self.failIfEqual, (3, 5)),
1670 (self.assertNotEquals, (3, 5)),
1671 (self.failUnlessEqual, (3, 3)),
1672 (self.assertEquals, (3, 3)),
1673 (self.failUnlessAlmostEqual, (2.0, 2.0)),
1674 (self.assertAlmostEquals, (2.0, 2.0)),
1675 (self.failIfAlmostEqual, (3.0, 5.0)),
1676 (self.assertNotAlmostEquals, (3.0, 5.0)),
1677 (self.failUnless, (True,)),
1678 (self.assert_, (True,)),
1679 (self.failUnlessRaises, (TypeError, lambda _: 3.14 + 'spam')),
1680 (self.failIf, (False,)),
1681 (self.assertDictContainsSubset, (dict(a=1, b=2), dict(a=1, b=2, c=3))),
1682 (self.assertRaisesRegexp, (KeyError, 'foo', lambda: {}['foo'])),
1683 (self.assertRegexpMatches, ('bar', 'bar')),
1686 with self.assertWarns(DeprecationWarning):
1691 def _testDeprecatedFailMethods(self): argument
1701 with self.assertRaises(AttributeError):
1702 getattr(self, deprecated_name) # remove these in 3.x
1704 def testDeepcopy(self): argument
1707 def testNothing(self): argument
1715 def testPickle(self): argument
1726 self.assertEqual(test, unpickled_test)
1732 def testKeyboardInterrupt(self): argument
1733 def _raise(self=None): argument
1735 def nothing(self): argument
1750 def test_something(self): argument
1751 self.addCleanup(_raise)
1754 with self.assertRaises(KeyboardInterrupt):
1757 def testSkippingEverywhere(self): argument
1758 def _skip(self=None): argument
1760 def nothing(self): argument
1775 def test_something(self): argument
1776 self.addCleanup(_skip)
1781 self.assertEqual(len(result.skipped), 1)
1782 self.assertEqual(result.testsRun, 1)
1784 def testSystemExit(self): argument
1785 def _raise(self=None): argument
1787 def nothing(self): argument
1802 def test_something(self): argument
1803 self.addCleanup(_raise)
1808 self.assertEqual(len(result.errors), 1)
1809 self.assertEqual(result.testsRun, 1)
1812 def testNoCycles(self): argument
1817 self.assertFalse(wr())
1819 def test_no_exception_leak(self): argument
1825 def __init__(self): argument
1827 Exception.__init__(self)
1829 def __del__(self): argument
1833 def test1(self): argument
1837 def test2(self): argument
1843 self.assertEqual(MyException.ninstance, 0)