Ejemplo n.º 1
0
    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')
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
 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])')
Ejemplo n.º 5
0
    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")
Ejemplo n.º 6
0
    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")
Ejemplo n.º 7
0
 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
         )
Ejemplo n.º 8
0
 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])')
Ejemplo n.º 9
0
    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"])
Ejemplo n.º 10
0
 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'
     )
Ejemplo n.º 11
0
 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'))
Ejemplo n.º 12
0
 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'),
     )
Ejemplo n.º 13
0
    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"))
Ejemplo n.º 14
0
 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'))
Ejemplo n.º 15
0
 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'))
Ejemplo n.º 16
0
 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')