Skip to content

Commit 1baeeab

Browse files
authored
Merge pull request #12 from jelmer/ruff-format
Format with ruff
2 parents 69a8175 + 2907ab6 commit 1baeeab

File tree

11 files changed

+210
-184
lines changed

11 files changed

+210
-184
lines changed

.github/workflows/python-package.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
- name: Run ruff
2727
run: |
2828
python -m ruff check .
29+
- name: Run ruff format
30+
run: |
31+
python -m ruff format --check .
2932
- name: Test with testtools
3033
run: |
3134
python -m testtools.run testscenarios.tests.test_suite

doc/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# dependency injection ('scenarios') by tests.
33
#
44
# Copyright (c) 2009, Robert Collins <robertc@robertcollins.net>
5-
#
5+
#
66
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
77
# license at the users choice. A copy of both licenses are available in the
88
# project source as Apache-2.0 and BSD. You may not use this file except in
99
# compliance with one of these two licences.
10-
#
10+
#
1111
# Unless required by applicable law or agreed to in writing, software
1212
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1313
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

doc/example.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# testscenarios: extensions to python unittest to allow declarative
22
# dependency injection ('scenarios') by tests.
33
# Copyright (c) 2009, Robert Collins <robertc@robertcollins.net>
4-
#
4+
#
55
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
66
# license at the users choice. A copy of both licenses are available in the
77
# project source as Apache-2.0 and BSD. You may not use this file except in
88
# compliance with one of these two licences.
9-
#
9+
#
1010
# Unless required by applicable law or agreed to in writing, software
1111
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1212
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -18,13 +18,12 @@
1818
from testscenarios import TestWithScenarios
1919

2020

21-
scenario1 = ('basic', {'attribute': 'value'})
22-
scenario2 = ('advanced', {'attribute': 'value2'})
21+
scenario1 = ("basic", {"attribute": "value"})
22+
scenario2 = ("advanced", {"attribute": "value2"})
2323

2424

2525
class SampleWithScenarios(TestWithScenarios):
26-
2726
scenarios = [scenario1, scenario2]
28-
27+
2928
def test_demo(self):
3029
self.assertIsInstance(self.attribute, str)

doc/test_sample.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# dependency injection ('scenarios') by tests.
33
#
44
# Copyright (c) 2009, Robert Collins <robertc@robertcollins.net>
5-
#
5+
#
66
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
77
# license at the users choice. A copy of both licenses are available in the
88
# project source as Apache-2.0 and BSD. You may not use this file except in
99
# compliance with one of these two licences.
10-
#
10+
#
1111
# Unless required by applicable law or agreed to in writing, software
1212
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1313
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -16,7 +16,7 @@
1616

1717
import unittest
1818

19-
class TestSample(unittest.TestCase):
2019

20+
class TestSample(unittest.TestCase):
2121
def test_so_easy(self):
2222
pass

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env python
22
import setuptools
33

4-
setuptools.setup(
5-
setup_requires=['pbr'],
6-
pbr=True)
4+
setuptools.setup(setup_requires=["pbr"], pbr=True)

testscenarios/__init__.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# dependency injection ('scenarios') by tests.
33
#
44
# Copyright (c) 2009, Robert Collins <robertc@robertcollins.net>
5-
#
5+
#
66
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
77
# license at the users choice. A copy of both licenses are available in the
88
# project source as Apache-2.0 and BSD. You may not use this file except in
99
# compliance with one of these two licences.
10-
#
10+
#
1111
# Unless required by applicable law or agreed to in writing, software
1212
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1313
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -39,20 +39,21 @@
3939
# If the releaselevel is 'final', then the tarball will be major.minor.micro.
4040
# Otherwise it is major.minor.micro~$(revno).
4141
from pbr.version import VersionInfo
42-
_version = VersionInfo('testscenarios')
42+
43+
_version = VersionInfo("testscenarios")
4344
__version__ = _version.semantic_version().version_tuple()
4445
version = _version.release_string()
4546

4647
__all__ = [
47-
'TestWithScenarios',
48-
'WithScenarios',
49-
'apply_scenario',
50-
'apply_scenarios',
51-
'generate_scenarios',
52-
'load_tests_apply_scenarios',
53-
'multiply_scenarios',
54-
'per_module_scenarios',
55-
]
48+
"TestWithScenarios",
49+
"WithScenarios",
50+
"apply_scenario",
51+
"apply_scenarios",
52+
"generate_scenarios",
53+
"load_tests_apply_scenarios",
54+
"multiply_scenarios",
55+
"per_module_scenarios",
56+
]
5657

