From da89717a82bf97939c3a264ad53fe5e3fbf7216a Mon Sep 17 00:00:00 2001 From: Asish Dash Date: Thu, 12 Nov 2015 15:27:01 +0100 Subject: [PATCH 1/8] Updated for python3 (test_HTMLTestRunner.py still work in progress) --- HTMLTestRunner.py | 14 +++++++------- test_HTMLTestRunner.py | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/HTMLTestRunner.py b/HTMLTestRunner.py index 8d60600..9cacd3e 100644 --- a/HTMLTestRunner.py +++ b/HTMLTestRunner.py @@ -94,7 +94,7 @@ # TODO: simplify javascript using ,ore than 1 class in the class attribute? import datetime -import StringIO +import io as StringIO import sys import time import unittest @@ -114,7 +114,7 @@ def to_unicode(s): try: - return unicode(s) + return str(s) except UnicodeDecodeError: # s is non ascii byte string return s.decode('unicode_escape') @@ -639,7 +639,7 @@ def run(self, test): test(result) self.stopTime = datetime.datetime.now() self.generateReport(test, result) - print >>sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime) + print('Time Elapsed: {}'.format((self.stopTime-self.startTime)), file=sys.stderr) return result @@ -650,7 +650,7 @@ def sortResult(self, result_list): classes = [] for n,t,o,e in result_list: cls = t.__class__ - if not rmap.has_key(cls): + if not cls in rmap: rmap[cls] = [] classes.append(cls) rmap[cls].append((n,t,o,e)) @@ -695,7 +695,7 @@ def generateReport(self, test, result): report = report, ending = ending, ) - self.stream.write(output.encode('utf8')) + self.stream.write(output) def _generate_stylesheet(self): @@ -774,13 +774,13 @@ def _generate_report_test(self, rows, cid, tid, n, t, o, e): if isinstance(o,str): # TODO: some problem with 'string_escape': it escape \n and mess up formating # uo = unicode(o.encode('string_escape')) - uo = o.decode('latin-1') + uo = bytes(o, 'utf-8').decode('latin-1') else: uo = o if isinstance(e,str): # TODO: some problem with 'string_escape': it escape \n and mess up formating # ue = unicode(e.encode('string_escape')) - ue = e.decode('latin-1') + ue = bytes(e, 'utf-8').decode('latin-1') else: ue = e diff --git a/test_HTMLTestRunner.py b/test_HTMLTestRunner.py index 3967ce8..56d0c81 100644 --- a/test_HTMLTestRunner.py +++ b/test_HTMLTestRunner.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -import StringIO +import io as StringIO import sys import unittest @@ -53,9 +53,9 @@ def test_fail(self): class SampleOutputTestBase(unittest.TestCase): """ Base TestCase. Generates 4 test cases x different content type. """ def test_1(self): - print self.MESSAGE + print(self.MESSAGE) def test_2(self): - print >>sys.stderr, self.MESSAGE + print(self.MESSAGE, file=sys.stderr) def test_3(self): self.fail(self.MESSAGE) def test_4(self): @@ -68,7 +68,7 @@ class SampleTestHTML(SampleOutputTestBase): MESSAGE = 'the message is 5 symbols: <>&"\'\nplus the HTML entity string: [©] on a second line' class SampleTestLatin1(SampleOutputTestBase): - MESSAGE = u'the message is áéíóú'.encode('latin-1') + MESSAGE = 'the message is áéíóú'.encode('latin-1') class SampleTestUnicode(SampleOutputTestBase): u""" Unicode (統一碼) test """ @@ -196,6 +196,7 @@ def test_main(self): >test_2< pass + the message is \u8563 >test_3< @@ -214,11 +215,11 @@ def test_main(self): """ # check out the output - byte_output = buf.getvalue() + str_output = buf.getvalue() # output the main test output for debugging & demo - print byte_output + print(str_output) # HTMLTestRunner pumps UTF-8 output - output = byte_output.decode('utf-8') + output = str_output self._checkoutput(output,EXPECTED) @@ -229,7 +230,7 @@ def _checkoutput(self,output,EXPECTED): continue j = output.find(p,i) if j < 0: - self.fail(safe_str('Pattern not found lineno %s: "%s"' % (lineno+1,p))) + self.fail('Pattern not found lineno %s: "%s"' % (lineno+1,p)) i = j + len(p) @@ -250,4 +251,3 @@ def _checkoutput(self,output,EXPECTED): # we will use standard library's TextTestRunner to reduce the nesting # that may confuse people. #HTMLTestRunner.main(argv=argv) - From c8864fc013e9f4d90b0ebc355377dc9d43540686 Mon Sep 17 00:00:00 2001 From: Asish Dash Date: Thu, 12 Nov 2015 15:27:41 +0100 Subject: [PATCH 2/8] no message --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc From acc68229bba6d643f0f6733aea8b22dbf1794622 Mon Sep 17 00:00:00 2001 From: dash0002 Date: Thu, 12 Nov 2015 15:37:17 +0100 Subject: [PATCH 3/8] Update README --- README | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README b/README index b1beea9..b29bb74 100644 --- a/README +++ b/README @@ -1,5 +1,4 @@ -HTMLTestRunner is an extension to the Python standard library's unittest module. -It generates easy to use HTML test reports. HTMLTestRunner is released under a -BSD style license. +# Overview # +This project is a python 3 compliant version of HTMLTestRunner. HTMLTestRunner was originally written by Wai Yip Tung as an extension point to python unittest module + -Only a single file module HTMLTestRunner.py is needed to generate your report. From e368abb690ef1e0ba716d115426e51aa4e07b1b8 Mon Sep 17 00:00:00 2001 From: Asish Dash Date: Fri, 13 Nov 2015 13:56:10 +0100 Subject: [PATCH 4/8] Updated content --- CHANGELOG.md | 12 +++++++ HTMLTestRunner.py | 92 ----------------------------------------------- LICENSE | 27 ++++++++++++++ README | 68 +++++++++++++++++++++++++++++++++-- 4 files changed, 105 insertions(+), 94 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 LICENSE diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f2083ab --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# Change Log +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/) and http://keepachangelog.com/. + +## [Unreleased] +### Added +- CHANGELOG.md from @dash0002 + +### Changed +- Moved license content from python file to LICENSE +- Updated README to reflect current state of project +- Upgraded to support Python 3.4.3 diff --git a/HTMLTestRunner.py b/HTMLTestRunner.py index 9cacd3e..6334f2d 100644 --- a/HTMLTestRunner.py +++ b/HTMLTestRunner.py @@ -1,95 +1,3 @@ -""" -A TestRunner for use with the Python unit testing framework. It -generates a HTML report to show the result at a glance. - -The simplest way to use this is to invoke its main method. E.g. - - import unittest - import HTMLTestRunner - - ... define your tests ... - - if __name__ == '__main__': - HTMLTestRunner.main() - - -For more customization options, instantiates a HTMLTestRunner object. -HTMLTestRunner is a counterpart to unittest's TextTestRunner. E.g. - - # output to a file - fp = file('my_report.html', 'wb') - runner = HTMLTestRunner.HTMLTestRunner( - stream=fp, - title='My unit test', - description='This demonstrates the report output by HTMLTestRunner.' - ) - - # Use an external stylesheet. - # See the Template_mixin class for more customizable options - runner.STYLESHEET_TMPL = '' - - # run the test - runner.run(my_test_suite) - - ------------------------------------------------------------------------- -Copyright (c) 2004-2007, Wai Yip Tung -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name Wai Yip Tung nor the names of its contributors may be - used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -""" - -# URL: http://tungwaiyip.info/software/HTMLTestRunner.html - -__author__ = "Wai Yip Tung" -__version__ = "0.8.3" - - -""" -Change History - -Version 0.8.3 -* Prevent crash on class or module-level exceptions (Darren Wurf). - -Version 0.8.2 -* Show output inline instead of popup window (Viorel Lupu). - -Version in 0.8.1 -* Validated XHTML (Wolfgang Borgert). -* Added description of test classes and test cases. - -Version in 0.8.0 -* Define Template_mixin class for customization. -* Workaround a IE 6 bug that it does not treat