Skip to content

Commit b61e722

Browse files
authored
Simplify flaky dependency (#197)
* Remove dependency on genty external package. Whole parametrization of tests can be done now easily with subTest from the standard library. * External package mock is not needed anymore.
1 parent 69c297e commit b61e722

File tree

3 files changed

+61
-73
lines changed

3 files changed

+61
-73
lines changed

requirements-dev.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
-rrequirements.txt
22
coveralls
3-
genty
4-
mock
53
ordereddict
64
pycodestyle
75
pylint

test/test_flaky_plugin.py

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1+
from collections import namedtuple
12
from io import StringIO
23
from unittest import TestCase
34

45
from flaky._flaky_plugin import _FlakyPlugin
56
from flaky.names import FlakyNames
67

7-
from genty import genty, genty_dataset
8+
TestCaseDataset = namedtuple("TestCaseDataset",
9+
['max_runs', 'min_passes', 'current_runs', 'current_passes', 'expect_fail'])
810

9-
10-
@genty
1111
class TestFlakyPlugin(TestCase):
12+
_test_dataset = (
13+
"default_not_started": TestCaseDataset(2, 1, 0, 0, False),
14+
"default_one_failure": TestCaseDataset(2, 1, 1, 0, False),
15+
"default_one_success": TestCaseDataset(2, 1, 1, 1, False),
16+
"default_two_failures": TestCaseDataset(2, 1, 2, 0, True),
17+
"default_one_failure_one_success": TestCaseDataset(2, 1, 2, 1, False),
18+
"three_two_not_started": TestCaseDataset(3, 2, 0, 0, False),
19+
"three_two_one_failure": TestCaseDataset(3, 2, 1, 0, False),
20+
"three_two_one_success": TestCaseDataset(3, 2, 1, 1, False),
21+
"three_two_two_failures": TestCaseDataset(3, 2, 2, 0, True),
22+
"three_two_one_failure_one_success": TestCaseDataset(3, 2, 2, 1, False),
23+
"three_two_two_successes": TestCaseDataset(3, 2, 2, 2, False),
24+
)
25+
1226
def setUp(self):
13-
super().setUp()
27+
super(TestFlakyPlugin, self).setUp()
1428
self._flaky_plugin = _FlakyPlugin()
1529

1630
def test_flaky_plugin_handles_non_ascii_byte_string_in_exception(self):
@@ -24,43 +38,26 @@ def test_flaky_plugin_handles_non_ascii_byte_string_in_exception(self):
2438
mock_message,
2539
)
2640

27-
@genty_dataset(
28-
default_not_started=(2, 1, 0, 0, False),
29-
default_one_failure=(2, 1, 1, 0, False),
30-
default_one_success=(2, 1, 1, 1, False),
31-
default_two_failures=(2, 1, 2, 0, True),
32-
default_one_failure_one_success=(2, 1, 2, 1, False),
33-
three_two_not_started=(3, 2, 0, 0, False),
34-
three_two_one_failure=(3, 2, 1, 0, False),
35-
three_two_one_success=(3, 2, 1, 1, False),
36-
three_two_two_failures=(3, 2, 2, 0, True),
37-
three_two_one_failure_one_success=(3, 2, 2, 1, False),
38-
three_two_two_successes=(3, 2, 2, 2, False),
39-
)
40-
def test_flaky_plugin_identifies_failure(
41-
self,
42-
max_runs,
43-
min_passes,
44-
current_runs,
45-
current_passes,
46-
expect_fail,
47-
):
48-
flaky = {
49-
FlakyNames.CURRENT_PASSES: current_passes,
50-
FlakyNames.CURRENT_RUNS: current_runs,
51-
FlakyNames.MAX_RUNS: max_runs,
52-
FlakyNames.MIN_PASSES: min_passes,
53-
}
54-
# pylint:disable=protected-access
55-
self.assertEqual(
56-
self._flaky_plugin._has_flaky_test_failed(flaky),
57-
expect_fail,
58-
)
41+
def test_flaky_plugin_identifies_failure(self):
42+
for test in _test_dataset:
43+
with self.subTest(test):
44+
flaky = {
45+
FlakyNames.CURRENT_PASSES: _test_dataset[test].current_passes,
46+
FlakyNames.CURRENT_RUNS: _test_dataset[test].current_runs,
47+
FlakyNames.MAX_RUNS: _test_dataset[test].max_runs,
48+
FlakyNames.MIN_PASSES: _test_dataset[test].min_passes,
49+
}
50+
# pylint:disable=protected-access
51+
self.assertEqual(
52+
self._flaky_plugin._has_flaky_test_failed(flaky),
53+
_test_dataset[test].expect_fail,
54+
)
5955

