def test_load_duplicates(self):
        config = FileStorageConfiguration()
        tmpdir = os.path.dirname(__file__) + os.sep + "duplicates"
        tmpfile = tmpdir + os.sep + "duplicates.txt"
        config.duplicates_storage._dirs = [tmpfile]
        config.duplicates_storage._has_single_file = True
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileDuplicatesStore(engine)

        path = store._get_dir_from_path(store._get_storage_path())
        if os.path.exists(path):
            shutil.rmtree(path)
        self.assertFalse(os.path.exists(path))

        store.empty()

        duplicates = [["aiml1.xml", "10", "20", "1", "5", "Duplicate_1"]]
        store.save_duplicates(duplicates)
        self.assertTrue(os.path.exists(store._get_storage_path()))

        duplicateInfo = store.load_duplicates()
        self.assertIsNotNone(duplicateInfo)
        self.assertIsNotNone(duplicateInfo['duplicates'])
        duplicates = duplicateInfo['duplicates']
        duplicate = duplicates[0]
        self.assertEqual("aiml1.xml", duplicate['file'])

        store.empty()
        self.assertFalse(os.path.exists(store._get_storage_path()))

        shutil.rmtree(tmpdir)
        self.assertFalse(os.path.exists(tmpdir))
Esempio n. 2
0
    def test_empty_no_dir(self):
        config = FileStorageConfiguration()
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileDuplicatesStore(engine)

        if os.path.exists(store._get_storage_path()) is True:
            shutil.rmtree(store._get_storage_path())

        store.empty()

        self.assertFalse(os.path.exists(store._get_storage_path()))