| 2217 | self.assertRaises(TypeError, Counter.update) |
| 2218 | |
| 2219 | def test_copying(self): |
| 2220 | # Check that counters are copyable, deepcopyable, picklable, and |
| 2221 | #have a repr/eval round-trip |
| 2222 | words = Counter('which witch had which witches wrist watch'.split()) |
| 2223 | def check(dup): |
| 2224 | msg = "\ncopy: %s\nwords: %s" % (dup, words) |
| 2225 | self.assertIsNot(dup, words, msg) |
| 2226 | self.assertEqual(dup, words) |
| 2227 | check(words.copy()) |
| 2228 | check(copy.copy(words)) |
| 2229 | check(copy.deepcopy(words)) |
| 2230 | for proto in range(pickle.HIGHEST_PROTOCOL + 1): |
| 2231 | with self.subTest(proto=proto): |
| 2232 | check(pickle.loads(pickle.dumps(words, proto))) |
| 2233 | check(eval(repr(words))) |
| 2234 | update_test = Counter() |
| 2235 | update_test.update(words) |
| 2236 | check(update_test) |
| 2237 | check(Counter(words)) |
| 2238 | |
| 2239 | def test_copy_subclass(self): |
| 2240 | class MyCounter(Counter): |