1+ import pytest
2+
13import juliapkg
4+ from juliapkg .deps import PkgSpec
25
36
47def test_openssl_compat ():
@@ -8,3 +11,70 @@ def test_openssl_compat():
811 assert juliapkg .deps .openssl_compat ((3 , 1 , 0 )) == "3 - 3.1"
912 assert juliapkg .deps .openssl_compat ((3 , 1 , 2 )) == "3 - 3.1"
1013 assert isinstance (juliapkg .deps .openssl_compat (), str )
14+
15+
16+ def test_pkgspec_validation ():
17+ # Test valid construction
18+ spec = PkgSpec (name = "Example" , uuid = "123e4567-e89b-12d3-a456-426614174000" )
19+ assert spec .name == "Example"
20+ assert spec .uuid == "123e4567-e89b-12d3-a456-426614174000"
21+ assert spec .dev is False
22+ assert spec .version is None
23+ assert spec .path is None
24+ assert spec .subdir is None
25+ assert spec .url is None
26+ assert spec .rev is None
27+
28+ # Test with all parameters
29+ spec = PkgSpec (
30+ name = "Example" ,
31+ uuid = "123e4567-e89b-12d3-a456-426614174000" ,
32+ dev = True ,
33+ version = "1.0.0" ,
34+ path = "/path/to/pkg" ,
35+ subdir = "subdir" ,
36+ url = "https://example.com/pkg.git" ,
37+ rev = "main" ,
38+ )
39+ assert spec .dev is True
40+ assert spec .version == "1.0.0"
41+ assert spec .path == "/path/to/pkg"
42+ assert spec .subdir == "subdir"
43+ assert spec .url == "https://example.com/pkg.git"
44+ assert spec .rev == "main"
45+
46+ # Test invalid name
47+ with pytest .raises (ValueError , match = "name must be a non-empty string" ):
48+ PkgSpec (name = "" , uuid = "0000" )
49+ with pytest .raises (ValueError , match = "name must be a non-empty string" ):
50+ PkgSpec (name = 123 , uuid = "0000" )
51+
52+ # Test invalid UUID
53+ with pytest .raises (ValueError , match = "uuid must be a non-empty string" ):
54+ PkgSpec (name = "Example" , uuid = "" )
55+ with pytest .raises (ValueError , match = "uuid must be a non-empty string" ):
56+ PkgSpec (name = "Example" , uuid = 123 )
57+
58+ # Test invalid dev flag
59+ with pytest .raises (TypeError , match = "dev must be a boolean" ):
60+ PkgSpec (name = "Example" , uuid = "0000" , dev = "not-a-boolean" )
61+
62+ # Test invalid version type
63+ with pytest .raises (TypeError , match = "version must be a string, Version, or None" ):
64+ PkgSpec (name = "Example" , uuid = "0000" , version = 123 )
65+
66+ # Test invalid path type
67+ with pytest .raises (TypeError , match = "path must be a string or None" ):
68+ PkgSpec (name = "Example" , uuid = "0000" , path = 123 )
69+
70+ # Test invalid subdir type
71+ with pytest .raises (TypeError , match = "subdir must be a string or None" ):
72+ PkgSpec (name = "Example" , uuid = "0000" , subdir = 123 )
73+
74+ # Test invalid url type
75+ with pytest .raises (TypeError , match = "url must be a string or None" ):
76+ PkgSpec (name = "Example" , uuid = "0000" , url = 123 )
77+
78+ # Test invalid rev type
79+ with pytest .raises (TypeError , match = "rev must be a string or None" ):
80+ PkgSpec (name = "Example" , uuid = "0000" , rev = 123 )
0 commit comments