def test_no_factory(self): greasy_spoon = DefaultDictWithKey() with self.assertRaisesRegex( TypeError, "'NoneType' object is not callable" ): greasy_spoon['spam']
def test_intended_use_case(self): def enlist(item): return [item] greasy_spoon = DefaultDictWithKey(enlist) self.assertEqual(greasy_spoon['spam'], ['spam']) greasy_spoon['spam'].append('spam') self.assertEqual(greasy_spoon['spam'], ['spam', 'spam'])
def test_too_many_params(self): def appender(item1, item2): return [item1, item2] greasy_spoon = DefaultDictWithKey(appender) with self.assertRaisesRegex( TypeError, r"appender\(\) missing 1 required positional argument: 'item2'" ): greasy_spoon['spam']
def test_not_enough_params(self): def empty_list(): return [] greasy_spoon = DefaultDictWithKey(empty_list) with self.assertRaisesRegex( TypeError, r'empty_list\(\) takes 0 positional arguments but 1 was given' ): greasy_spoon['spam']