Skip to content
Merged
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ This project adheres to [Semantic Versioning](http://semver.org/) and http://kee
- Moved license content from python file to LICENSE
- Updated README to reflect current state of project
- Upgraded to support Python 3.4.3

### Changed
- Imported select functions only rather than the entire module.
- remove unused variables.
- Remove string slice and use a datetime function instead.
- Now compatible with python 3.5.2
- Added Contributor Dark-Passenger to Readme
35 changes: 16 additions & 19 deletions HTMLTestRunner.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
__version__ = "1.0.0"
__version__ = "1.0.1"

import datetime
import io as StringIO
import sys
import time
import unittest
from datetime import datetime
from io import StringIO
from unittest import TestResult, TestProgram
from xml.sax import saxutils
import sys


# ------------------------------------------------------------------------
# The redirectors below are used to capture output during testing. Output
# sent to sys.stdout and sys.stderr are automatically captured. However
# in some cases sys.stdout is already cached before HTMLTestRunner is
# sent to stdout and stderr are automatically captured. However
# in some cases stdout is already cached before HTMLTestRunner is
# invoked (e.g. calling logging.basicConfig). In order to capture those
# output, use the redirectors for the cached stream.
#
Expand Down Expand Up @@ -426,15 +425,13 @@ class Template_mixin(object):
# -------------------- The end of the Template class -------------------


TestResult = unittest.TestResult

class _TestResult(TestResult):
# note: _TestResult is a pure representation of results.
# It lacks the output and reporting ability compares to unittest._TextTestResult.

def __init__(self, verbosity=1):
TestResult.__init__(self)
self.outputBuffer = StringIO.StringIO()
self.outputBuffer = StringIO()
self.stdout0 = None
self.stderr0 = None
self.success_count = 0
Expand Down Expand Up @@ -498,7 +495,7 @@ def addSuccess(self, test):
def addError(self, test, err):
self.error_count += 1
TestResult.addError(self, test, err)
_, _exc_str = self.errors[-1]
_exc_str = self.errors[-1][1]
output = self.complete_output()
self.result.append((2, test, output, _exc_str))
if self.verbosity > 1:
Expand All @@ -511,7 +508,7 @@ def addError(self, test, err):
def addFailure(self, test, err):
self.failure_count += 1
TestResult.addFailure(self, test, err)
_, _exc_str = self.failures[-1]
_exc_str = self.failures[-1][1]
output = self.complete_output()
self.result.append((1, test, output, _exc_str))
if self.verbosity > 1:
Expand All @@ -537,14 +534,14 @@ def __init__(self, stream=sys.stdout, verbosity=1, title=None, description=None)
else:
self.description = description

self.startTime = datetime.datetime.now()
self.startTime = datetime.now().replace(microsecond=0)


def run(self, test):
"Run the given test case or test suite."
result = _TestResult(self.verbosity)
test(result)
self.stopTime = datetime.datetime.now()
self.stopTime = datetime.now().replace(microsecond=0)
self.generateReport(test, result)
print('Time Elapsed: {}'.format((self.stopTime-self.startTime)), file=sys.stderr)
return result
Expand All @@ -570,7 +567,7 @@ def getReportAttributes(self, result):
Return report attributes as a list of (name, value).
Override this to add custom attributes.
"""
startTime = str(self.startTime)[:19]
startTime = str(self.startTime)
duration = str(self.stopTime - self.startTime)
status = []
if result.success_count: status.append('Pass %s' % result.success_count)
Expand Down Expand Up @@ -719,7 +716,7 @@ def _generate_ending(self):
# Note: Reuse unittest.TestProgram to launch test. In the future we may
# build our own launcher to support more specific command line
# parameters like test title, CSS, etc.
class TestProgram(unittest.TestProgram):
class _TestProgram(TestProgram):
"""
A variation of the unittest.TestProgram. Please refer to the base
class for command line parameters.
Expand All @@ -730,9 +727,9 @@ def runTests(self):
# we have to instantiate HTMLTestRunner before we know self.verbosity.
if self.testRunner is None:
self.testRunner = HTMLTestRunner(verbosity=self.verbosity)
unittest.TestProgram.runTests(self)
TestProgram.runTests(self)

main = TestProgram
main = _TestProgram

##############################################################################
# Executing this module from the command line
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ as-is.

Way Yip Tung - https://github.com/tungwaiyip
Asish Dash - https://github.com/dash0002
Dhruv Paranjape - https://github.com/dark-passenger

Contributions are gladly accepted as this is a side project at best. Please, also
consider this when looking at feedback cycles, issues, pull requests, etc.
Expand Down