-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_example_6.py
170 lines (141 loc) · 4.99 KB
/
test_example_6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import pytest
from tests.conftest import (
Case,
parametrize_cases,
)
from examples.example_6 import (
break_string_pattern,
count_characters_in_strings,
)
@pytest.fixture
def list_of_string_that_had_no_underscores() -> list[str]:
"""The result of applying `'abcd'.split('_')."""
return ['abcd']
@pytest.fixture
def list_of_string_that_had_one_underscore() -> list[str]:
"""The result of applying `'ab_cd'.split('_')."""
return ['ab', 'cd']
@pytest.fixture
def list_of_string_that_had_three_underscores() -> list[str]:
"""The result of applying `'a_b_c_d'.split('_')."""
return ['a' ,'b', 'c', 'd']
class TestBreakStringPattern:
"""Tests for the break_string_pattern function."""
@parametrize_cases(
Case(
label='abcd',
input_string='abcd',
expected='list_of_string_that_had_no_underscores',
),
Case(
label='ab_cd',
input_string='ab_cd',
expected='list_of_string_that_had_one_underscore',
),
Case(
label='a_b_c_d',
input_string='a_b_c_d',
expected='list_of_string_that_had_three_underscores',
),
)
def test_expected_using_builtin_requests(
self,
input_string,
expected,
request, # This is a built in pytest fixture.
):
"""Test using the built in pytest request fixture to access fixture data within the test.
Here we need to:
* specify the fixtures to use as a string that matches their name
* pass `request` in as a fixture
* wrap the fixture string in `request.getfixturevalue
"""
actual = break_string_pattern(input_string)
assert actual == request.getfixturevalue(expected)
@parametrize_cases(
Case(
label='abcd',
input_string='abcd',
expected=pytest.lazy_fixture('list_of_string_that_had_no_underscores'),
),
Case(
label='ab_cd',
input_string='ab_cd',
expected=pytest.lazy_fixture('list_of_string_that_had_one_underscore'),
),
Case(
label='a_b_c_d',
input_string='a_b_c_d',
expected=pytest.lazy_fixture('list_of_string_that_had_three_underscores'),
),
)
def test_expected_using_lazy_fixture(self, input_string, expected):
"""Test using the built in pytest lazy_fixture add in to access fixture data within the test.
Here we simply wrap the fixture string within the `pytest.lazy_fixture`
method in our parameterisation setup.
"""
actual = break_string_pattern(input_string)
assert actual == expected
class TestCountCharactersInStrings:
"""Tests for the count_characters_in_strings function."""
@parametrize_cases(
Case(
label='abcd',
input_values='list_of_string_that_had_no_underscores',
expected={'abcd': 4}
),
Case(
label='ab_cd',
input_values='list_of_string_that_had_one_underscore',
expected={'ab': 2, 'cd': 2}
),
Case(
label='a_b_c_d',
input_values='list_of_string_that_had_three_underscores',
expected={'a': 1, 'b': 1, 'c': 1, 'd': 1}
),
)
def test_expected_using_builtin_requests(
self,
input_values,
expected,
request, # This is a built in pytest fixture.
):
"""Test using the built in pytest request fixture to access fixture data within the test.
Here we need to:
* specify the fixtures to use as a string that matches their name
* pass `request` in as a fixture
* wrap the fixture string in `request.getfixturevalue
"""
actual = count_characters_in_strings(
request.getfixturevalue(input_values)
)
assert actual == expected
@parametrize_cases(
Case(
label='abcd',
input_values=pytest.lazy_fixture('list_of_string_that_had_no_underscores'),
expected={'abcd': 4}
),
Case(
label='ab_cd',
input_values=pytest.lazy_fixture('list_of_string_that_had_one_underscore'),
expected={'ab': 2, 'cd': 2}
),
Case(
label='a_b_c_d',
input_values=pytest.lazy_fixture('list_of_string_that_had_three_underscores'),
expected={'a': 1, 'b': 1, 'c': 1, 'd': 1}
),
)
def test_expected_using_lazy_fixture(self, input_values, expected):
"""Test using the built in pytest lazy_fixture add in to access fixture data within the test.
Here we simply wrap the fixture string within the `pytest.lazy_fixture`
method in our parameterisation setup.
"""
actual = count_characters_in_strings(input_values)
assert actual == expected
class TestRemoveCharactersInString:
@pytest.mark.skip(reason='No test implemented')
def test_expected(self):
pass