コード例 #1
0
    def test_multiple_versions(self):
        """Test multiple versions of the same type.
        """
        r = kbtypes.Regenerator(self.args)
        t = self._get_types(r)

        # Insert extra version.
        for modname in t.keys():
            for typename in t[modname].keys():
                t[modname][typename]["9_9"] = {'description': "TEST99"}

        # Capture output classes
        w = StringIO.StringIO()
        r.write_types(w, t)

        # Check if versions are recorded properly
        # by looking at the output
        buf, prev_depth, num_ver, cur_mod = w.getvalue(), 0, 0, "?"
        #print("@@ BUF: {}".format(buf))
        for line in buf.split("\n"):
            match = re.search("\S", line)
            if match is None:
                continue  # blank line
            depth = match.span()[0] / 4  # calc. depth by #leading spaces
            if depth == 0:
                match = re.match("class (\w+)", line)
                if match is None:
                    self.fail("junk on line: {}".format(line))
                cur_mod = match.group(1)
            if depth == 2 and re.search("class v\d+_\d+\(.*\):", line):
                num_ver += 1
            # when we finish a class, check that we found at least 2 versions
            if depth == 0 and prev_depth > 0:
                self.assertGreaterEqual(
                    num_ver, 2, "{}: Expected >=2 versions, got {:d}".format(
                        cur_mod, num_ver))
                num_ver = 0
            prev_depth = depth
コード例 #2
0
 def test_get_types(self):
     """Regenerator.get_types
     """
     r = kbtypes.Regenerator(self.args)
     t = self._get_types(r)
     self.assert_(t)