Module: check_mk
Branch: master
Commit: 555d75c1be79c9ee607c2cb365444763df935a9b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=555d75c1be79c9…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Fri Oct 28 17:34:45 2016 +0200
Updated test tools for refactoring
---
tests/web/auto_build_test.py | 29 ++++++++++++++++++++++++-----
tests/web/classes.py | 12 ++++++++++++
tests/web/tools.py | 2 +-
3 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/tests/web/auto_build_test.py b/tests/web/auto_build_test.py
index ad51128..d236741 100644
--- a/tests/web/auto_build_test.py
+++ b/tests/web/auto_build_test.py
@@ -29,7 +29,7 @@ from bs4 import BeautifulSoup as bs
# internal imports
from classes import HTMLOrigTester, HTMLCheck_MKTester
-from tools import compare_html , gentest, compare_and_empty
+from tools import compare_html, gentest, compare_and_empty
'''
function_start = lambda x: '''
@@ -67,15 +67,27 @@ if __name__ == "__main__":
exit(0)
counter = 0
+ indent = ' ' * 4
with open(autotest_filename, 'w') as auto:
auto.write(header)
with open(sys.argv[1], 'r') as diff:
+
+ old_line = []
+ new_line = []
+
for line in diff:
+ line = line[0] + line[1:].lstrip(' ')
+
if re.match(r'@@.*', line):
if counter > 0:
+ auto.write(indent + indent.join(old_line))
+ auto.write(indent + indent.join(new_line))
+ auto.write("\n\n")
auto.write(function_end)
+ old_line = []
+ new_line = []
auto.write(function_start(counter))
counter += 1
continue
@@ -87,21 +99,28 @@ if __name__ == "__main__":
continue
if not re.match(r'[+|-].+', line) and line[0] not in
['+', '-']:
- auto.write(line[1:])
+ old_line.append(line[1:])
+ new_line.append(line[1:])
elif re.match(r'[+]{3}.*', line) or re.match(r'[-]{3}.*',
line):
continue
elif re.match(r'[-]\s*html\..*', line):
pattern = re.compile(r'[-]\s*html\.')
- auto.write(re.sub(r'\s*html\.', ' old.', line[1:],
count=1))
+ old_line.append(re.sub(r'\s*html\.', 'old.',
line[1:], count=1))
elif re.match(r'[+]\s*html\..*', line):
pattern = re.compile(r'\s*html\.')
- auto.write(pattern.sub(' new.', line[1:], count=1))
+ new_line.append(pattern.sub('new.', line[1:], count=1))
+
+ elif re.match(r'[-].*', line):
+ old_line.append(line[1:])
+
+ elif re.match(r'[+].*', line):
+ new_line.append(line[1:])
else:
- auto.write(line[1:])
+ print line
if(counter > 0):
auto.write(function_end)
diff --git a/tests/web/classes.py b/tests/web/classes.py
index 6da3e1d..8e3b88f 100644
--- a/tests/web/classes.py
+++ b/tests/web/classes.py
@@ -50,6 +50,7 @@ class DeprecatedRenderer(object):
self.enable_debug = False
self.screenshotmode = False
+ self.have_help = False
self.help_visible = False
self.body_classes = ['main']
@@ -125,6 +126,17 @@ class DeprecatedRenderer(object):
self._dump_get_vars()
+ # Embed help box, whose visibility is controlled by a global
+ # button in the page.
+ def help(self, text):
+ if text and text.strip():
+ self.have_help = True
+ self.write('<div class=help style="display: %s">' %
(
+ not self.help_visible and "none" or
"block"))
+ self.write(text.strip())
+ self.write('</div>')
+
+
#
# HTML form rendering
#
diff --git a/tests/web/tools.py b/tests/web/tools.py
index 5d65476..ede4c5e 100644
--- a/tests/web/tools.py
+++ b/tests/web/tools.py
@@ -130,7 +130,7 @@ def compare_soup(html1, html2):
if key.startswith("on") or key == "style":
val1 = filter(lambda x: x, map(lambda x: unify_attrs(x).strip('
'), attrs1.pop(key, '').split(';')))
val2 = filter(lambda x: x, map(lambda x: unify_attrs(x).strip('
'), attrs2.pop(key, '').split(';')))
- assert val1 == val2, '\n%s\n%s' % (attrs1, attrs2)
+ assert val1 == val2, '\n%s\n%s' % (val1, val2)
assert attrs1 == attrs2, '\n%s\n%s' % (d1, d2)