@@ -80,3 +80,69 @@ def test_compare_versions(envs, ignored_violations, expected):
8080 envs , policy_versions , ignored_violations
8181 )
8282 assert actual == expected
83+
84+
85+ class TestParseCondaEnvironment :
86+ @pytest .mark .parametrize (
87+ ["spec_text" , "expected_spec" , "expected_warnings" ],
88+ (
89+ pytest .param (
90+ "a=3.2" , Spec ("a" , Version ("3.2" )), [], id = "exact-no_warnings"
91+ ),
92+ pytest .param (
93+ "b>=1.1" ,
94+ Spec ("b" , Version ("1.1" )),
95+ [
96+ "package must be pinned with an exact version: 'b>=1.1'."
97+ " Using the version as an exact pin instead."
98+ ],
99+ id = "lower_bound" ,
100+ ),
101+ pytest .param (
102+ "b<=4.1" ,
103+ Spec ("b" , Version ("4.1" )),
104+ [
105+ "package must be pinned with an exact version: 'b<=4.1'."
106+ " Using the version as an exact pin instead."
107+ ],
108+ id = "upper_equal_bound" ,
109+ ),
110+ pytest .param (
111+ "b<4.1" ,
112+ Spec ("b" , Version ("4.1" )),
113+ [
114+ "package must be pinned with an exact version: 'b<=4.1'."
115+ " Using the version as an exact pin instead."
116+ ],
117+ marks = pytest .mark .xfail (
118+ reason = "exclusive upper bounds are not supported"
119+ ),
120+ id = "upper_bound" ,
121+ ),
122+ pytest .param (
123+ "b>4.1" ,
124+ Spec ("b" , Version ("4.1" )),
125+ [
126+ "package must be pinned with an exact version: 'b>4.1'."
127+ " Using the version as an exact pin instead."
128+ ],
129+ marks = pytest .mark .xfail (
130+ reason = "exclusive lower bounds are not supported"
131+ ),
132+ id = "lower_bound" ,
133+ ),
134+ pytest .param (
135+ "c=1.6.2" ,
136+ Spec ("c" , Version ("1.6.2" )),
137+ ["package should be pinned to a minor version (got 1.6.2)" ],
138+ ),
139+ ),
140+ )
141+ def test_parse_spec (self , spec_text , expected_spec , expected_warnings ):
142+ actual_spec , (actual_name , actual_warnings ) = environments .conda .parse_spec (
143+ spec_text
144+ )
145+
146+ assert actual_spec == expected_spec
147+ assert actual_name == expected_spec .name
148+ assert actual_warnings == expected_warnings
0 commit comments