5758

5859
from testscenarios.scenarios import ( # noqa: E402
@@ -62,12 +63,13 @@
6263
load_tests_apply_scenarios,
6364
multiply_scenarios,
6465
per_module_scenarios,
65-
)
66+
)
6667
from testscenarios.testcase import TestWithScenarios, WithScenarios # noqa: E402
6768

6869

6970
def test_suite():
7071
import testscenarios.tests # noqa: F401
72+
7173
return testscenarios.tests.test_suite()
7274

7375

testscenarios/scenarios.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
#
44
# Copyright (c) 2009, Robert Collins <robertc@robertcollins.net>
55
# Copyright (c) 2010, 2011 Martin Pool <mbp@sourcefrog.net>
6-
#
6+
#
77
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
88
# license at the users choice. A copy of both licenses are available in the
99
# project source as Apache-2.0 and BSD. You may not use this file except in
1010
# compliance with one of these two licences.
11-
#
11+
#
1212
# Unless required by applicable law or agreed to in writing, software
1313
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1414
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1515
# license you chose for the specific language governing permissions and
1616
# limitations under that license.
1717

1818
__all__ = [
19-
'apply_scenario',
20-
'apply_scenarios',
21-
'generate_scenarios',
22-
'load_tests_apply_scenarios',
23-
'multiply_scenarios',
24-
]
19+
"apply_scenario",
20+
"apply_scenarios",
21+
"generate_scenarios",
22+
"load_tests_apply_scenarios",
23+
"multiply_scenarios",
24+
]
2525

2626
from itertools import (
2727
product,
28-
)
28+
)
2929
import sys
3030

3131
from testtools.testcase import clone_test_with_new_id
@@ -42,13 +42,12 @@ def apply_scenario(scenario, test):
4242
:return: A new test cloned from test, with the scenario applied.
4343
"""
4444
name, parameters = scenario
45-
scenario_suffix = '(' + name + ')'
46-
newtest = clone_test_with_new_id(test,
47-
test.id() + scenario_suffix)
45+
scenario_suffix = "(" + name + ")"
46+
newtest = clone_test_with_new_id(test, test.id() + scenario_suffix)
4847
test_desc = test.shortDescription()
4948
if test_desc is not None:
5049
newtest_desc = "%(test_desc)s %(scenario_suffix)s" % vars()
51-
newtest.shortDescription = (lambda: newtest_desc)
50+
newtest.shortDescription = lambda: newtest_desc
5251
for key, value in parameters.items():
5352
setattr(newtest, key, value)
5453
return newtest
@@ -76,7 +75,7 @@ def generate_scenarios(test_or_suite):
7675
:return: A generator of tests - objects satisfying the TestCase protocol.
7776
"""
7877
for test in iterate_tests(test_or_suite):
79-
scenarios = getattr(test, 'scenarios', None)
78+
scenarios = getattr(test, "scenarios", None)
8079
if scenarios:
8180
for newtest in apply_scenarios(scenarios, test):
8281
newtest.scenarios = None
@@ -98,10 +97,10 @@ def load_tests_apply_scenarios(*params):
9897
pattern), and bzr used (standard_tests, module, loader).
9998
10099
:param loader: A TestLoader.
101-
:param standard_test: The test objects found in this module before
100+
:param standard_test: The test objects found in this module before
102101
multiplication.
103102
"""
104-
if getattr(params[0], 'suiteClass', None) is not None:
103+
if getattr(params[0], "suiteClass", None) is not None:
105104
loader, standard_tests, pattern = params
106105
else:
107106
standard_tests, module, loader = params
@@ -115,15 +114,15 @@ def multiply_scenarios(*scenarios):
115114
116115
It is safe to pass scenario generators or iterators.
117116
118-
:returns: A list of compound scenarios: the cross-product of all
117+
:returns: A list of compound scenarios: the cross-product of all
119118
scenarios, with the names concatenated and the parameters
120119
merged together.
121120
"""
122121
result = []
123122
scenario_lists = map(list, scenarios)
124123
for combination in product(*scenario_lists):
125124
names, parameters = zip(*combination)
126-
scenario_name = ','.join(names)
125+
scenario_name = ",".join(names)
127126
scenario_parameters = {}
128127
for parameter in parameters:
129128
scenario_parameters.update(parameter)
@@ -145,21 +144,19 @@ def per_module_scenarios(attribute_name, modules):
145144
yet.
146145
147146
:param attribute_name: A name to be set in the scenario parameter
148-
dictionary (and thence onto the test instance) pointing to the
147+
dictionary (and thence onto the test instance) pointing to the
149148
implementation module (or import exception) for this scenario.
150149
151-
:param modules: An iterable of (short_name, module_name), where
150+
:param modules: An iterable of (short_name, module_name), where
152151
the short name is something like 'python' to put in the
153152
scenario name, and the long name is a fully-qualified Python module
154153
name.
155154
"""
156155
scenarios = []
157156
for short_name, module_name in modules:
158157
try:
159-
mod = __import__(module_name, {}, {}, [''])
158+
mod = __import__(module_name, {}, {}, [""])
160159
except BaseException:
161160
mod = sys.exc_info()
162-
scenarios.append((
163-
short_name,
164-
{attribute_name: mod}))
161+
scenarios.append((short_name, {attribute_name: mod}))
165162
return scenarios

testscenarios/testcase.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
# dependency injection ('scenarios') by tests.
33
#
44
# Copyright (c) 2009, Robert Collins <robertc@robertcollins.net>
5-
#
5+
#
66
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
77
# license at the users choice. A copy of both licenses are available in the
88
# project source as Apache-2.0 and BSD. You may not use this file except in
99
# compliance with one of these two licences.
10-
#
10+
#
1111
# Unless required by applicable law or agreed to in writing, software
1212
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1313
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1414
# license you chose for the specific language governing permissions and
1515
# limitations under that license.
1616

1717
__all__ = [
18-
'TestWithScenarios',
19-
'WithScenarios',
20-
]
18+
"TestWithScenarios",
19+
"WithScenarios",
20+
]
2121

2222
import unittest
2323

@@ -32,12 +32,16 @@
3232
compatibly with WithScenarios).
3333
"""
3434

