Example #1
0
    def testTuple(self):
        """Test indexed tuple"""
        i = rorpiter.IndexedTuple((1, 2, 3), ("a", "b"))
        i2 = rorpiter.IndexedTuple((), ("hello", "there", "how are you"))

        assert i[0] == "a"
        assert i[1] == "b"
        assert i2[1] == "there"
        assert len(i) == 2 and len(i2) == 3
        assert i2 < i, i2 < i
Example #2
0
    def testTuple(self):
        """Test indexed tuple"""
        i = rorpiter.IndexedTuple((1, 2, 3), ("a", "b"))
        i2 = rorpiter.IndexedTuple((), ("hello", "there", "how are you"))

        self.assertEqual(i[0], "a")
        self.assertEqual(i[1], "b")
        self.assertEqual(i2[1], "there")
        self.assertEqual(len(i), 2)
        self.assertEqual(len(i2), 3)
        self.assertLess(i2, i)
Example #3
0
    def yield_inc_complexes(self, inc_rpath):
        """Yield (sub_inc_rpath, inc_list) IndexedTuples from given inc_rpath

        Finds pairs under directory inc_rpath.  sub_inc_rpath will just be
        the prefix rp, while the rps in inc_list should actually exist.

        """
        if not inc_rpath.isdir():
            return

        def get_inc_pairs():
            """Return unsorted list of (basename, inc_filenames) pairs"""
            inc_dict = {}  # dictionary of basenames:inc_filenames
            dirlist = robust.listrp(inc_rpath)

            def add_to_dict(filename):
                """Add filename to the inc tuple dictionary"""
                rp = inc_rpath.append(filename)
                if rp.isincfile() and rp.getinctype() != b'data':
                    basename = rp.getincbase_bname()
                    inc_filename_list = inc_dict.setdefault(basename, [])
                    inc_filename_list.append(filename)
                elif rp.isdir():
                    inc_dict.setdefault(filename, [])

            for filename in dirlist:
                add_to_dict(filename)
            return list(inc_dict.items())

        def inc_filenames2incrps(filenames):
            """Map list of filenames into increment rps"""
            inc_list = []
            for filename in filenames:
                rp = inc_rpath.append(filename)
                assert rp.isincfile(), (
                    "Path '{mrp}' must be an increment file.".format(mrp=rp))
                inc_list.append(rp)
            return inc_list

        items = get_inc_pairs()
        items.sort()  # Sorting on basis of basename now
        for (basename, inc_filenames) in items:
            sub_inc_rpath = inc_rpath.append(basename)
            yield rorpiter.IndexedTuple(
                sub_inc_rpath.index,
                (sub_inc_rpath, inc_filenames2incrps(inc_filenames)))
Example #4
0
 def testTupleAssignment(self):
     a, b, c = rorpiter.IndexedTuple((), (1, 2, 3))
     assert a == 1
     assert b == 2
     assert c == 3
Example #5
0
 def get_iter(self):
     """Return iterator yielding indexed objects, add to dict d"""
     for i in range(100):
         it = rorpiter.IndexedTuple((i, ), range(i))
         self.d[(i, )] = it
         yield it
Example #6
0
 def testTupleAssignment(self):
     a, b, c = rorpiter.IndexedTuple((), (1, 2, 3))
     self.assertEqual((a, b, c), (1, 2, 3))