def test_add(self): test_key = 1 test_value = "one" test_dict = {} self.assert_(test_key not in test_dict) helper_functions.add_or_append(test_key, test_value, test_dict) self.assert_(test_key in test_dict) self.assertEqual([test_value], test_dict[test_key])
def process_filename(fqn, files_by_size, extensions): """ Given a fully-qualified filename, a dictionary of filenames keyed by size, and a dictionary of file extensions, update the two dictionaries with the relevant information about the file. """ filesize = os.stat(fqn).st_size helper_functions.add_or_append(filesize, fqn, files_by_size) extension = helper_functions.process_extension(fqn) if extension is None: extension = NO_EXTENSION helper_functions.add_or_append(extension, filesize, extensions)
def test_append(self): test_key = 1 test_value_1 = 'one' test_value_2 = 'two' test_dict = {test_key : [test_value_1]} self.assert_(test_key in test_dict) self.assertEquals(1, len(test_dict[test_key])) helper_functions.add_or_append(test_key, test_value_2, test_dict) self.assertEquals(2, len(test_dict[test_key])) # Values should always be appended to the list self.assertEquals([test_value_1, test_value_2], test_dict[test_key]) self.assertNotEqual([test_value_2, test_value_1], test_dict[test_key])
def test_append(self): test_key = 1 test_value_1 = 'one' test_value_2 = 'two' test_dict = {test_key: [test_value_1]} self.assert_(test_key in test_dict) self.assertEquals(1, len(test_dict[test_key])) helper_functions.add_or_append(test_key, test_value_2, test_dict) self.assertEquals(2, len(test_dict[test_key])) # Values should always be appended to the list self.assertEquals([test_value_1, test_value_2], test_dict[test_key]) self.assertNotEqual([test_value_2, test_value_1], test_dict[test_key])
def test_complicated_use(self): test_key_1 = 1 test_key_2 = "two" test_key_3 = 3 test_value_1 = "one" test_value_2 = "two" test_value_3 = 3 test_dict = {test_key_1: [test_value_1, test_value_2], test_key_3: []} self.assertEquals(2, len(test_dict)) self.assertEquals(2, len(test_dict[test_key_1])) self.assert_(test_key_2 not in test_dict) self.assertEquals([], test_dict[test_key_3]) helper_functions.add_or_append(test_key_1, test_value_3, test_dict) self.assertEquals(2, len(test_dict)) self.assertEquals(3, len(test_dict[test_key_1])) helper_functions.add_or_append(test_key_2, test_value_1, test_dict) self.assertEquals(3, len(test_dict)) self.assertEquals(1, len(test_dict[test_key_2]))
def test_complicated_use(self): test_key_1 = 1 test_key_2 = "two" test_key_3 = 3 test_value_1 = "one" test_value_2 = "two" test_value_3 = 3 test_dict = { test_key_1 : [test_value_1, test_value_2], test_key_3 : [] } self.assertEquals(2, len(test_dict)) self.assertEquals(2, len(test_dict[test_key_1])) self.assert_(test_key_2 not in test_dict) self.assertEquals([], test_dict[test_key_3]) helper_functions.add_or_append(test_key_1, test_value_3, test_dict) self.assertEquals(2, len(test_dict)) self.assertEquals(3, len(test_dict[test_key_1])) helper_functions.add_or_append(test_key_2, test_value_1, test_dict) self.assertEquals(3, len(test_dict)) self.assertEquals(1, len(test_dict[test_key_2]))