def test_example(self): actual = diff(''' line1 line2 line3 ''', ''' line1 line changed line3 ''') expected = '''\ --- first +++ second @@ -1,5 +1,5 @@ line1 - line2 + line changed line3 ''' self.assertEqual( [line.strip() for line in expected.split("\n")], [line.strip() for line in actual.split("\n")], '\n%r\n!=\n%r' % (expected, actual) )
def test_example(self): actual = diff( '\n line1\n line2\n line3\n ', '\n line1\n line changed\n line3\n ') expected = '--- first\n+++ second\n@@ -1,5 +1,5 @@\n\n line1\n- line2\n+ line changed\n line3\n ' self.assertEqual([line.strip() for line in expected.split('\n')], [line.strip() for line in actual.split('\n')], '\n%r\n!=\n%r' % (expected, actual))
def test_no_newlines(self): actual = diff("x", "y") # no rhyme or reason as to which of these comes back :-/ try: expected = "@@ -1 +1 @@\n-x\n+y" self.assertEqual(expected, actual, "\n%r\n!=\n%r" % (expected, actual)) except AssertionError: # pragma: no cover expected = "--- first\n+++ second\n@@ -1 +1 @@\n-x\n+y" self.assertEqual(expected, actual, "\n%r\n!=\n%r" % (expected, actual))
def test_no_newlines(self): actual = diff('x', 'y') try: expected = '@@ -1 +1 @@\n-x\n+y' self.assertEqual(expected, actual, '\n%r\n!=\n%r' % (expected, actual)) except AssertionError: expected = '--- first\n+++ second\n@@ -1 +1 @@\n-x\n+y' self.assertEqual(expected, actual, '\n%r\n!=\n%r' % (expected, actual))
def format(self, document): for region in document: result = region.evaluated if not isinstance(result, FileResult): continue if not result.passed: region.formatted = diff( result.expected, result.actual, 'File "%s", line %i:' % (document.location, region.lineno), 'Reading from "%s":' % result.path)
def test_no_newlines(self): actual = diff('x','y') expected = '''@@ -1,1 +1,1 @@ -x +y''' self.assertEqual( expected, actual, '\n%r\n!=\n%r'%(expected,actual) )
def evaluate(self, example): block = example.parsed dir = example.namespace[self.name] if block.action == 'read': actual = dir.read(block.path, 'ascii').replace(os.linesep, '\n') if actual != block.content: return diff(block.content, actual, 'File %r, line %i:' % (example.path, example.line), 'Reading from "%s":' % dir.getpath(block.path)) if block.action == 'write': dir.write(block.path, block.content, 'ascii')
def test_no_newlines(self): actual = diff('x', 'y') # no rhyme or reason as to which of these comes back :-/ try: expected = '@@ -1 +1 @@\n-x\n+y' self.assertEqual(expected, actual, '\n%r\n!=\n%r' % (expected, actual)) except AssertionError: # pragma: no cover expected = '--- first\n+++ second\n@@ -1 +1 @@\n-x\n+y' self.assertEqual(expected, actual, '\n%r\n!=\n%r' % (expected, actual))
def evaluate(self, example): block = example.parsed dir = example.namespace[self.name] if block.action == 'read': actual = dir.read(block.path, 'ascii').replace(os.linesep, '\n') if actual != block.content: return diff( block.content, actual, 'File %r, line %i:' % (example.path, example.line), 'Reading from "%s":' % dir.getpath(block.path) ) if block.action == 'write': dir.write(block.path, block.content, 'ascii')
def format(self, document): for region in document: result = region.evaluated if not isinstance(result, FileResult): continue if not result.passed: region.formatted = diff( result.expected, result.actual, 'File "%s", line %i:' % (document.location, region.lineno), 'Reading from "%s":' % result.path ) return
def ShouldAssert(expected_text): """ A context manager to check that an :class:`AssertionError` is raised and its text is as expected. """ try: yield except AssertionError as e: actual_text = str(e) if expected_text != actual_text: raise AssertionError(diff(expected_text, actual_text, x_label='expected', y_label='actual')) else: raise AssertionError('Expected AssertionError(%r), None raised!' % expected_text)
def test_no_newlines(self): actual = diff('x','y') # no rhyme or reason as to which of these comes back :-/ try: expected = '@@ -1 +1 @@\n-x\n+y' self.assertEqual( expected, actual, '\n%r\n!=\n%r' % (expected, actual) ) except AssertionError: # pragma: no cover expected = '@@ -1,1 +1,1 @@\n-x\n+y' self.assertEqual( expected, actual, '\n%r\n!=\n%r' % (expected, actual) )
def test_example(self): actual = diff( ''' line1 line2 line3 ''', ''' line1 line changed line3 ''') expected = '''@@ -1,5 +1,5 @@ line1 - line2 + line changed line3 ''' self.assertEqual(expected, actual, '\n%r\n!=\n%r' % (expected, actual))
def test_example(self): actual = diff(''' line1 line2 line3 ''', ''' line1 line changed line3 ''') expected = '''@@ -1,5 +1,5 @@ line1 - line2 + line changed line3 ''' self.assertEqual( expected, actual, '\n%r\n!=\n%r'%(expected,actual) )
def test_example(self): actual = diff( """ line1 line2 line3 """, """ line1 line changed line3 """, ) expected = """\ --- first +++ second @@ -1,5 +1,5 @@ line1 - line2 + line changed line3 """ self.assertEqual(expected, actual, "\n%r\n!=\n%r" % (expected, actual))
def test_example(self): actual = diff( ''' line1 line2 line3 ''', ''' line1 line changed line3 ''') expected = '''\ --- first +++ second @@ -1,5 +1,5 @@ line1 - line2 + line changed line3 ''' self.assertEqual([line.strip() for line in expected.split("\n")], [line.strip() for line in actual.split("\n")], '\n%r\n!=\n%r' % (expected, actual))
def compare_repr(obj, expected): actual = diff(expected, repr(obj)) if actual: # pragma: no cover raise AssertionError(actual)
af = open(ap,'rb') actual = af.read() af.close() if name in expected_names: expected = open(j(expected_base,name),'rb').read() expected_names.remove(name) if actual==expected: os.remove(ap) else: print 'different:',name else: print "unexpected:",name for name in expected_names: if name!='.svn': print "missing:",name output.seek(0) output = output.read().strip().replace('\r','') for re,rp in sub_res: output = re.sub(rp,output) expected_path = j(expected_base+'.txt') if not os.path.exists(expected_path): expected = '' else: expected = open(expected_path).read().strip().replace('\r','') if output!=expected: print '='*len(name) print diff(expected,output) print '='*len(name)