refactoring
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
from BatchcodeOptionsSetter import BatchcodeOptionsSetter
|
from BatchcodeOptionsSetter import BatchcodeOptionsSetter
|
||||||
|
from TestHelper import TestHelper
|
||||||
|
|
||||||
class BatchcodeOptionsSetterTest(unittest.TestCase):
|
class BatchcodeOptionsSetterTest(unittest.TestCase):
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ class BatchcodeOptionsSetterTest(unittest.TestCase):
|
|||||||
'<option value="FF3318">FF3318</option>'])
|
'<option value="FF3318">FF3318</option>'])
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
assertEqualHTML(
|
TestHelper.assertEqualHTML(
|
||||||
htmlActual,
|
htmlActual,
|
||||||
'''
|
'''
|
||||||
<html>
|
<html>
|
||||||
@@ -40,32 +41,3 @@ class BatchcodeOptionsSetterTest(unittest.TestCase):
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
''')
|
''')
|
||||||
|
|
||||||
# adapted from https://stackoverflow.com/questions/8006909/pretty-print-assertequal-for-html-strings
|
|
||||||
def assertEqualHTML(string1, string2, file1='', file2=''):
|
|
||||||
u'''
|
|
||||||
Compare two unicode strings containing HTML.
|
|
||||||
A human friendly diff goes to logging.error() if they
|
|
||||||
are not equal, and an exception gets raised.
|
|
||||||
'''
|
|
||||||
from bs4 import BeautifulSoup as bs
|
|
||||||
import difflib
|
|
||||||
|
|
||||||
def short(mystr):
|
|
||||||
max = 20
|
|
||||||
if len(mystr) > max:
|
|
||||||
return mystr[:max]
|
|
||||||
return mystr
|
|
||||||
p = []
|
|
||||||
for mystr, file in [(string1, file1), (string2, file2)]:
|
|
||||||
if not isinstance(mystr, str):
|
|
||||||
raise Exception(u'string ist not unicode: %r %s' %
|
|
||||||
(short(mystr), file))
|
|
||||||
soup = bs(mystr, 'lxml')
|
|
||||||
pretty = soup.prettify()
|
|
||||||
p.append(pretty)
|
|
||||||
if p[0] != p[1]:
|
|
||||||
for line in difflib.unified_diff(p[0].splitlines(), p[1].splitlines(), fromfile=file1, tofile=file2):
|
|
||||||
print(line)
|
|
||||||
print(p[0], ' != ', p[1])
|
|
||||||
raise Exception('Not equal %s %s' % (file1, file2))
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
|
from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
|
||||||
|
from TestHelper import TestHelper
|
||||||
|
|
||||||
|
|
||||||
class OptionsSetterTest(unittest.TestCase):
|
class OptionsSetterTest(unittest.TestCase):
|
||||||
|
|
||||||
@@ -24,7 +26,7 @@ class OptionsSetterTest(unittest.TestCase):
|
|||||||
'<option value="ADEN">ADEN</option>'])
|
'<option value="ADEN">ADEN</option>'])
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
assertEqualHTML(
|
TestHelper.assertEqualHTML(
|
||||||
htmlActual,
|
htmlActual,
|
||||||
'''
|
'''
|
||||||
<html>
|
<html>
|
||||||
@@ -37,33 +39,3 @@ class OptionsSetterTest(unittest.TestCase):
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
''')
|
''')
|
||||||
|
|
||||||
# FK-TODO: DRY with BatchcodeOptionsSetterTest.assertEqualHTML()
|
|
||||||
# adapted from https://stackoverflow.com/questions/8006909/pretty-print-assertequal-for-html-strings
|
|
||||||
def assertEqualHTML(string1, string2, file1='', file2=''):
|
|
||||||
u'''
|
|
||||||
Compare two unicode strings containing HTML.
|
|
||||||
A human friendly diff goes to logging.error() if they
|
|
||||||
are not equal, and an exception gets raised.
|
|
||||||
'''
|
|
||||||
from bs4 import BeautifulSoup as bs
|
|
||||||
import difflib
|
|
||||||
|
|
||||||
def short(mystr):
|
|
||||||
max = 20
|
|
||||||
if len(mystr) > max:
|
|
||||||
return mystr[:max]
|
|
||||||
return mystr
|
|
||||||
p = []
|
|
||||||
for mystr, file in [(string1, file1), (string2, file2)]:
|
|
||||||
if not isinstance(mystr, str):
|
|
||||||
raise Exception(u'string ist not unicode: %r %s' %
|
|
||||||
(short(mystr), file))
|
|
||||||
soup = bs(mystr, 'lxml')
|
|
||||||
pretty = soup.prettify()
|
|
||||||
p.append(pretty)
|
|
||||||
if p[0] != p[1]:
|
|
||||||
for line in difflib.unified_diff(p[0].splitlines(), p[1].splitlines(), fromfile=file1, tofile=file2):
|
|
||||||
print(line)
|
|
||||||
print(p[0], ' != ', p[1])
|
|
||||||
raise Exception('Not equal %s %s' % (file1, file2))
|
|
||||||
|
|||||||
@@ -12,3 +12,33 @@ class TestHelper:
|
|||||||
series = pd.Series(**kwargs)
|
series = pd.Series(**kwargs)
|
||||||
series.index.name = indexName
|
series.index.name = indexName
|
||||||
return series
|
return series
|
||||||
|
|
||||||
|
# adapted from https://stackoverflow.com/questions/8006909/pretty-print-assertequal-for-html-strings
|
||||||
|
@staticmethod
|
||||||
|
def assertEqualHTML(string1, string2, file1='', file2=''):
|
||||||
|
u'''
|
||||||
|
Compare two unicode strings containing HTML.
|
||||||
|
A human friendly diff goes to logging.error() if they
|
||||||
|
are not equal, and an exception gets raised.
|
||||||
|
'''
|
||||||
|
from bs4 import BeautifulSoup as bs
|
||||||
|
import difflib
|
||||||
|
|
||||||
|
def short(mystr):
|
||||||
|
max = 20
|
||||||
|
if len(mystr) > max:
|
||||||
|
return mystr[:max]
|
||||||
|
return mystr
|
||||||
|
p = []
|
||||||
|
for mystr, file in [(string1, file1), (string2, file2)]:
|
||||||
|
if not isinstance(mystr, str):
|
||||||
|
raise Exception(u'string ist not unicode: %r %s' %
|
||||||
|
(short(mystr), file))
|
||||||
|
soup = bs(mystr, 'lxml')
|
||||||
|
pretty = soup.prettify()
|
||||||
|
p.append(pretty)
|
||||||
|
if p[0] != p[1]:
|
||||||
|
for line in difflib.unified_diff(p[0].splitlines(), p[1].splitlines(), fromfile=file1, tofile=file2):
|
||||||
|
print(line)
|
||||||
|
print(p[0], ' != ', p[1])
|
||||||
|
raise Exception('Not equal %s %s' % (file1, file2))
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class KreisOptionsSetterTest(unittest.TestCase):
|
|||||||
</html>
|
</html>
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
# FK-TODO: delegate to use TestHelper.assertEqualHTML()
|
||||||
# adapted from https://stackoverflow.com/questions/8006909/pretty-print-assertequal-for-html-strings
|
# adapted from https://stackoverflow.com/questions/8006909/pretty-print-assertequal-for-html-strings
|
||||||
def assertEqualHTML(string1, string2, file1='', file2=''):
|
def assertEqualHTML(string1, string2, file1='', file2=''):
|
||||||
u'''
|
u'''
|
||||||
|
|||||||
Reference in New Issue
Block a user