@@ -107,7 +107,7 @@ def test_pylock_packages_without_dist() -> None:
107107 with pytest .raises (PylockValidationError ) as exc_info :
108108 Pylock .from_dict (data )
109109 assert str (exc_info .value ) == (
110- "Error parsing item 0 of 'packages': "
110+ "Error in item 0 of 'packages': "
111111 "Exactly one of vcs, directory, archive must be set "
112112 "if sdist and wheels are not set"
113113 )
@@ -139,3 +139,76 @@ def test_pylock_basic_package() -> None:
139139 assert package .marker == Marker ('os_name == "posix"' )
140140 assert package .requires_python == SpecifierSet (">=3.10, !=3.10.1" )
141141 assert pylock .to_dict () == data
142+
143+
144+ def test_pylock_invalid_archive () -> None :
145+ data = {
146+ "lock-version" : "1.0" ,
147+ "created-by" : "pip" ,
148+ "requires-python" : ">=3.10" ,
149+ "environments" : ['os_name == "posix"' ],
150+ "packages" : [
151+ {
152+ "name" : "example" ,
153+ "archive" : {
154+ # "path": "example.tar.gz",
155+ "hashes" : {"sha256" : "f" * 40 },
156+ },
157+ }
158+ ],
159+ }
160+ with pytest .raises (PylockValidationError ) as exc_info :
161+ Pylock .from_dict (data )
162+ assert str (exc_info .value ) == (
163+ "Error in item 0 of 'packages': "
164+ "Error in 'archive': "
165+ "No path nor url set for archive package"
166+ )
167+
168+
169+ def test_pylock_invalid_wheel () -> None :
170+ data = {
171+ "lock-version" : "1.0" ,
172+ "created-by" : "pip" ,
173+ "requires-python" : ">=3.10" ,
174+ "environments" : ['os_name == "posix"' ],
175+ "packages" : [
176+ {
177+ "name" : "example" ,
178+ "wheels" : [
179+ {
180+ "name" : "example-1.0-py3-none-any.whl" ,
181+ "path" : "./example-1.0-py3-none-any.whl" ,
182+ # "hashes": {"sha256": "f" * 40},
183+ }
184+ ],
185+ }
186+ ],
187+ }
188+ with pytest .raises (PylockValidationError ) as exc_info :
189+ Pylock .from_dict (data )
190+ assert str (exc_info .value ) == (
191+ "Error in item 0 of 'packages': "
192+ "Error in item 0 of 'wheels': "
193+ "Missing required key 'hashes'"
194+ )
195+
196+
197+ def test_pylock_invalid_environments () -> None :
198+ data = {
199+ "lock-version" : "1.0" ,
200+ "created-by" : "pip" ,
201+ "environments" : [
202+ 'os_name == "posix"' ,
203+ 'invalid_marker == "..."' ,
204+ ],
205+ "packages" : [],
206+ }
207+ with pytest .raises (PylockValidationError ) as exc_info :
208+ Pylock .from_dict (data )
209+ assert str (exc_info .value ) == (
210+ "Error in item 1 of 'environments': "
211+ "Expected a marker variable or quoted string\n "
212+ ' invalid_marker == "..."\n '
213+ " ^"
214+ )
0 commit comments