def test_archives(self): path_archives = {'path_1': [Archive('archive_1'), Archive('archive_2')], 'path_2': [Archive('archive_3')]} af = ArchiveFinder() af.path_archives_found = path_archives self.assertEquals(len(af.archives), 3) self.assertEquals([archive.name for archive in af.archives], ['archive_1', 'archive_2', 'archive_3'])
def test_str(self): a = Archive(self.default_name) self.assertEquals(str(a), 'archive_name (0 undefined archives)') a.archives = range(10) a.medkits = range(5) self.assertEquals( str(a), 'archive_name (10 undefined archives, 5 par2 files)')
def test_init(self): a = Archive(self.default_name) self.assertEquals(a.path, '.') self.assertEquals(a.name, self.default_name) self.assertEquals(a.filenames, []) self.assertEquals(a.medkits, []) self.assertEquals(a.archives, []) filenames = ['%s.par2' % self.default_name, '%s.ext' % self.default_name, '%s.vol00+02.par2' % self.default_name, '%s.vol01+03.PAR2' % self.default_name, '%s.nzb' % self.default_name] a = Archive(self.default_name, './tests', filenames) self.assertEquals(a.path, './tests') self.assertEquals(a.name, self.default_name) self.assertEquals(len(a.filenames), 5) self.assertEquals(len(a.medkits), 3) self.assertEquals(len(a.archives), 0)
def test_extract(self): original_extract = Archive._extract def always_extract(cls): return True Archive._extract = always_extract a = Archive(self.default_name) self.assertTrue(a.extract()) def never_extract(cls): return False Archive._extract = never_extract a = Archive(self.default_name) self.assertFalse(a.extract()) self.assertFalse(a.extract(True)) def notextract_extract(cls): extract = cls.i % 2 cls.i += 1 return bool(extract) def always_repair(silent=True): return True Archive._extract = notextract_extract a = Archive(self.default_name) a.i = 0 self.assertFalse(a.extract()) self.assertTrue(a.extract()) self.assertFalse(a.extract(True)) self.assertTrue(a.extract()) original_check_and_repair = a.check_and_repair a.check_and_repair = always_repair self.assertTrue(a.extract(True)) a.check_and_repair = original_check_and_repair self.assertFalse(a.extract()) Archive._extract = original_extract
def test_remove(self): system_commands = [] def fake_system(cmd): system_commands.append(cmd) original_system = os.system os.system = fake_system a = Archive(self.default_name) a.medkits = ['toto', 'titi'] a.archives = ['tata', 'tutu'] a.remove() self.assertEquals(system_commands, ['rm -f ./tata ./tutu ./toto ./titi']) os.system = original_system
def test_find_archives(self): filenames = ['%s.rar' % self.default_name, '%s.zip' % self.default_name, 'bla.rar'] a = Archive(self.default_name, './tests') self.assertEquals(a.archives, []) a.find_archives(filenames) self.assertEquals(a.archives, []) original_is_archive_file = a.is_archive_file def always_archive_file(filename): return True a.is_archive_file = always_archive_file a.find_archives(filenames) self.assertEquals(len(a.archives), 2) a.is_archive_file = original_is_archive_file
def test__extract(self): a = Archive(self.default_name) self.assertRaises(NotImplementedError, a.extract)
def test_files(self): a = Archive(self.default_name) self.assertEquals(len(a.files), 0) a.medkits = ['toto', 'titi'] a.archives = ['tata', 'tutu'] self.assertEquals(len(a.files), 4)