Module: check_mk
Branch: master
Commit: ce587a5af53d1308e33032fb1fe7e8e1c13cc345
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ce587a5af53d13…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Tue Oct 18 11:42:06 2016 +0200
Fixed string concatenation bug
---
tests/web/data/testtable___2.html | 33 +++++++++++++
tests/web/data/testtable___None.html | 95 ++++++++++++++++++++++++++++++++++++
tests/web/test_html.py | 64 ++++++++++++++++++++++++
web/htdocs/htmllib.py | 9 ++++
4 files changed, 201 insertions(+)
diff --git a/tests/web/data/testtable___2.html b/tests/web/data/testtable___2.html
new file mode 100644
index 0000000..13fc3ac
--- /dev/null
+++ b/tests/web/data/testtable___2.html
@@ -0,0 +1,33 @@
+
+<h3>
+ TEST
+ </h3>
+
+ <table class="data oddeven">
+ <tr>
+ <th>
+ Number
+ </th>
+ <th>
+ Cubical
+ </th>
+ </tr>
+ <tr class="data odd 0">
+ <td>
+ 0
+ </td>
+ <td>
+ 0
+ </td>
+ </tr>
+ <tr class="data even 0">
+ <td>
+ 1
+ </td>
+ <td>
+ 1
+ </td>
+ </tr>
+ </table>
+<div class=success>This table is limited to show only 2 of 10 rows. Click <a
href=".py?limit=none">here</a> to disable the limitation.</div>
+
diff --git a/tests/web/data/testtable___None.html b/tests/web/data/testtable___None.html
new file mode 100644
index 0000000..b62ffb6
--- /dev/null
+++ b/tests/web/data/testtable___None.html
@@ -0,0 +1,95 @@
+
+<h3>
+ TEST
+ </h3>
+
+ <table class="data oddeven">
+ <tr>
+ <th>
+ Number
+ </th>
+ <th>
+ Cubical
+ </th>
+ </tr>
+ <tr class="data odd 0">
+ <td>
+ 0
+ </td>
+ <td>
+ 0
+ </td>
+ </tr>
+ <tr class="data even 0">
+ <td>
+ 1
+ </td>
+ <td>
+ 1
+ </td>
+ </tr>
+ <tr class="data odd 0">
+ <td>
+ 2
+ </td>
+ <td>
+ 8
+ </td>
+ </tr>
+ <tr class="data even 0">
+ <td>
+ 3
+ </td>
+ <td>
+ 27
+ </td>
+ </tr>
+ <tr class="data odd 0">
+ <td>
+ 4
+ </td>
+ <td>
+ 64
+ </td>
+ </tr>
+ <tr class="data even 0">
+ <td>
+ 5
+ </td>
+ <td>
+ 125
+ </td>
+ </tr>
+ <tr class="data odd
0">
+ <td>
+ 6
+ </td>
+ <td>
+ 216
+ </td>
+ </tr>
+ <tr class="data even
0">
+ <td>
+ 7
+ </td>
+ <td>
+ 343
+ </td>
+ </tr>
+ <tr class="data odd
0">
+ <td>
+ 8
+ </td>
+ <td>
+ 512
+ </td>
+ </tr>
+ <tr
class="data even 0">
+ <td>
+ 9
+ </td>
+ <td>
+ 729
+
</td>
+ </tr>
+ </table>
diff --git a/tests/web/test_html.py b/tests/web/test_html.py
new file mode 100644
index 0000000..b416d60
--- /dev/null
+++ b/tests/web/test_html.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+# call using
+# > py.test -s -k test_HTML_generator.py
+
+# enable imports from web directory
+from testlib import cmk_path
+import sys
+sys.path.insert(0, "%s/web/htdocs" % cmk_path())
+
+# external imports
+import re
+
+# internal imports
+from htmllib import HTML
+
+
+
+
+def test_class_HTML():
+
+ a = "One"
+ b = "two"
+ c = "Three"
+
+ A = HTML(a)
+ B = HTML(b)
+ C = HTML(c)
+
+ assert (A + B) == (a + b)
+ print A
+
+ A += B
+ assert isinstance(A, HTML), A
+
+ a += b
+ assert A == a, A
+
+ assert A == a
+
+ assert ("%s" % A) == a
+
+ assert B + C != C + B
+
+ assert HTML(A) == A, "%s %s" % (HTML(A), A)
+ assert HTML(a) == A, "%s %s" % (HTML(a), A)
+
+ assert (A < B) == (a < b), "%s %s" % (A < B, a < b)
+
+ assert (A > B) == (a > b)
+
+ assert A != B
+
+ assert isinstance(HTML(HTML(A)), HTML)
+ assert isinstance(HTML(HTML(A)).value, str)
+
+ assert isinstance(A, HTML)
+ A += (" JO PICASSO! ")
+ assert isinstance(A, HTML)
+
+ assert isinstance(A + "TEST" , str)
+
+ assert isinstance("TEST%s" % A, str)
+
+ assert "test" + C == "test" + c
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 5577b10..f7d2126 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -113,6 +113,7 @@ class HTML(object):
def __init__(self, value):
+ super(HTML, self).__init__()
if isinstance(value, HTML):
self.value = value.value
else:
@@ -130,10 +131,18 @@ class HTML(object):
return self.value + other
+ def __radd__(self, other):
+ if isinstance(other, HTML):
+ return other.value + self.value
+ else:
+ return other + self.value
+
+
def __iadd__(self, other):
self.value = self.__add__(other)
return self
+
def __lt__(self, other):
if isinstance(other, HTML):
return self.value < other.value