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
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
def testIgnoreComments(self): self.assertEqual("#comment\nx=1", utils.unindent("#comment\n x=1"))
def testPartiallyIndendedComment(self): self.assertEqual("#comment\nx=1", utils.unindent(" #comment\n x=1"))
def testStructurePreservedTabs(self): self.assertEqual("def foo():\n x=1", utils.unindent("\tdef foo():\n\t x=1"))
def testIgnoreEmtptyLines(self): self.assertEqual("\nx=1", utils.unindent("\n x=1"))
def testTwoLinesMixed(self): self.assertEqual("x=1\ny=2", utils.unindent("\tx=1\n y=2"))
def testStructurePreservedSpaces(self): self.assertEqual("def foo():\n x=1", utils.unindent(" def foo():\n x=1"))
def testTwoLinesTabs(self): self.assertEqual("x=1\ny=2", utils.unindent("\tx=1\n\ty=2"))
def testTwoLinesSpaces(self): self.assertEqual("x=1\ny=2", utils.unindent(" x=1\n y=2"))
def testOneLineMix(self): self.assertEqual("x=1", utils.unindent(" \t \t x=1"))
def testOneLineSpaces(self): self.assertEqual("x=1", utils.unindent(" x=1"))
def testEmptyString(self): self.assertEqual("", utils.unindent(""))