Ejemplo n.º 1
0
 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])
Ejemplo n.º 2
0
 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])
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
 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])
Ejemplo n.º 6
0
 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])
Ejemplo n.º 7
0
 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]))
Ejemplo n.º 8
0
 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]))