Module: check_mk
Branch: master
Commit: a7a23cefea4723091f26fb3f3c44057bfcd660c8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a7a23cefea4723…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Tue Feb 7 14:26:33 2017 +0100
feature: table.open() context.
Change-Id: I3d7fb0d3de3dcf411b44240a7c374a5501e9e851
---
tests/web/test_table.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
web/htdocs/table.py | 10 +++++++++
2 files changed, 65 insertions(+)
diff --git a/tests/web/test_table.py b/tests/web/test_table.py
index 16c3492..25d5308 100644
--- a/tests/web/test_table.py
+++ b/tests/web/test_table.py
@@ -138,3 +138,58 @@ def table_test_cubical(sortable, searchable, limit, output_format,
tmpdir):
assert len(data) == limit
assert data == rows[:limit]
+
+
+
+
+
+def test_context():
+ import table
+
+ html = TableTest()
+ __builtin__.html = html
+
+ table_id = 0
+ rows = [ (i, i**3) for i in range(10) ]
+ header = ["Number", "Cubical"]
+
+ with table.open(table_id=table_id, searchable=False, sortable=False):
+ for row in rows:
+ table.row()
+ for i in range(len(header)):
+ table.cell(_(header[i]), row[i])
+
+ text = html.written_text
+ data = read_out_table(text)
+ assert data.pop(0) == header
+ data = [ tuple(map(int, row)) for row in data if row and row[0]]
+ assert data == rows
+
+
+#def test_nested_context():
+# import table
+#
+# html = TableTest()
+# __builtin__.html = html
+#
+# table_id = 0
+# rows = [ (i, i**3) for i in range(2) ]
+# header = ["Number", "Cubical"]
+#
+# with table.open(table_id=table_id, searchable=False, sortable=False):
+# for row in rows:
+# table.row()
+# for i in range(len(header)):
+# table.cell(_(header[i]), row[i])
+# with table.open(table_id=table_id, searchable=False, sortable=False):
+# for row in rows:
+# table.row()
+# for i in range(len(header)):
+# table.cell(_(header[i]), row[i])
+#
+# text = html.written_text
+# print "\n" + text
+# data = read_out_table(text)
+# assert data.pop(0) == header
+# data = [ tuple(map(int, row)) for row in data if row and row[0]]
+# assert data == rows
diff --git a/web/htdocs/table.py b/web/htdocs/table.py
index e2851ba..bc4fe9f 100644
--- a/web/htdocs/table.py
+++ b/web/htdocs/table.py
@@ -26,6 +26,16 @@
import config
from lib import num_split
+# TODO: Is contextlib part of older versions of python?
+# external imports
+from contextlib import contextmanager
+@contextmanager
+def open(**kwargs):
+ begin(**kwargs)
+ yield
+ end()
+
+
table = None
mode = None
next_func = None