33import shutil
44from uiucprescon import packager
55
6- from pytest_bdd import scenario , given , when , then
6+ from pytest_bdd import scenario , given , when , then , parsers
77import pytest
88
99from uiucprescon .packager import Metadata
1010from ..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" )
1714def 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+ )
2224def 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+ )
4046def 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+ )
6170def 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)
8392def 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+ )
88100def 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)
121137def 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+ )
126145def 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" )
142162def 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