Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganizing file layout + minor changes. #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
test_HTMLTestRunner.py

.idea

*.pyc
*.pyo
*.pyo
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
16 changes: 16 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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/*.*']}
)
40 changes: 30 additions & 10 deletions HTMLTestRunner.py → src/HTMLTestRunner.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import StringIO
import datetime
import os
import sys
import unittest
from xml.sax import saxutils

__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?
Expand Down Expand Up @@ -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 <link> for external style sheet, e.g.
# <link rel="stylesheet" href="$url" type="text/css">
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)
Expand All @@ -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')


Expand Down Expand Up @@ -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):
Expand All @@ -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()
Expand Down Expand Up @@ -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 = []
Expand Down
Empty file added src/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions src/resources/templates/head_inserts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- Bootstrap -->
<link href="%(root_dir)s/css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="%(root_dir)s/js/jquery-3.1.1.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="%(root_dir)s/js/bootstrap.min.js"></script>
<!-- Project CSS -->
<link href="%(root_dir)s/css/runner.css" rel="stylesheet">
<!-- Project JS -->
<script src="%(root_dir)s/js/runner.js"></script>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 0 additions & 10 deletions templates/head_inserts.html

This file was deleted.

File renamed without changes.
File renamed without changes.