Skip to content

Commit a8fc230

Browse files
committed
tests: update to use pytest bdd version 8
1 parent d45bb08 commit a8fc230

6 files changed

Lines changed: 215 additions & 168 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test = [
4141
"coverage",
4242
"pytest",
4343
"pytest-cov",
44-
"pytest-bdd >= 3.1.0,<4.0",
44+
"pytest-bdd >= 4,<9.0",
4545
]
4646
tox = ['tox']
4747
tox-uv = [

tests/features/package_factory.feature

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ Feature: Build package objects
33
# You should easily be able to build a new package object using the package factory
44

55
Scenario Outline: Loading session containing 2 objects
6-
Given We have a object created by contains files that belong to two groups
6+
Given We have a <package_type> object created by contains files that belong to two groups
77
Then resulting packages should be 2
8-
And the first object should contain everything from the first group
9-
And the second object should contain everything from the second group
8+
And the first <package_type> object should contain everything from the first group
9+
And the second <package_type> object should contain everything from the second group
10+
1011
Examples:
1112
| package_type |
1213
| CaptureOnePackage |

tests/features/package_transform.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Feature: Transform package objects
22
Scenario Outline: package containing 2 objects and want to transform them into a another type of package
3-
Given A package containing 2 objects
4-
And We have another path to save the objects to
5-
When we transform all the packages found into the new package format
6-
Then the newly transformed package should contain the same files but in the new format
3+
Given A package containing 2 objects of <source_package_type>
4+
And We have another path to save the objects to <new_package_type>
5+
When we transform all the packages found into the new <new_package_type> package format
6+
Then the newly transformed package should contain the same files but in the <new_package_type> format
77
Examples:
88
| source_package_type | new_package_type |
99
| CaptureOnePackage | HathiTiff |

tests/steps/test_package_factory_feature.py

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33
import shutil
44
from uiucprescon import packager
55

6-
from pytest_bdd import scenario, given, when, then
6+
from pytest_bdd import scenario, given, when, then, parsers
77
import pytest
88

99
from uiucprescon.packager import Metadata
1010
from ..conftest import sample_packages
1111

1212

13-
@scenario(
14-
"package_factory.feature",
15-
"Loading session containing 2 objects"
16-
)
13+
@scenario("package_factory.feature", "Loading session containing 2 objects")
1714
def test_load_session_objects():
1815
pass
1916

2017

21-
@given("We have a object created by contains files that belong to two groups")
18+
@given(
19+
parsers.parse(
20+
"We have a {package_type} object created by contains files that belong to two groups"
21+
),
22+
target_fixture="package_objects",
23+
)
2224
def package_objects(source_path, package_type):
2325
pkg_factory_type = eval(f"packager.packages.{package_type}")
2426

@@ -36,11 +38,14 @@ def two_packages(package_objects):
3638
assert len(package_objects) == 2
3739

3840

39-
@then("the first object should contain everything from the first group")
41+
@then(
42+
parsers.parse(
43+
"the first {package_type} object should contain everything from the first group"
44+
)
45+
)
4046
def step_impl(package_objects, package_type):
4147
first_group_regex = sample_packages[package_type][1]
42-
package_objects = sorted(package_objects,
43-
key=lambda p: p.metadata[Metadata.ID])
48+
package_objects = sorted(package_objects, key=lambda p: p.metadata[Metadata.ID])
4449
object_000001 = package_objects[0]
4550

4651
assert object_000001.metadata[Metadata.ID] == "000001"
@@ -57,11 +62,14 @@ def step_impl(package_objects, package_type):
5762
assert checker.match(basename)
5863

5964

60-
@then("the second object should contain everything from the second group")
65+
@then(
66+
parsers.parse(
67+
"the second {package_type} object should contain everything from the second group"
68+
)
69+
)
6170
def step_impl(package_objects, package_type):
6271
second_group_regex = sample_packages[package_type][2]
63-
package_objects = sorted(package_objects,
64-
key=lambda p: p.metadata[Metadata.ID])
72+
package_objects = sorted(package_objects, key=lambda p: p.metadata[Metadata.ID])
6573
object_000002 = package_objects[1]
6674
assert object_000002.metadata[Metadata.ID] == "000002"
6775

@@ -77,27 +85,31 @@ def step_impl(package_objects, package_type):
7785
assert checker.match(basename)
7886

7987

80-
@scenario("package_factory.feature",
81-
"Hathi TIFF package containing 2 objects with sidecar text files"
88+
@scenario(
89+
"package_factory.feature",
90+
"Hathi TIFF package containing 2 objects with sidecar text files",
8291
)
8392
def test_hathi_tiff_two_object_and_sidecar_text():
8493
pass
8594

8695

87-
@given("a hathi tiff package containing 2 objects with text sidecar files")
96+
@given(
97+
"a hathi tiff package containing 2 objects with text sidecar files",
98+
target_fixture="hathi_tiff_package_w_sidecar_text",
99+
)
88100
def hathi_tiff_package_w_sidecar_text(hathi_tiff_sample_package):
89101
package_one_path = os.path.join(hathi_tiff_sample_package, "000001")
90102
for i in range(3):
91-
with open(os.path.join(package_one_path, f"0000000{i+1}.txt"), "w"):
103+
with open(os.path.join(package_one_path, f"0000000{i + 1}.txt"), "w"):
92104
pass
93105

94106
package_two_path = os.path.join(hathi_tiff_sample_package, "000002")
95107
for i in range(2):
96-
with open(os.path.join(package_two_path, f"0000000{i+1}.txt"), "w"):
108+
with open(os.path.join(package_two_path, f"0000000{i + 1}.txt"), "w"):
97109
pass
98110
package_factory = packager.PackageFactory(packager.packages.HathiTiff())
99111

100-
packages = list(package_factory .locate_packages(hathi_tiff_sample_package))
112+
packages = list(package_factory.locate_packages(hathi_tiff_sample_package))
101113
return packages
102114

103115

@@ -113,31 +125,39 @@ def step_impl(hathi_tiff_package_w_sidecar_text):
113125
for instance in item.instantiations.values():
114126
num_sidecar_file = len(instance.sidecar_files)
115127
if num_sidecar_file != 1:
116-
pytest.fail(f"{instance} contains {num_sidecar_file} sidecare files")
128+
pytest.fail(
129+
f"{instance} contains {num_sidecar_file} sidecare files"
130+
)
131+
117132

118-
@scenario("package_factory.feature",
119-
"Hathi jp2 package containing 2 objects with sidecar text files"
133+
@scenario(
134+
"package_factory.feature",
135+
"Hathi jp2 package containing 2 objects with sidecar text files",
120136
)
121137
def test_hathi_jp2_two_object_and_sidecar_text():
122138
pass
123139

124140

125-
@given("a hathi jp2 package containing 2 objects with text sidecar files")
141+
@given(
142+
"a hathi jp2 package containing 2 objects with text sidecar files",
143+
target_fixture="hathi_jp2_package_w_sidecar_text",
144+
)
126145
def hathi_jp2_package_w_sidecar_text(hathi_jp2_sample_package):
127146
package_one_path = os.path.join(hathi_jp2_sample_package, "000001")
128147
for i in range(3):
129-
with open(os.path.join(package_one_path, f"0000000{i+1}.txt"), "w"):
148+
with open(os.path.join(package_one_path, f"0000000{i + 1}.txt"), "w"):
130149
pass
131150

132151
package_two_path = os.path.join(hathi_jp2_sample_package, "000002")
133152
for i in range(2):
134-
with open(os.path.join(package_two_path, f"0000000{i+1}.txt"), "w"):
153+
with open(os.path.join(package_two_path, f"0000000{i + 1}.txt"), "w"):
135154
pass
136155
package_factory = packager.PackageFactory(packager.packages.HathiJp2())
137156

138157
packages = list(package_factory.locate_packages(hathi_jp2_sample_package))
139158
return packages
140159

160+
141161
@then("resulting packages hathi jp2 package should be 2")
142162
def step_impl(hathi_jp2_package_w_sidecar_text):
143163
assert len(hathi_jp2_package_w_sidecar_text) == 2
@@ -150,9 +170,7 @@ def step_impl(hathi_jp2_package_w_sidecar_text):
150170
for instance in item.instantiations.values():
151171
num_sidecar_file = len(instance.sidecar_files)
152172
if num_sidecar_file != 1:
153-
pytest.fail(
154-
f"{instance} contains {num_sidecar_file} sidecar files"
155-
)
173+
pytest.fail(f"{instance} contains {num_sidecar_file} sidecar files")
156174

157175

158176
@then("each instance in jp2 package should files")
@@ -161,6 +179,4 @@ def instances_has_files(hathi_jp2_package_w_sidecar_text):
161179
for item in obj:
162180
for inst in item.instantiations.values():
163181
if len(list(inst.get_files())) == 0:
164-
pytest.fail(
165-
f"{inst.metadata[Metadata.ID]} contains no files"
166-
)
182+
pytest.fail(f"{inst.metadata[Metadata.ID]} contains no files")

0 commit comments

Comments
 (0)