def compare(self, src, expected_src):
     actual_root = ast.parse(utils.unindent(src))
     scoping.ScopeAssigner().visit(actual_root)
     EncodeScopeInIdentifier().visit(actual_root)
     actual_src = astor.to_source(actual_root)
     
     expected_root = ast.parse(utils.unindent(expected_src))
     expected_src = astor.to_source(expected_root)
             
     cmps = itertools.izip_longest(expected_src.splitlines(), actual_src.splitlines())
     for linenr, c in enumerate(cmps, 1):
         expected_line = c[0]
         actual_line = c[1]
         self.assertEqual(expected_line, actual_line, "Line %s differs. Expected %s but got %s." % (linenr, repr(expected_line), repr(actual_line)))
 def scan_func(self, src):
     src = utils.unindent(src)
     root = ast.parse(src)
     func = next(node for node in root.body if isinstance(node, ast.FunctionDef) and node.name == "test")
     target = scoping.LocalVariableCollector()
     target.visit(func)
     return target
示例#3
0
    def compare(self, src, expected_src):
        actual_root = ast.parse(utils.unindent(src))
        scoping.ScopeAssigner().visit(actual_root)
        EncodeScopeInIdentifier().visit(actual_root)
        actual_src = astor.to_source(actual_root)

        expected_root = ast.parse(utils.unindent(expected_src))
        expected_src = astor.to_source(expected_root)

        cmps = itertools.izip_longest(expected_src.splitlines(),
                                      actual_src.splitlines())
        for linenr, c in enumerate(cmps, 1):
            expected_line = c[0]
            actual_line = c[1]
            self.assertEqual(
                expected_line, actual_line,
                "Line %s differs. Expected %s but got %s." %
                (linenr, repr(expected_line), repr(actual_line)))
示例#4
0
 def scan_func(self, src):
     src = utils.unindent(src)
     root = ast.parse(src)
     func = next(
         node for node in root.body
         if isinstance(node, ast.FunctionDef) and node.name == "test")
     target = scoping.LocalVariableCollector()
     target.visit(func)
     return target
示例#5
0
 def testIgnoreComments(self):
     self.assertEqual("#comment\nx=1", utils.unindent("#comment\n   x=1"))
示例#6
0
 def testPartiallyIndendedComment(self):
     self.assertEqual("#comment\nx=1", utils.unindent(" #comment\n   x=1"))
示例#7
0
 def testStructurePreservedTabs(self):
     self.assertEqual("def foo():\n  x=1", utils.unindent("\tdef foo():\n\t  x=1"))
示例#8
0
 def testIgnoreEmtptyLines(self):
     self.assertEqual("\nx=1", utils.unindent("\n   x=1"))
示例#9
0
 def testTwoLinesMixed(self):
     self.assertEqual("x=1\ny=2", utils.unindent("\tx=1\n        y=2"))
示例#10
0
 def testStructurePreservedSpaces(self):
     self.assertEqual("def foo():\n  x=1", utils.unindent("  def foo():\n    x=1"))
示例#11
0
 def testTwoLinesTabs(self):
     self.assertEqual("x=1\ny=2", utils.unindent("\tx=1\n\ty=2"))
示例#12
0
 def testTwoLinesSpaces(self):
     self.assertEqual("x=1\ny=2", utils.unindent("  x=1\n  y=2"))
示例#13
0
 def testOneLineMix(self):
     self.assertEqual("x=1", utils.unindent(" \t \t  x=1"))
示例#14
0
 def testOneLineSpaces(self):
     self.assertEqual("x=1", utils.unindent("  x=1"))
示例#15
0
 def testEmptyString(self):
     self.assertEqual("", utils.unindent(""))