示例#1
0
    def test_filter_files_for_reindexing__test_files_for_reindexing__3_to_keep_2_to_remove(
        self, ):
        test_group = FileReindexer.group_files_by_index(
            self.TEST_FILES_FOR_REINDEXING)
        reindex, remove = FileReindexer.filter_files_for_reindexing(
            test_group, self.TEST_KEYS)

        self.assertEqual(test_group[26751], remove[0])
        self.assertEqual(test_group[26752], reindex[0])
        self.assertEqual(test_group[26753], reindex[1])
        self.assertEqual(test_group[26754], remove[1])
        self.assertEqual(test_group[26755], reindex[2])
示例#2
0
 def test_group_files_by_index__singe_file_per_index__length_and_values_correct(
     self, ):
     result = FileReindexer.group_files_by_index(
         ["front_123.png", "rear_123.png"])
     self.assertEqual(1, len(result.keys()))
     self.assertIn(result[123][0].file_path.name,
                   ["front_123.png", "rear_123.png"])
示例#3
0
 def test_group_files_by_index__test_files_for_reindexing__correct(self):
     result = FileReindexer.group_files_by_index(
         self.TEST_FILES_FOR_REINDEXING)
     self.assertEqual(5, len(result.keys()))
     self.assertEqual(1, len(result[26751]))
     self.assertEqual(2, len(result[26752]))
     self.assertEqual(2, len(result[26753]))
     self.assertEqual(1, len(result[26754]))
     self.assertEqual(2, len(result[26755]))
示例#4
0
    def test_filter_files_for_reindexing__single_group_for_reindexing__correct(
            self):
        test_group = {
            123: [FileModel("front_123.png"),
                  FileModel("rear_123.png")]
        }
        reindex, remove = FileReindexer.filter_files_for_reindexing(
            test_group, self.TEST_KEYS)

        self.assertEqual(test_group[123], reindex[0])
        self.assertFalse(remove)
示例#5
0
    def test_filter_files_for_reindexing__two_groups_for_removing__correct(
            self):
        test_group = {
            123: [FileModel("front_123.png")],
            124: [FileModel("rear_124.png")],
        }
        reindex, remove = FileReindexer.filter_files_for_reindexing(
            test_group, self.TEST_KEYS)

        self.assertFalse(reindex)
        self.assertEqual(test_group[123], remove[0])
        self.assertEqual(test_group[124], remove[1])
示例#6
0
def reindex_files(image_files, image_topics):
    """
    Reindex files to follow required structure
    :param image_files:
    :param image_topics:
    :return:
    """
    image_reindexer = FileReindexer(image_files, image_topics)
    if user_confirmation(
            "%d/%d samples will be removed" %
        (len(image_reindexer.files_to_remove), len(image_files))):
        image_reindexer.clean_up()
    if user_confirmation("%d/%d samples with %d topics will be reindexed" %
                         (len(image_reindexer.files_to_reindex),
                          len(image_files), len(image_topics))):
        image_reindexer.reindex()
示例#7
0
 def test_clean_up__test_files_for_reindexing__rename_called_six_times(
         self, mock_method):
     unit = FileReindexer(self.TEST_FILES_FOR_REINDEXING, self.TEST_KEYS)
     unit.reindex()
     self.assertEqual(6, mock_method.call_count)
示例#8
0
 def test_clean_up__no_files_to_reindex__no_reindexing(self, mock_method):
     unit = FileReindexer([], self.TEST_KEYS)
     unit.reindex()
     mock_method.assert_not_called()
示例#9
0
 def test_clean_up__test_files_for_reindexing__unlink_called_twice(
         self, mock_method):
     unit = FileReindexer(self.TEST_FILES_FOR_REINDEXING, self.TEST_KEYS)
     unit.clean_up()
     self.assertEqual(2, mock_method.call_count)
示例#10
0
 def test_filter_files_for_reindexing__no_files__empty(self):
     reindex, remove = FileReindexer.filter_files_for_reindexing(
         {}, self.TEST_KEYS)
     self.assertFalse(reindex)
     self.assertFalse(remove)
示例#11
0
 def test_group_files_by_index__file_order_with_one_leading_zeros__ordered_by_file_index(
     self, ):
     file_list = get_ordered_file_list_with_one_leading_zero()
     result = list(FileReindexer.group_files_by_index(file_list))
     self.assertTrue(
         all(result[i] <= result[i + 1] for i in range(len(result) - 1)))
示例#12
0
 def test_group_files_by_index__no_files__empty(self):
     result = FileReindexer.group_files_by_index([])
     self.assertFalse(result)