| 2237 | self.assertRaises(TypeError, Counter.update) |
| 2238 | |
| 2239 | def test_copying(self): |
| 2240 | # Check that counters are copyable, deepcopyable, picklable, and |
| 2241 | #have a repr/eval round-trip |
| 2242 | words = Counter('which witch had which witches wrist watch'.split()) |
| 2243 | def check(dup): |
| 2244 | msg = "\ncopy: %s\nwords: %s" % (dup, words) |
| 2245 | self.assertIsNot(dup, words, msg) |
| 2246 | self.assertEqual(dup, words) |
| 2247 | check(words.copy()) |
| 2248 | check(copy.copy(words)) |
| 2249 | check(copy.deepcopy(words)) |
| 2250 | for proto in range(pickle.HIGHEST_PROTOCOL + 1): |
| 2251 | with self.subTest(proto=proto): |
| 2252 | check(pickle.loads(pickle.dumps(words, proto))) |
| 2253 | check(eval(repr(words))) |
| 2254 | update_test = Counter() |
| 2255 | update_test.update(words) |
| 2256 | check(update_test) |
| 2257 | check(Counter(words)) |
| 2258 | |
| 2259 | def test_copy_subclass(self): |
| 2260 | class MyCounter(Counter): |