35+
3536
class WithScenarios(object):
36-
__doc__ = """A mixin for TestCase with support for declarative scenarios.
37-
""" + _doc
37+
__doc__ = (
38+
"""A mixin for TestCase with support for declarative scenarios.
39+
"""
40+
+ _doc
41+
)
3842

3943
def _get_scenarios(self):
40-
return getattr(self, 'scenarios', None)
44+
return getattr(self, "scenarios", None)
4145

4246
def countTestCases(self):
4347
scenarios = self._get_scenarios()
@@ -65,5 +69,8 @@ def run(self, result=None):
6569

6670

6771
class TestWithScenarios(WithScenarios, unittest.TestCase):
68-
__doc__ = """Unittest TestCase with support for declarative scenarios.
69-
""" + _doc
72+
__doc__ = (
73+
"""Unittest TestCase with support for declarative scenarios.
74+
"""
75+
+ _doc
76+
)

testscenarios/tests/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# dependency injection ('scenarios') by tests.
33
#
44
# Copyright (c) 2009, Robert Collins <robertc@robertcollins.net>
5-
#
5+
#
66
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
77
# license at the users choice. A copy of both licenses are available in the
88
# project source as Apache-2.0 and BSD. You may not use this file except in
99
# compliance with one of these two licences.
10-
#
10+
#
1111
# Unless required by applicable law or agreed to in writing, software
1212
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1313
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -23,20 +23,21 @@
2323

2424
def test_suite():
2525
standard_tests = unittest.TestSuite()
26-
module = sys.modules['testscenarios.tests']
26+
module = sys.modules["testscenarios.tests"]
2727
loader = unittest.TestLoader()
2828
return load_tests(standard_tests, module, loader)
2929

3030

3131
def load_tests(standard_tests, module, loader):
3232
test_modules = [
33-
'testcase',
34-
'scenarios',
35-
]
33+
"testcase",
34+
"scenarios",
35+
]
3636
prefix = "testscenarios.tests.test_"
3737
test_mod_names = [prefix + test_module for test_module in test_modules]
3838
standard_tests.addTests(loader.loadTestsFromNames(test_mod_names))
3939
doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE)
4040
standard_tests.addTest(
41-
doctest.DocFileSuite("../../README.rst", optionflags=doctest.ELLIPSIS))
41+
doctest.DocFileSuite("../../README.rst", optionflags=doctest.ELLIPSIS)
42+
)
4243
return loader.suiteClass(testscenarios.generate_scenarios(standard_tests))

0 commit comments

Comments
 (0)