60-
@genty_dataset('ascii stuff', 'ńőń ȁŝćȉȉ ŝƭȕƒƒ')
61-
def test_write_unicode_to_stream(self, message):
62-
stream = StringIO()
63-
stream.write('ascii stuff')
64-
# pylint:disable=protected-access
65-
self._flaky_plugin._stream.write(message)
66-
self._flaky_plugin._add_flaky_report(stream)
56+
def test_write_unicode_to_stream(self):
57+
for message in ('ascii stuff', 'ńőń ȁŝćȉȉ ŝƭȕƒƒ'):
58+
with self.subTest(message):
59+
stream = StringIO()
60+
stream.write('ascii stuff')
61+
# pylint:disable=protected-access
62+
self._flaky_plugin._stream.write(message)
63+
self._flaky_plugin._add_flaky_report(stream)
Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
from io import StringIO
22
from unittest import TestCase
33

4-
from genty import genty, genty_dataset
54

6-
7-
@genty
85
class TestMultiprocessStringIO(TestCase):
96
_unicode_string = 'Plain Hello'
107
_unicode_string_non_ascii = 'ńőń ȁŝćȉȉ ŝƭȕƒƒ'
8+
_test_values = {
9+
"no_writes": ([], ''),
10+
"one_write": ([_unicode_string], _unicode_string),
11+
"two_writes": (
12+
[_unicode_string, _unicode_string_non_ascii],
13+
'{}{}'.format(_unicode_string, _unicode_string_non_ascii),
14+
)
15+
}
1116

1217
def setUp(self):
1318
super().setUp()
@@ -17,29 +22,17 @@ def setUp(self):
1722
del self._mp_string_io.proxy[:]
1823
self._string_ios = (self._string_io, self._mp_string_io)
1924

20-
@genty_dataset(
21-
no_writes=([], ''),
22-
one_write=([_unicode_string], _unicode_string),
23-
two_writes=(
24-
[_unicode_string, _unicode_string_non_ascii],
25-
'{}{}'.format(_unicode_string, _unicode_string_non_ascii),
26-
)
27-
)
28-
def test_write_then_read(self, writes, expected_value):
29-
for string_io in self._string_ios:
30-
for item in writes:
31-
string_io.write(item)
32-
self.assertEqual(string_io.getvalue(), expected_value)
25+
def test_write_then_read(self):
26+
for name in _test_values:
27+
with self.subTest(name):
28+
for string_io in self._string_ios:
29+
for item in _test_values[name][0]:
30+
string_io.write(item)
31+
self.assertEqual(string_io.getvalue(), _test_values[name][1])
3332

34-
@genty_dataset(
35-
no_writes=([], ''),
36-
one_write=([_unicode_string], _unicode_string),
37-
two_writes=(
38-
[_unicode_string, _unicode_string_non_ascii],
39-
'{}{}'.format(_unicode_string, _unicode_string_non_ascii),
40-
)
41-
)
42-
def test_writelines_then_read(self, lines, expected_value):
43-
for string_io in self._string_ios:
44-
string_io.writelines(lines)
45-
self.assertEqual(string_io.getvalue(), expected_value)
33+
def test_writelines_then_read(self):
34+
for name in _test_values:
35+
with self.subTest(name):
36+
for string_io in self._string_ios:
37+
string_io.writelines(_test_values[name][0])
38+
self.assertEqual(string_io.getvalue(), _test_values[name][1])

0 commit comments

Comments
 (0)