Set default width to 80 for justify filter 71/33471/3
authorYujun Zhang <zhang.yujunz@zte.com.cn>
Tue, 18 Apr 2017 10:57:14 +0000 (18:57 +0800)
committerYujun Zhang <zhang.yujunz@zte.com.cn>
Thu, 20 Apr 2017 01:57:31 +0000 (09:57 +0800)
- 80 default screen width for most consoles
- template content should not be part of console reporter test
- remove fix width splitter in console report templates

Change-Id: Ib060b447bd52c211a4bf1e4ded2f898a9201b6d8
Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
qtip/reporter/filters.py
qtip/reporter/templates/base.j2
tests/unit/cli/cmd_report_test.py
tests/unit/reporter/console_test.py

index dc46e19..c0c379d 100644 (file)
@@ -8,7 +8,7 @@
 ##############################################################################
 
 
-def justify(pair, width=100, padding_with='.'):
+def justify(pair, width=80, padding_with='.'):
     """align first element along the left margin, second along the right, padding spaces"""
     n = width - len(pair[0])
     return '{key}{value:{c}>{n}}'.format(key=pair[0], value=pair[1], c=padding_with, n=n)
index 34242b4..5dafc8b 100644 (file)
@@ -1,4 +1,4 @@
-{{ '=' * 100}}
+{{ ('=', '=')|justify }}
 {{ ('Plan Name', plan_name)|justify }}
 {{ ('Start Time', start_time)|justify }}
 {{ ('Stop Time', stop_time)|justify }}
@@ -14,7 +14,7 @@
 {% include '%s.j2' % metric_name %}
 {% endif %}
 System Information
-{{ ('CPU Brand', bm.sysinfo.cpu)|justify }}
+{{ ('CPU', bm.sysinfo.cpu)|justify }}
 {{ ('Disk', bm.sysinfo.disk)|justify }}
 {{ ('Host Name', bm.sysinfo.hostname)|justify }}
 {{ ('Kernel', bm.sysinfo.kernel)|justify }}
@@ -25,5 +25,5 @@ System Information
 {%- endfor -%}
 {% endfor %}
 
-{{ '\033[93m' }} {{ '*' * 100}} {{ '\033[0m' }}
+{{ ('\033[93m*', '*\033[0m')|justify }}
 {%- endfor -%}
index 21e757d..064ed8f 100644 (file)
@@ -26,60 +26,16 @@ def result_path():
     return result
 
 
-def test_dhrystone(runner, result_path):
+@pytest.mark.parametrize(['report_name'], [
+    ('dhrystone',),
+    ('whetstone',),
+    ('dpi',),
+    ('ramspeed',),
+    ('ssl',)
+])
+def test_dhrystone(report_name, runner, result_path):
     """Test dhrystone report"""
 
-    result = runner.invoke(cli, ['report', 'show', 'dhrystone', '-p', result_path])
-    assert "Benchmark..............................................................." \
-           "...................dhrystone" in result.output
-    assert "Score..................................................................." \
-           "..................63529.6"
-
-
-def test_whetstone(runner, result_path):
-    """ Test whetstone output"""
-
-    result = runner.invoke(cli, ['report', 'show', 'whetstone', '-p', result_path])
-    assert "Number................................................................." \
-           "...........................40" in result.output
-    assert "Total CPUs............................................................." \
-           "...........................40"
-
-
-def test_dpi(runner, result_path):
-    """ Test dpi report"""
-    result = runner.invoke(cli, ['report', 'show', 'dpi', '-p', result_path])
-    assert "Bits per Second..................................................." \
-           ".............................3.638" in result.output
-    assert "Packets per Second................................................" \
-           ".............................1.458" in result.output
-
-
-def test_ramspeed(runner, result_path):
-    """ Test ramspeed report """
-    result = runner.invoke(cli, ['report', 'show', 'ramspeed', '-p', result_path])
-    assert "Float Addition........................................................" \
-           "......................10522.33" in result.output
-    assert "Integer Average........................................................" \
-           ".....................11466.52" in result.output
-
-
-def test_ssl(runner, result_path):
-    """ Test ssl report"""
-
-    result = runner.invoke(cli, ['report', 'show', 'ssl', '-p', result_path])
-    assert "8192............................................................." \
-           ".........................667303.94k" in result.output
-    assert "1024.............................................................." \
-           "..........................100088.3" in result.output
-
-
-def test_sys(runner, result_path):
-    """ Test sys_info """
-
-    result = runner.invoke(cli, ['report', 'show', 'ssl', '-p', result_path])
-    assert "System Information" in result.output
-    assert "Host Name........................................................" \
-           ".................node-38.zte.com.cn" in result.output
-    assert "Operating System.................................................." \
-           "...............Ubuntu 16.04 xenial" in result.output
+    result = runner.invoke(cli, ['report', 'show', report_name, '-p', result_path])
+    for line in str(result).split('\n'):
+        assert len(line) <= 80
index 7ece466..11fb3f7 100644 (file)
@@ -29,60 +29,16 @@ def test_constructor(console_reporter):
     assert isinstance(console_reporter, ConsoleReporter)
 
 
-def test_dhrystone(console_reporter, result_path):
+@pytest.mark.parametrize(['template_name'], [
+    ('dhrystone',),
+    ('whetstone',),
+    ('dpi',),
+    ('ramspeed',),
+    ('ssl',)
+])
+def test_templates(template_name, console_reporter, result_path):
     """ Test dhrystone report"""
 
-    result = console_reporter.render('dhrystone', result_path)
-    assert "Benchmark..............................................................." \
-           "...................dhrystone" in result
-
-
-def test_whetstone(console_reporter, result_path):
-    """ Test whetstone output"""
-
-    result = console_reporter.render('whetstone', result_path)
-    assert "Number................................................................." \
-           "...........................40" in result
-    assert "Total CPUs............................................................." \
-           "...........................40" in result
-
-
-def test_dpi(console_reporter, result_path):
-    """ Test dpi report"""
-
-    result = console_reporter.render('dpi', result_path)
-    assert "Bits per Second..................................................." \
-           ".............................3.638" in result
-    assert "Packets per Second................................................" \
-           ".............................1.458" in result
-
-
-def test_ramspeed(console_reporter, result_path):
-    """ Test ramspeed report """
-
-    result = console_reporter.render('ramspeed', result_path)
-    assert "Float Addition........................................................" \
-           "......................10522.33" in result
-    assert "Integer Average........................................................" \
-           ".....................11466.52" in result
-
-
-def test_ssl(console_reporter, result_path):
-    """ Test ssl report"""
-
-    result = console_reporter.render('ssl', result_path)
-    assert "8192............................................................." \
-           ".........................667303.94k" in result
-    assert "1024.............................................................." \
-           "..........................100088.3" in result
-
-
-def test_sys(console_reporter, result_path):
-    """ Test sys_info """
-
-    result = console_reporter.render('ssl', result_path)
-    assert "System Information" in result
-    assert "Host Name........................................................" \
-           ".................node-38.zte.com.cn" in result
-    assert "Operating System.................................................." \
-           "...............Ubuntu 16.04 xenial" in result
+    result = console_reporter.render(template_name, result_path)
+    for line in result.split('\n'):
+        assert len(line) <= 80