Add blocking suites to daily summary

Add title and optional script to html header
This commit is contained in:
Erick Fejta
2016-04-15 18:09:58 -07:00
parent 64fbb4a81e
commit e01825bfee
5 changed files with 350 additions and 122 deletions

View File

@@ -25,46 +25,112 @@ import unittest
import gen_html
TEST_DATA = {
"test1":
{"kubernetes-release": [{"build": 3, "failed": False, "time": 3.52},
{"build": 4, "failed": True, "time": 63.21}],
"kubernetes-debug": [{"build": 5, "failed": False, "time": 7.56},
{"build": 6, "failed": False, "time": 8.43}],
'test1':
{'kubernetes-release': [{'build': 3, 'failed': False, 'time': 3.52},
{'build': 4, 'failed': True, 'time': 63.21}],
'kubernetes-debug': [{'build': 5, 'failed': False, 'time': 7.56},
{'build': 6, 'failed': False, 'time': 8.43}],
},
"test2":
{"kubernetes-debug": [{"build": 6, "failed": True, "time": 3.53}]},
'test2':
{'kubernetes-debug': [{'build': 6, 'failed': True, 'time': 3.53}]},
}
class GenHtmlTest(unittest.TestCase):
def gen_html(self, *args):
"""Unit tests for gen_html.py."""
# pylint: disable=invalid-name
def testHtmlHeader_NoScript(self):
result = '\n'.join(gen_html.html_header('', False))
self.assertNotIn('<script', result)
def testHtmlHeader_NoTitle(self):
def Test(title):
result = '\n'.join(gen_html.html_header(title, False))
self.assertNotIn('<title', result)
Test('')
Test(None)
def testHtmlHeader_Title(self):
lines = gen_html.html_header('foo', False)
for item in lines:
if '<title' in item:
self.assertIn('foo', item)
break
else:
self.fail('No foo in: %s' % '\n'.join(lines))
def testHtmlHeader_Script(self):
lines = gen_html.html_header('', True)
for item in lines:
if '<script' in item:
break
else:
self.fail('No script in: %s' % '\n'.join(lines))
@staticmethod
def gen_html(*args):
"""Call gen_html with TEST_DATA."""
return gen_html.gen_html(TEST_DATA, *args)[0]
def testGenHtml(self):
"""Test that the expected tests and jobs are in the results."""
html = self.gen_html('')
self.assertIn("test1", html)
self.assertIn("test2", html)
self.assertIn("release", html)
self.assertIn("debug", html)
self.assertIn('test1', html)
self.assertIn('test2', html)
self.assertIn('release', html)
self.assertIn('debug', html)
def testGenHtmlFilter(self):
"""Test that filtering to just the release jobs works."""
html = self.gen_html('release')
self.assertIn("release", html)
self.assertIn('release', html)
self.assertIn('skipped">\ntest2', html)
self.assertNotIn("debug", html)
def testGenHtmlFilterExact(self):
html = self.gen_html('release', True)
self.assertNotIn('debug', html)
def testGenHtmlFilterExact(self):
"""Test that filtering to an exact name works."""
html = self.gen_html('release', True)
self.assertIn('release', html)
self.assertNotIn('debug', html)
def testGetOptions(self):
"""Test argument parsing works correctly."""
def check(args, expected_output_dir, expected_input):
"""Check that args is parsed correctly."""
options = gen_html.get_options(args)
self.assertEquals(expected_output_dir, options.output_dir)
self.assertEquals(expected_input, options.input)
check(['--output-dir=foo', '--input=bar'], 'foo', 'bar')
check(['--output-dir', 'foo', '--input', 'bar'], 'foo', 'bar')
check(['--input=bar', '--output-dir=foo'], 'foo', 'bar')
def testGetOptions_Missing(self):
"""Test missing arguments raise an exception."""
def check(args):
"""Check that args raise an exception."""
with self.assertRaises(SystemExit):
gen_html.get_options(args)
check([])
check(['--output-dir=foo'])
check(['--input=bar'])
def testMain(self):
"""Test main() creates pages."""
temp_dir = tempfile.mkdtemp(prefix='kube-test-hist-')
try:
tests_json = os.path.join(temp_dir, 'tests.json')
with open(tests_json, 'w') as f:
json.dump(TEST_DATA, f)
gen_html.main(['--suites', '--prefixes', ',rel,deb',
'--output-dir', temp_dir, '--input', tests_json])
for page in ('index', 'suite-kubernetes-debug', 'tests', 'tests-rel', 'tests-deb'):
with open(tests_json, 'w') as buf:
json.dump(TEST_DATA, buf)
gen_html.main(tests_json, temp_dir)
for page in (
'index',
'tests-kubernetes',
'suite-kubernetes-release',
'suite-kubernetes-debug'):
self.assertTrue(os.path.exists('%s/%s.html' % (temp_dir, page)))
finally:
shutil.rmtree(temp_dir)