diff --git a/.gitignore b/.gitignore index 8c34d19..16ddcaf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -test_HTMLTestRunner.py - .idea *.pyc -*.pyo \ No newline at end of file +*.pyo diff --git a/.travis.yml b/.travis.yml index 3b72857..3be5531 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,5 @@ python: - "2.7" # command to run tests script: - - python tests.py - - python test_HTMLTestRunner.py + - python test/tests.py + - python test/test_HTMLTestRunner.py diff --git a/LECENSE.md b/LICENSE.md similarity index 100% rename from LECENSE.md rename to LICENSE.md diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8286371 --- /dev/null +++ b/setup.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +from setuptools import setup + +setup( + name='html-testRunner2', + version='0.1.0', + description="A Test Runner in python, for Human Readable HTML Reports", + packages=[ + 'HTMLTestRunner', + ], + package_dir={'HTMLTestRunner': 'src'}, + include_package_data=True, + + package_data={'HTMLTestRunner': ['resources/css/*.*', 'resources/fonts/*.*', 'resources/js/*.*', 'resources/templates/*.*']} +) diff --git a/HTMLTestRunner.py b/src/HTMLTestRunner.py similarity index 92% rename from HTMLTestRunner.py rename to src/HTMLTestRunner.py index abb6fbf..6e570f3 100644 --- a/HTMLTestRunner.py +++ b/src/HTMLTestRunner.py @@ -1,5 +1,6 @@ import StringIO import datetime +import os import sys import unittest from xml.sax import saxutils @@ -7,6 +8,8 @@ __author__ = "Wai Yip Tung" __version__ = "2.0.0" +FILE_PATH = os.path.dirname(__file__) +RESOURCES_ROOT = os.path.join(FILE_PATH, 'resources') # TODO: color stderr # TODO: simplify javascript using , more than 1 class in the class attribute? @@ -109,46 +112,46 @@ class TemplateMixin(object): # ------------------------------------------------------------------- # # variables: (title, generator, stylesheet, heading, report, ending) - HTML_TEMPLATE = open('templates/report.html', 'r').read().encode('utf-8') + HTML_TEMPLATE = open(os.path.join(RESOURCES_ROOT, 'templates/report.html'), 'r').read().encode('utf-8') # ------------------------------------------------------------------- # # Stylesheet # ------------------------------------------------------------------- # # alternatively use a for external style sheet, e.g. # - STYLESHEET_TEMPLATE = open('templates/head_inserts.html', 'r').read() \ + STYLESHEET_TEMPLATE = open(os.path.join(RESOURCES_ROOT, 'templates/head_inserts.html'), 'r').read() \ .encode('utf-8') # ------------------------------------------------------------------- # # Heading # ------------------------------------------------------------------- # # variables: (title, parameters, description) - HEADING_TEMPLATE = open('templates/header.html', 'r').read() \ + HEADING_TEMPLATE = open(os.path.join(RESOURCES_ROOT, 'templates/header.html'), 'r').read() \ .encode('utf-8') # variables: (name, value) - HEADING_ATTRIBUTE_TEMPLATE = open('templates/header_parameters.html', 'r')\ + HEADING_ATTRIBUTE_TEMPLATE = open(os.path.join(RESOURCES_ROOT, 'templates/header_parameters.html'), 'r')\ .read().encode('utf-8') # ------------------------------------------------------------------- # # Report # ------------------------------------------------------------------- # # variables: (test_list, count, Pass, fail, error, skip) - REPORT__TABLE_TEMPLATE = open('templates/result_table.html', 'r') \ + REPORT__TABLE_TEMPLATE = open(os.path.join(RESOURCES_ROOT, 'templates/result_table.html'), 'r') \ .read().encode('utf-8') # variables: (style, desc, count, Pass, fail, error, cid) - REPORT_CLASS_TEMPLATE = open('templates/test_class.html', 'r').read()\ + REPORT_CLASS_TEMPLATE = open(os.path.join(RESOURCES_ROOT, 'templates/test_class.html'), 'r').read()\ .encode('utf-8') # variables: (tid, Class, style, desc, status) REPORT_TEST_WITH_OUTPUT_TMPL = \ - open('templates/report_test_with_output.html', 'r').read()\ + open(os.path.join(RESOURCES_ROOT, 'templates/report_test_with_output.html'), 'r').read()\ .encode('utf-8') # variables: (tid, Class, style, desc, status) REPORT_TEST_NO_OUTPUT_TEMPLATE = \ - open('templates/report_test_no_output.html', 'r').read()\ + open(os.path.join(RESOURCES_ROOT, 'templates/report_test_no_output.html'), 'r').read()\ .encode('utf-8') # variables: (id, output) @@ -157,7 +160,7 @@ class TemplateMixin(object): # ------------------------------------------------------------------- # # ENDING # ------------------------------------------------------------------- # - ENDING_TEMPLATE = open('templates/footer.html', 'r').read()\ + ENDING_TEMPLATE = open(os.path.join(RESOURCES_ROOT, 'templates/footer.html'), 'r').read()\ .encode('utf-8') @@ -290,6 +293,20 @@ def sort_result(result_list): return r +def fake_attrs(): + g2attrs = [ + ('My Project Name', 'Fake Project Name'), + ('Reponsible Team', 'Fake Team'), + ('Build Number', '42'), + ] + g3attrs = [ + ('Product Under Test', 'The Fake Product Site'), + ('Product Team', 'Fake Product Team') + ] + attrs = {'group2': g2attrs, 'group3': g3attrs} + return attrs + + class HTMLTestRunner(TemplateMixin): def __init__(self, stream=sys.stdout, verbosity=1, title=None, description=None, attrs=None): @@ -306,6 +323,9 @@ def __init__(self, stream=sys.stdout, verbosity=1, title=None, else: self.description = description + if attrs is None: + attrs = fake_attrs() + self.attributes = attrs self.startTime = datetime.datetime.now() @@ -368,7 +388,7 @@ def generate_report(self, result): self.stream.write(output.encode('utf8')) def _generate_stylesheet(self): - return self.STYLESHEET_TEMPLATE + return self.STYLESHEET_TEMPLATE % dict(root_dir=RESOURCES_ROOT) def _parse_attributes_group(self, group): attrs_list = [] diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/css/bootstrap-theme.css b/src/resources/css/bootstrap-theme.css similarity index 100% rename from css/bootstrap-theme.css rename to src/resources/css/bootstrap-theme.css diff --git a/css/bootstrap-theme.css.map b/src/resources/css/bootstrap-theme.css.map similarity index 100% rename from css/bootstrap-theme.css.map rename to src/resources/css/bootstrap-theme.css.map diff --git a/css/bootstrap-theme.min.css b/src/resources/css/bootstrap-theme.min.css similarity index 100% rename from css/bootstrap-theme.min.css rename to src/resources/css/bootstrap-theme.min.css diff --git a/css/bootstrap-theme.min.css.map b/src/resources/css/bootstrap-theme.min.css.map similarity index 100% rename from css/bootstrap-theme.min.css.map rename to src/resources/css/bootstrap-theme.min.css.map diff --git a/css/bootstrap.css b/src/resources/css/bootstrap.css similarity index 100% rename from css/bootstrap.css rename to src/resources/css/bootstrap.css diff --git a/css/bootstrap.css.map b/src/resources/css/bootstrap.css.map similarity index 100% rename from css/bootstrap.css.map rename to src/resources/css/bootstrap.css.map diff --git a/css/bootstrap.min.css b/src/resources/css/bootstrap.min.css similarity index 100% rename from css/bootstrap.min.css rename to src/resources/css/bootstrap.min.css diff --git a/css/bootstrap.min.css.map b/src/resources/css/bootstrap.min.css.map similarity index 100% rename from css/bootstrap.min.css.map rename to src/resources/css/bootstrap.min.css.map diff --git a/css/runner.css b/src/resources/css/runner.css similarity index 100% rename from css/runner.css rename to src/resources/css/runner.css diff --git a/fonts/glyphicons-halflings-regular.eot b/src/resources/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from fonts/glyphicons-halflings-regular.eot rename to src/resources/fonts/glyphicons-halflings-regular.eot diff --git a/fonts/glyphicons-halflings-regular.svg b/src/resources/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from fonts/glyphicons-halflings-regular.svg rename to src/resources/fonts/glyphicons-halflings-regular.svg diff --git a/fonts/glyphicons-halflings-regular.ttf b/src/resources/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from fonts/glyphicons-halflings-regular.ttf rename to src/resources/fonts/glyphicons-halflings-regular.ttf diff --git a/fonts/glyphicons-halflings-regular.woff b/src/resources/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from fonts/glyphicons-halflings-regular.woff rename to src/resources/fonts/glyphicons-halflings-regular.woff diff --git a/fonts/glyphicons-halflings-regular.woff2 b/src/resources/fonts/glyphicons-halflings-regular.woff2 similarity index 100% rename from fonts/glyphicons-halflings-regular.woff2 rename to src/resources/fonts/glyphicons-halflings-regular.woff2 diff --git a/js/bootstrap.js b/src/resources/js/bootstrap.js similarity index 100% rename from js/bootstrap.js rename to src/resources/js/bootstrap.js diff --git a/js/bootstrap.min.js b/src/resources/js/bootstrap.min.js similarity index 100% rename from js/bootstrap.min.js rename to src/resources/js/bootstrap.min.js diff --git a/js/jquery-3.1.1.js b/src/resources/js/jquery-3.1.1.js similarity index 100% rename from js/jquery-3.1.1.js rename to src/resources/js/jquery-3.1.1.js diff --git a/js/npm.js b/src/resources/js/npm.js similarity index 100% rename from js/npm.js rename to src/resources/js/npm.js diff --git a/js/runner.js b/src/resources/js/runner.js similarity index 100% rename from js/runner.js rename to src/resources/js/runner.js diff --git a/templates/footer.html b/src/resources/templates/footer.html similarity index 100% rename from templates/footer.html rename to src/resources/templates/footer.html diff --git a/src/resources/templates/head_inserts.html b/src/resources/templates/head_inserts.html new file mode 100644 index 0000000..387b88a --- /dev/null +++ b/src/resources/templates/head_inserts.html @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/templates/header.html b/src/resources/templates/header.html similarity index 100% rename from templates/header.html rename to src/resources/templates/header.html diff --git a/templates/header_parameters.html b/src/resources/templates/header_parameters.html similarity index 100% rename from templates/header_parameters.html rename to src/resources/templates/header_parameters.html diff --git a/templates/report.html b/src/resources/templates/report.html similarity index 100% rename from templates/report.html rename to src/resources/templates/report.html diff --git a/templates/report_test_no_output.html b/src/resources/templates/report_test_no_output.html similarity index 100% rename from templates/report_test_no_output.html rename to src/resources/templates/report_test_no_output.html diff --git a/templates/report_test_with_output.html b/src/resources/templates/report_test_with_output.html similarity index 100% rename from templates/report_test_with_output.html rename to src/resources/templates/report_test_with_output.html diff --git a/templates/result_table.html b/src/resources/templates/result_table.html similarity index 100% rename from templates/result_table.html rename to src/resources/templates/result_table.html diff --git a/templates/test_class.html b/src/resources/templates/test_class.html similarity index 100% rename from templates/test_class.html rename to src/resources/templates/test_class.html diff --git a/templates/head_inserts.html b/templates/head_inserts.html deleted file mode 100644 index 809cdc3..0000000 --- a/templates/head_inserts.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/test_HTMLTestRunner.py b/test/test_HTMLTestRunner.py similarity index 100% rename from test_HTMLTestRunner.py rename to test/test_HTMLTestRunner.py diff --git a/tests.py b/test/tests.py similarity index 100% rename from tests.py rename to test/tests.py