55
66import jsonschema
77import pytest
8- import yaml
8+ from ruamel . yaml import YAML
99
1010import stackinator .schema as schema
1111
12+ yaml = YAML ()
13+
1214
1315@pytest .fixture
1416def test_path ():
@@ -38,7 +40,7 @@ def recipe_paths(test_path, recipes):
3840def test_config_yaml (yaml_path ):
3941 # test that the defaults are set as expected
4042 with open (yaml_path / "config.defaults.yaml" ) as fid :
41- raw = yaml .load (fid , Loader = yaml . Loader )
43+ raw = yaml .load (fid )
4244 schema .ConfigValidator .validate (raw )
4345 assert raw ["store" ] == "/user-environment"
4446 assert raw ["spack" ]["commit" ] is None
@@ -57,10 +59,7 @@ def test_config_yaml(yaml_path):
5759 repo: https://github.com/spack/spack.git
5860 commit: develop-packages
5961 """ )
60- raw = yaml .load (
61- config ,
62- Loader = yaml .Loader ,
63- )
62+ raw = yaml .load (config )
6463 schema .ConfigValidator .validate (raw )
6564 assert raw ["spack" ]["commit" ] is None
6665 assert raw ["spack" ]["packages" ]["commit" ] is not None
@@ -78,10 +77,7 @@ def test_config_yaml(yaml_path):
7877 packages:
7978 repo: https://github.com/spack/spack.git
8079 """ )
81- raw = yaml .load (
82- config ,
83- Loader = yaml .Loader ,
84- )
80+ raw = yaml .load (config )
8581 schema .ConfigValidator .validate (raw )
8682 assert raw ["spack" ]["commit" ] == "develop"
8783 assert raw ["spack" ]["packages" ]["commit" ] is None
@@ -91,7 +87,7 @@ def test_config_yaml(yaml_path):
9187
9288 # full config
9389 with open (yaml_path / "config.full.yaml" ) as fid :
94- raw = yaml .load (fid , Loader = yaml . Loader )
90+ raw = yaml .load (fid )
9591 schema .ConfigValidator .validate (raw )
9692 assert raw ["store" ] == "/alternative-point"
9793 assert raw ["spack" ]["commit" ] == "6408b51"
@@ -107,28 +103,28 @@ def test_config_yaml(yaml_path):
107103 spack:
108104 repo: https://github.com/spack/spack.git
109105 """ )
110- raw = yaml .load (config , Loader = yaml . Loader )
106+ raw = yaml .load (config )
111107 schema .ConfigValidator .validate (raw )
112108
113109
114110def test_recipe_config_yaml (recipe_paths ):
115111 # validate the config.yaml in the test recipes
116112 for p in recipe_paths :
117113 with open (p / "config.yaml" ) as fid :
118- raw = yaml .load (fid , Loader = yaml . Loader )
114+ raw = yaml .load (fid )
119115 schema .ConfigValidator .validate (raw )
120116
121117
122118def test_compilers_yaml (yaml_path ):
123119 # test that the defaults are set as expected
124120 with open (yaml_path / "compilers.defaults.yaml" ) as fid :
125- raw = yaml .load (fid , Loader = yaml . Loader )
121+ raw = yaml .load (fid )
126122 schema .CompilersValidator .validate (raw )
127123 assert raw ["gcc" ] == {"version" : "10.2" }
128124 assert raw ["llvm" ] is None
129125
130126 with open (yaml_path / "compilers.full.yaml" ) as fid :
131- raw = yaml .load (fid , Loader = yaml . Loader )
127+ raw = yaml .load (fid )
132128 schema .CompilersValidator .validate (raw )
133129 assert raw ["gcc" ] == {"version" : "11" }
134130 assert raw ["llvm" ] == {"version" : "13" }
@@ -139,13 +135,13 @@ def test_recipe_compilers_yaml(recipe_paths):
139135 # validate the compilers.yaml in the test recipes
140136 for p in recipe_paths :
141137 with open (p / "compilers.yaml" ) as fid :
142- raw = yaml .load (fid , Loader = yaml . Loader )
138+ raw = yaml .load (fid )
143139 schema .CompilersValidator .validate (raw )
144140
145141
146142def test_environments_yaml (yaml_path ):
147143 with open (yaml_path / "environments.full.yaml" ) as fid :
148- raw = yaml .load (fid , Loader = yaml . Loader )
144+ raw = yaml .load (fid )
149145 schema .EnvironmentsValidator .validate (raw )
150146
151147 # the defaults-env does not set fields
@@ -186,7 +182,7 @@ def test_environments_yaml(yaml_path):
186182 # check that only allowed fields are accepted
187183 # from an example that was silently validated
188184 with open (yaml_path / "environments.err-providers.yaml" ) as fid :
189- raw = yaml .load (fid , Loader = yaml . Loader )
185+ raw = yaml .load (fid )
190186 with pytest .raises (
191187 jsonschema .exceptions .ValidationError ,
192188 match = r"Additional properties are not allowed \('providers' was unexpected" ,
@@ -198,7 +194,7 @@ def test_recipe_environments_yaml(recipe_paths):
198194 # validate the environments.yaml in the test recipes
199195 for p in recipe_paths :
200196 with open (p / "environments.yaml" ) as fid :
201- raw = yaml .load (fid , Loader = yaml . Loader )
197+ raw = yaml .load (fid )
202198 schema .EnvironmentsValidator .validate (raw )
203199
204200
@@ -210,5 +206,7 @@ def test_unique_properties():
210206 """
211207 )
212208
213- with pytest .raises (Exception ):
214- yaml .load (invalid_config , Loader = yaml .Loader )
209+ from ruamel .yaml .constructor import DuplicateKeyError
210+
211+ with pytest .raises (DuplicateKeyError ):
212+ yaml .load (invalid_config )
0 commit comments