def test___setslice___(self): s = Sequence(["file.001.ext"]) s[1:2] = "file.002.ext" self.assertEqual(len(s), 2) self.assertEqual(s[0], Item("file.001.ext")) self.assertEqual(s[1], Item("file.002.ext")) s = Sequence(["file.001.ext"]) s[1:2] = Item("file.002.ext") self.assertEqual(len(s), 2) self.assertEqual(s[0], Item("file.001.ext")) self.assertEqual(s[1], Item("file.002.ext")) s = Sequence(["file.001.ext"]) s[1:2] = [Item("file.002.ext")] self.assertEqual(len(s), 2) self.assertEqual(s[0], Item("file.001.ext")) self.assertEqual(s[1], Item("file.002.ext")) s = Sequence(["file.001.ext"]) s[1:2] = Sequence([Item("file.002.ext")]) self.assertEqual(len(s), 2) self.assertEqual(s[0], Item("file.001.ext")) self.assertEqual(s[1], Item("file.002.ext")) self.assertRaises(SequenceError, s.__setslice__, 1, 2, 'item.001.ext')
def test___add__(self): s = Sequence(["file.01.ext"]) ns = s + Item("file.02.ext") self.assertEqual(len(ns), 2) self.assertEqual(ns[0], s[0]) self.assertEqual(ns[1], Item("file.02.ext")) self.assertEqual(len(s), 1) ns = s + "file.02.ext" self.assertEqual(len(ns), 2) self.assertEqual(ns[0], s[0]) self.assertEqual(ns[1], Item("file.02.ext")) self.assertEqual(len(s), 1) ns = s + ["file.02.ext"] self.assertEqual(len(ns), 2) self.assertEqual(ns[0], s[0]) self.assertEqual(ns[1], Item("file.02.ext")) self.assertEqual(len(s), 1) ns = s + Sequence(["file.02.ext"]) self.assertEqual(len(ns), 2) self.assertEqual(ns[0], s[0]) self.assertEqual(ns[1], Item("file.02.ext")) self.assertEqual(len(s), 1) self.assertRaises(SequenceError, s.__add__, "item.01.ext") self.assertRaises(TypeError, s.__add__, 1)
def test__get_missing(self): """ test that _get_missing works """ # Can't initialize Sequence without an item # seq = Sequence([]) # self.assertEqual(seq._get_missing(), []) seq = Sequence(["file.00010.jpg"]) self.assertEqual(seq._get_missing(), []) seq = Sequence(self.files) seq.append("file.0006.jpg") self.assertEqual(seq._get_missing(), [4, 5]) seq = Sequence(["file.%04d.jpg" % i for i in xrange(20)]) seq.pop(10) seq.pop(10) seq.pop(10) seq.pop(14) seq.pop(14) missing = [10, 11, 12, 17, 18] self.assertEqual(seq._get_missing(), missing) missing = [] seq = Sequence(["file.0001.jpg"]) for i in xrange(2, 50): if random.randint(0, 1) == 1: seq.append("file.%04d.jpg" % i) else: missing.append(i) # remove ending random frames while missing[-1] > int(re.search("file\.(\d{4})\.jpg", seq[-1]).group(1)): missing.pop(-1) self.assertEqual(seq._get_missing(), missing)
def test_format_is_working_properly_1(self): """testing if format is working properly """ seq = Sequence(self.files) seq.append('file.0006.jpg') self.assertEqual(seq.format('%h%p%t %r (%R)'), 'file.%04d.jpg 1-6 ([1-3, 6])')
def test_insert(self): s = Sequence(["file.001.ext"]) s.insert(0, "file.002.ext") self.assertEqual(len(s), 2) self.assertEqual(s[0], Item("file.002.ext")) self.assertEqual(s[1], Item("file.001.ext")) self.assertRaises(SequenceError, s.insert, 1, "item")
def test___setitem__(self): s = Sequence(["file.01.ext", "file.05.ext"]) s[1] = "file.02.ext" self.assertEqual(len(s), 2) self.assertEqual(s[0], Item("file.01.ext")) self.assertEqual(s[1], Item("file.02.ext")) self.assertRaises(SequenceError, s.__setitem__, 0, "item.1.ext")
def test_format_directory_attribute(self): dir_name = os.path.dirname( os.path.abspath(self.files[0])) + os.sep seq = Sequence(self.files) self.assertEqual( seq.format("%D"), dir_name )
def test_format_is_working_properly_3(self): """testing if format is working properly """ seq = Sequence(self.files) seq.append('file.0006.jpg') seq.append('file.0010.jpg') self.assertEqual(seq.format('%h%p%t %r (missing %M)'), 'file.%04d.jpg 1-10 (missing [4-5, 7-9])')
def test_extend(self): s = Sequence(["file.001.ext"]) s.extend(["file.002.ext", "file.003.ext"]) self.assertEqual(len(s), 3) self.assertEqual(s[0], Item("file.001.ext")) self.assertEqual(s[1], Item("file.002.ext")) self.assertEqual(s[2], Item("file.003.ext")) self.assertRaises(SequenceError, s.extend, ["item"])
def test_from_list(self): """testing if Sequence instance can be initialized with a list of file names """ seq = Sequence(self.files) self.assertEqual( str(seq), 'file.1-3.jpg' )
def test_appending_a_new_file(self): """testing if it is possible to append a new item to the list by giving the file name """ seq = Sequence(self.files) test_file = 'file.0006.jpg' seq.append(test_file) self.assertTrue(seq.contains('file.0005.jpg')) self.assertTrue(seq.contains(test_file)) self.assertFalse(seq.contains('file.0015.jpg'))
def test_format_is_working_properly_2(self): """testing if format is working properly """ seq = Sequence(self.files) seq.append('file.0006.jpg') self.assertEqual( 'file.0001-0006.jpg', seq.format('%h%04s-%04e%t'), ) self.assertEqual( 'file. 1- 6.jpg', seq.format('%h%4s-%4e%t'), )
def test___iadd__(self): s = Sequence(["file.01.ext"]) s += Item("file.02.ext") self.assertEqual(len(s), 2) self.assertEqual(s[0], s[0]) self.assertEqual(s[1], Item("file.02.ext")) s = Sequence(["file.01.ext"]) s += "file.02.ext" self.assertEqual(len(s), 2) self.assertEqual(s[0], s[0]) self.assertEqual(s[1], Item("file.02.ext")) s = Sequence(["file.01.ext"]) s += ["file.02.ext"] self.assertEqual(len(s), 2) self.assertEqual(s[0], s[0]) self.assertEqual(s[1], Item("file.02.ext")) s = Sequence(["file.01.ext"]) s += Sequence(["file.02.ext"]) self.assertEqual(len(s), 2) self.assertEqual(s[0], s[0]) self.assertEqual(s[1], Item("file.02.ext"))
def test_contains_is_working_properly(self): """testing if Sequence.contains() method is working properly """ seq = Sequence(self.files) self.assertFalse(seq.contains('file.0009.jpg')) self.assertFalse(seq.contains('file.0009.pic'))
def test_includes_is_working_properly(self): """testing if Sequence.includes() method is working properly """ seq = Sequence(self.files) self.assertTrue(seq.includes('file.0009.jpg')) self.assertFalse(seq.includes('file.0009.pic'))
def test_format_is_working_properly_4(self): """testing if format is working properly """ seq = Sequence(self.files) seq.append('file.0006.jpg') self.assertEqual(seq.format('%h%s%t'), 'file.1.jpg')