Skip to content

Commit e92a5fe

Browse files
authored
Merge pull request #3 from Dark-Passenger/master
Reduce namespace pollution by only importing specific functions.
2 parents 3ede4b3 + 1a55050 commit e92a5fe

3 files changed

Lines changed: 24 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ This project adheres to [Semantic Versioning](http://semver.org/) and http://kee
1010
- Moved license content from python file to LICENSE
1111
- Updated README to reflect current state of project
1212
- Upgraded to support Python 3.4.3
13+
14+
### Changed
15+
- Imported select functions only rather than the entire module.
16+
- remove unused variables.
17+
- Remove string slice and use a datetime function instead.
18+
- Now compatible with python 3.5.2
19+
- Added Contributor Dark-Passenger to Readme

HTMLTestRunner.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
__version__ = "1.0.0"
1+
__version__ = "1.0.1"
22

3-
import datetime
4-
import io as StringIO
5-
import sys
6-
import time
7-
import unittest
3+
from datetime import datetime
4+
from io import StringIO
5+
from unittest import TestResult, TestProgram
86
from xml.sax import saxutils
7+
import sys
98

109

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

428427

429-
TestResult = unittest.TestResult
430-
431428
class _TestResult(TestResult):
432429
# note: _TestResult is a pure representation of results.
433430
# It lacks the output and reporting ability compares to unittest._TextTestResult.
434431

435432
def __init__(self, verbosity=1):
436433
TestResult.__init__(self)
437-
self.outputBuffer = StringIO.StringIO()
434+
self.outputBuffer = StringIO()
438435
self.stdout0 = None
439436
self.stderr0 = None
440437
self.success_count = 0
@@ -498,7 +495,7 @@ def addSuccess(self, test):
498495
def addError(self, test, err):
499496
self.error_count += 1
500497
TestResult.addError(self, test, err)
501-
_, _exc_str = self.errors[-1]
498+
_exc_str = self.errors[-1][1]
502499
output = self.complete_output()
503500
self.result.append((2, test, output, _exc_str))
504501
if self.verbosity > 1:
@@ -511,7 +508,7 @@ def addError(self, test, err):
511508
def addFailure(self, test, err):
512509
self.failure_count += 1
513510
TestResult.addFailure(self, test, err)
514-
_, _exc_str = self.failures[-1]
511+
_exc_str = self.failures[-1][1]
515512
output = self.complete_output()
516513
self.result.append((1, test, output, _exc_str))
517514
if self.verbosity > 1:
@@ -537,14 +534,14 @@ def __init__(self, stream=sys.stdout, verbosity=1, title=None, description=None)
537534
else:
538535
self.description = description
539536

540-
self.startTime = datetime.datetime.now()
537+
self.startTime = datetime.now().replace(microsecond=0)
541538

542539

543540
def run(self, test):
544541
"Run the given test case or test suite."
545542
result = _TestResult(self.verbosity)
546543
test(result)
547-
self.stopTime = datetime.datetime.now()
544+
self.stopTime = datetime.now().replace(microsecond=0)
548545
self.generateReport(test, result)
549546
print('Time Elapsed: {}'.format((self.stopTime-self.startTime)), file=sys.stderr)
550547
return result
@@ -570,7 +567,7 @@ def getReportAttributes(self, result):
570567
Return report attributes as a list of (name, value).
571568
Override this to add custom attributes.
572569
"""
573-
startTime = str(self.startTime)[:19]
570+
startTime = str(self.startTime)
574571
duration = str(self.stopTime - self.startTime)
575572
status = []
576573
if result.success_count: status.append('Pass %s' % result.success_count)
@@ -719,7 +716,7 @@ def _generate_ending(self):
719716
# Note: Reuse unittest.TestProgram to launch test. In the future we may
720717
# build our own launcher to support more specific command line
721718
# parameters like test title, CSS, etc.
722-
class TestProgram(unittest.TestProgram):
719+
class _TestProgram(TestProgram):
723720
"""
724721
A variation of the unittest.TestProgram. Please refer to the base
725722
class for command line parameters.
@@ -730,9 +727,9 @@ def runTests(self):
730727
# we have to instantiate HTMLTestRunner before we know self.verbosity.
731728
if self.testRunner is None:
732729
self.testRunner = HTMLTestRunner(verbosity=self.verbosity)
733-
unittest.TestProgram.runTests(self)
730+
TestProgram.runTests(self)
734731

735-
main = TestProgram
732+
main = _TestProgram
736733

737734
##############################################################################
738735
# Executing this module from the command line

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ as-is.
5959

6060
Way Yip Tung - https://github.com/tungwaiyip
6161
Asish Dash - https://github.com/dash0002
62+
Dhruv Paranjape - https://github.com/dark-passenger
6263

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

0 commit comments

Comments
 (0)