Пример #1
0
 def test_match_token_seq(self):
     cst = self.cover.parse("def foo(): pass\n")
     tokenseq = find_all_token(cst)
     self.assertTrue(
         self.fn_cov.match_token_seq(
             cst, ["def", "foo", "(", ")", ":", "pass", "\n"]))
     self.assertTrue(self.fn_cov.match_token_seq(cst, ["def", "foo"]))
     self.assertFalse(self.fn_cov.match_token_seq(cst, ["foo", "("]))
Пример #2
0
 def get_line_info_end(self, node):
     try:
         node_end = node[-1][2]-1
     except IndexError:
         token = find_all_token(node)
         nl = 0
         for T in token[::-1]:
             if len(T)>2:
                 node_end = T[2]+nl-1
                 break
             else:
                 nl+=T[1].count("\n")
     return node_end
Пример #3
0
 def get_line_info_end(self, node):
     try:
         node_end = node[-1][2] - 1
     except IndexError:
         token = find_all_token(node)
         nl = 0
         for T in token[::-1]:
             if len(T) > 2:
                 node_end = T[2] + nl - 1
                 break
             else:
                 nl += T[1].count("\n")
     return node_end
Пример #4
0
    def unparse(self, node):
        """Writes a node's equivalent source code to the output object.

        @raise TypeError: If the node's type is unknown.
        """
        self.reset()
        stream = find_all_token(node)
        for tok in stream:
            text = tok[1]
            if isinstance(text, tokenstring):
                intron = text.ext
            else:
                intron = ""
            name = self.get_name(tok)
            # print "TOKEN", len(tok), tok, [intron], type(tok[1]), name
            if name and hasattr(self, "handle_"+name):
                method = getattr(self, "handle_"+name)
                method(tok, intron = intron)
            else:
                self._format(tok, intron)
            self.last_node = tok
            #print "\n-------------\n"+self.format()+"\n----------------"
        S = "".join(self.output).lstrip('\n')
        return S
Пример #5
0
    def unparse(self, node):
        """Writes a node's equivalent source code to the output object.

        @raise TypeError: If the node's type is unknown.
        """
        self.reset()
        stream = find_all_token(node)
        for tok in stream:
            text = tok[1]
            if isinstance(text, tokenstring):
                intron = text.ext
            else:
                intron = ""
            name = self.get_name(tok)
            # print "TOKEN", len(tok), tok, [intron], type(tok[1]), name
            if name and hasattr(self, "handle_" + name):
                method = getattr(self, "handle_" + name)
                method(tok, intron=intron)
            else:
                self._format(tok, intron)
            self.last_node = tok
            #print "\n-------------\n"+self.format()+"\n----------------"
        S = "".join(self.output).lstrip('\n')
        return S