Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for two failing tests #100

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions hamlpy/test/template_compare_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
class TestTemplateCompare(unittest.TestCase):

def test_nuke_inner_whitespace(self):
self._compare_test_files('nukeInnerWhitespace')
self._compare_test_files('nukeInnerWhiteSpace')

def test_nuke_outer_whitespace(self):
self._compare_test_files('nukeOuterWhitespace')
self._compare_test_files('nukeOuterWhiteSpace')

def test_comparing_simple_templates(self):
self._compare_test_files('simple')
Expand Down Expand Up @@ -57,52 +57,52 @@ def test_whitespace_preservation(self):
self._compare_test_files('whitespacePreservation')

def _print_diff(self, s1, s2):
if len(s1)>len(s2):
shorter=s2
if len(s1) > len(s2):
shorter = s2
else:
shorter=s1
shorter = s1

line=1
col=1
line = 1
col = 1

for i, _ in enumerate(shorter):
if len(shorter) <= i+1:
if len(shorter) <= i + 1:
print 'Ran out of characters to compare!'
print 'Actual len=%d'%len(s1)
print 'Expected len=%d'%len(s2)
print 'Actual len=%d' % len(s1)
print 'Expected len=%d' % len(s2)
break
if s1[i] != s2[i]:
print 'Difference begins at line', line, 'column', col
actual_line = s1.splitlines()[line-1]
expected_line = s2.splitlines()[line-1]
actual_line = s1.splitlines()[line - 1]
expected_line = s2.splitlines()[line - 1]
print 'HTML (actual, len=%2d) : %s' % (len(actual_line), actual_line)
print 'HTML (expected, len=%2d) : %s' % (len(expected_line), expected_line)
print 'Character code (actual) : %d (%s)' % (ord(s1[i]), s1[i])
print 'Character code (expected): %d (%s)' % (ord(s2[i]), s2[i])
break

if shorter[i]=='\n':
if shorter[i] == '\n':
line += 1
col=1
col = 1
else:
col+=1
col += 1
else:
print "No Difference Found"

def _compare_test_files(self, name):
haml_lines = codecs.open('templates/'+name+'.hamlpy', encoding='utf-8').readlines()
html = open('templates/'+name+'.html').read()
haml_lines = codecs.open('templates/' + name + '.hamlpy', encoding = 'utf-8').readlines()
html = open('templates/' + name + '.html').read()

haml_compiler = hamlpy.Compiler()
parsed = haml_compiler.process_lines(haml_lines)

# Ignore line ending differences
parsed=parsed.replace('\r','')
html=html.replace('\r','')
parsed = parsed.replace('\r', '')
html = html.replace('\r', '')

if parsed != html:
print '\nHTML (actual): '
print '\n'.join(["%d. %s" % (i+1, l) for i, l in enumerate(parsed.split('\n')) ])
print '\n'.join(["%d. %s" % (i + 1, l) for i, l in enumerate(parsed.split('\n')) ])
self._print_diff(parsed, html)
eq_(parsed, html)

Expand Down