Merge lp:~chipaca/testscenarios/fix-with-py3 into lp:~testtools-committers/testscenarios/trunk

Proposed by John Lenton
Status: Merged
Merge reported by: Robert Collins
Merged at revision: not available
Proposed branch: lp:~chipaca/testscenarios/fix-with-py3
Merge into: lp:~testtools-committers/testscenarios/trunk
Diff against target: 77 lines (+11/-6)
3 files modified
README (+6/-3)
lib/testscenarios/scenarios.py (+3/-2)
setup.py (+2/-1)
To merge this branch: bzr merge lp:~chipaca/testscenarios/fix-with-py3
Reviewer Review Type Date Requested Status
Robert Collins Needs Resubmitting
John Vandenberg (community) Approve
Review via email: mp+105447@code.launchpad.net

Description of the change

Fix for big justice with python 3.

Fairly straightforward. The only hairy bit is the use of StringIO.StringIO vs io.BytesIO and io.StringIO in the docstring, versus unittest.runner's writing a bare "." to the stream in both python 2 and 3. Resolved with some import shenanigans.

To post a comment you must log in.
23. By John Lenton

make setup.py work also

Revision history for this message
John Vandenberg (jayvdb) wrote :

I think this should be merged. I have tested setup.py and 'make check' with Python 3.2, 3.3 and 3.4.

There are two tests with fail on Python 3, due to the addition of '.<locals>.' in the name of local objects. However that only affects the visual UI, and is arguably correct. I have a separate patch for that; will try to figure out how to upload load that to launchpad.

For Python 3.1.5 (officially retired anyway), unittest2-1.0.1 fails, and testtools depends on that.
NameError: global name 'callable' is not defined

review: Approve
Revision history for this message
John Vandenberg (jayvdb) wrote :

Hmm, looking at this more closely, a bit more explanation is needed. This patch is needed to catch up with the released version on https://pypi.python.org/pypi/testscenarios.

pypi lists v0.4 as the current version, and was released on 2013-01-27.

An inspection of the diff between lp:testscenarios and 0.4 indicates that this changeset was essentially included into pypi 0.4, without being merged here in launchpad, and is the only _functional_ difference between lp:testscenarios and pypi 0.4.

So, this code is very mature, having been in the wild for a long time, distributed via pypi.

Revision history for this message
Robert Collins (lifeless) wrote :

testscenarios code is maintained on github now, pull requests should be submitted there, bug reports here (preferred) or there.

review: Needs Resubmitting
Revision history for this message
Robert Collins (lifeless) wrote :

Huh no sorry, I haven't completed the migration, only intended to. I'll have to check my local tree to see the status.

Revision history for this message
Robert Collins (lifeless) wrote :

Huh no sorry, I haven't completed the migration, only intended to. I'll have to check my local tree to see the status.

Revision history for this message
John Lenton (chipaca) wrote :

You do realise you're asking me to resubmit a merge proposal from three years ago, yes?

Revision history for this message
Robert Collins (lifeless) wrote :

@chipaca sorry, I didn't really process that it was a different John initially, also I was confused about which projects I'd move the code over to github for. I'm not sure what happened with this here MP, since testscenarios is clearly 3 compatible and has been for ages, likely from this code, or dual evolution : EIHAVENOCLUE.

Revision history for this message
John Vandenberg (jayvdb) wrote :

I've added a patch to bring lp up to date with pypi: https://code.launchpad.net/~jayvdb/testscenarios/0.4

However, a move to github would be welcome.

As background for reviving this lp project,
I've been building a rather too complex test framework for pywikibot, and want to migrate to a separately maintained framework, and testscenarios looks to be the closest match.<https://phabricator.wikimedia.org/T85899> And I couldnt find it on github...

Any better suggestions would be appreciated.

Revision history for this message
Robert Collins (lifeless) wrote :

Code equivalent to this is in trunk.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2012-04-04 10:02:46 +0000
3+++ README 2012-05-11 07:43:19 +0000
4@@ -98,7 +98,10 @@
5 ``testscenarios.generate_scenarios()``. For instance::
6
7 >>> import unittest
8- >>> import StringIO
9+ >>> try:
10+ ... from StringIO import StringIO
11+ ... except ImportError:
12+ ... from io import StringIO
13 >>> from testscenarios.scenarios import generate_scenarios
14
15 This can work with loaders and runners from the standard library, or possibly other
16@@ -106,7 +109,7 @@
17
18 >>> loader = unittest.TestLoader()
19 >>> test_suite = unittest.TestSuite()
20- >>> runner = unittest.TextTestRunner(stream=StringIO.StringIO())
21+ >>> runner = unittest.TextTestRunner(stream=StringIO())
22
23 >>> mytests = loader.loadTestsFromNames(['doc.test_sample'])
24 >>> test_suite.addTests(generate_scenarios(mytests))
25@@ -211,7 +214,7 @@
26 ...
27 >>> suite2 = unittest.TestSuite()
28 >>> suite2.addTests(generate_scenarios(suite))
29- >>> print suite2.countTestCases()
30+ >>> print(suite2.countTestCases())
31 4
32
33 Dynamic Scenarios
34
35=== modified file 'lib/testscenarios/scenarios.py'
36--- lib/testscenarios/scenarios.py 2012-04-04 10:02:46 +0000
37+++ lib/testscenarios/scenarios.py 2012-05-11 07:43:19 +0000
38@@ -34,7 +34,7 @@
39 from testtools import iterate_tests
40
41
42-def apply_scenario((name, parameters), test):
43+def apply_scenario(scenario, test):
44 """Apply scenario to test.
45
46 :param scenario: A tuple (name, parameters) to apply to the test. The test
47@@ -43,6 +43,7 @@
48 :param test: The test to apply the scenario to. This test is unaltered.
49 :return: A new test cloned from test, with the scenario applied.
50 """
51+ (name, parameters) = scenario
52 scenario_suffix = '(' + name + ')'
53 newtest = clone_test_with_new_id(test,
54 test.id() + scenario_suffix)
55@@ -50,7 +51,7 @@
56 if test_desc is not None:
57 newtest_desc = "%(test_desc)s %(scenario_suffix)s" % vars()
58 newtest.shortDescription = (lambda: newtest_desc)
59- for key, value in parameters.iteritems():
60+ for key, value in parameters.items():
61 setattr(newtest, key, value)
62 return newtest
63
64
65=== modified file 'setup.py'
66--- setup.py 2012-04-04 10:46:52 +0000
67+++ setup.py 2012-05-11 07:43:19 +0000
68@@ -3,7 +3,8 @@
69 from distutils.core import setup
70 import os.path
71
72-description = file(os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()
73+description = open(os.path.join(os.path.dirname(__file__),
74+ 'README'), 'rb').read().decode("utf-8")
75
76 setup(name="testscenarios",
77 version="0.3",

Subscribers

People subscribed via source and target branches