def testCompositeName(self): command_name = 'mean' keyword_list1 = ['rms', 'x'] keyword_list2 = ['rms', 'y'] name_dict = {} name, components, flag = createName(name_dict, keyword_list1, keyword_list2, command_name) name_dict[name] = 'Hello' command_name = 'median' keyword_list1 = components keyword_list2 = [] name, components, flag = createName(name_dict, keyword_list1, keyword_list2, command_name) self.assertEqual(name, 'median.mean.rms.x.rms.y') self.assertEqual(components, ['median', 'mean', 'rms', 'x', 'rms', 'y']) self.assertFalse(flag)
def addFile(self, dir_entry, file_type, folder_database, parent_path): base_name = os.path.basename(dir_entry.name) keywords = splitPattern(base_name) file_object = FileObject(os.path.join(parent_path, dir_entry.name), file_type, '', False) # Future can generate some description file_name, _, _ = createName(folder_database._argument_database[file_type].name_dict.keys(), keywords) folder_database.add(file_type, keywords, file_object, file_name)
def testSimpleName(self): command_name = 'mean' keyword_list1 = ['rms', 'x'] keyword_list2 = ['rms', 'y'] name_dict = {} name, components, flag = createName(name_dict, keyword_list1, keyword_list2, command_name) self.assertEqual(name, 'mean.rms.x.rms.y') self.assertEqual(components, ['mean', 'rms', 'x', 'rms', 'y']) self.assertFalse(flag)
def testExistingName(self): command_name = 'mean' keyword_list1 = ['rms', 'x'] keyword_list2 = ['rms', 'y', 'z'] name_dict = {'mean.rms.x.rms.y.z': 'Hello'} name, components, flag = createName(name_dict, keyword_list1, keyword_list2, command_name) self.assertEqual(name, 'mean.rms.x.rms.y.z.1') self.assertEqual(components, ['mean', 'rms', 'x', 'rms', 'y', 'z', '1']) self.assertTrue(flag)
def testLastResort(self): command_name = 'mean' keyword_list1 = ['x', 'z'] keyword_list2 = ['y', 'a'] name_dict = {'mean.x.y': 'Hello', 'mean.x.z.y': 'Hello', 'mean.x.z.y.a': 'Hello'} name, components, flag = createName(name_dict, keyword_list1, keyword_list2, command_name) self.assertEqual(name, 'mean.x.z.y.a.1') self.assertEqual(components, ['mean', 'x', 'z', 'y', 'a', '1']) self.assertTrue(flag) name_dict[name] = 'Hello' name, components, flag = createName(name_dict, keyword_list1, keyword_list2, command_name) self.assertEqual(name, 'mean.x.z.y.a.2') self.assertEqual(components, ['mean', 'x', 'z', 'y', 'a', '2']) self.assertTrue(flag) for i in range(1000): name_dict['mean.x.z.y.a.' + str(i + 1)] = 'Hello' self.assertRaises(RuntimeError, createName, name_dict, keyword_list1, keyword_list2, command_name)