示例#1
0
 def test_no_factory(self):
     greasy_spoon = DefaultDictWithKey()
     with self.assertRaisesRegex(
         TypeError,
         "'NoneType' object is not callable"
     ):
         greasy_spoon['spam']
示例#2
0
 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'])
示例#3
0
 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']
示例#4
0
 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']