@@ -149,59 +149,59 @@ def test_get_user_info_with_local_conf_file(runtime_inputs, expected, user_files
149149 assert actual == expected
150150
151151
152- # @pytest.mark.parametrize("inputsa, inputsb, expected", params_user_info_with_no_home_conf_file)
153- # def test_get_user_info_with_no_home_conf_file(monkeypatch, inputsa, inputsb, expected, user_filesystem):
154- # _setup_dirs(monkeypatch, user_filesystem)
155- # os.remove(Path().home() / "diffpyconfig.json")
156- # inp_iter = iter(inputsb)
157- # monkeypatch.setattr("builtins.input", lambda _: next(inp_iter))
158- # _run_tests(inputsa, expected)
159- # confile = Path().home() / "diffpyconfig.json"
160- # assert confile.is_file()
161- #
162- #
163- # @pytest.mark.parametrize("inputsa, inputsb, expected", params_user_info_no_conf_file_no_inputs)
164- # def test_get_user_info_no_conf_file_no_inputs(monkeypatch, inputsa, inputsb, expected, user_filesystem):
165- # _setup_dirs(monkeypatch, user_filesystem)
166- # os.remove(Path().home() / "diffpyconfig.json")
167- # inp_iter = iter(inputsb)
168- # monkeypatch.setattr("builtins.input", lambda _: next(inp_iter))
169- # _run_tests(inputsa, expected)
170- # confile = Path().home() / "diffpyconfig.json"
171- # assert confile.exists() is False
172- #
173-
174-
175152@pytest .mark .parametrize (
176153 "test_inputs,expected" ,
177154 [ # Check check_and_build_global_config() builds correct config when config is found missing
178155 ( # C1: user inputs valid name, email and orcid
179156 {"user_inputs" : ["input_name" , "input@email.com" , "input_orcid" ]},
180157 {"owner_email" : "input@email.com" , "owner_orcid" : "input_orcid" , "owner_name" : "input_name" },
181158 ),
182- # ( # C2: empty strings passed in, expect uname, email, orcid from home_config
183- # {"owner_name": "", "owner_email": "", "owner_orcid": ""},
184- # {"owner_name": "home_ownername", "owner_email": "home@email.com", "owner_orcid": "home_orcid"},
185- # ),
159+ ({"user_inputs" : ["" , "" , "" ]}, None ), # C2: empty strings passed in, expect no config file created
160+ ( # C3: just username input, expect config file but with some empty values
161+ {"user_inputs" : ["input_name" , "" , "" ]},
162+ {"owner_email" : "" , "owner_orcid" : "" , "owner_name" : "input_name" },
163+ ),
186164 ],
187165)
188166def test_check_and_build_global_config (test_inputs , expected , user_filesystem , mocker ):
189167 # user_filesystem[0] is tmp_dir/home_dir with the global config file in it, user_filesystem[1]
190168 # is tmp_dir/cwd_dir
191169 mocker .patch .object (Path , "home" , return_value = user_filesystem [0 ])
192170 os .chdir (user_filesystem [1 ])
171+ confile = user_filesystem [0 ] / "diffpyconfig.json"
193172 # remove the config file from home that came with user_filesystem
194- old_confile = user_filesystem [ 0 ] / "diffpyconfig.json"
195- os . remove ( old_confile )
173+ os . remove ( confile )
174+ mocker . patch ( "builtins.input" , side_effect = test_inputs [ "user_inputs" ] )
196175 check_and_build_global_config ()
197- inp_iter = iter (test_inputs ["user_inputs" ])
198- mocker .patch ("builtins.input" , lambda _ : next (inp_iter ))
199- with open (old_confile , "r" ) as f :
176+ try :
177+ with open (confile , "r" ) as f :
178+ actual = json .load (f )
179+ except FileNotFoundError :
180+ actual = None
181+ assert actual == expected
182+
183+
184+ def test_check_and_build_global_config_file_exists (user_filesystem , mocker ):
185+ mocker .patch .object (Path , "home" , return_value = user_filesystem [0 ])
186+ os .chdir (user_filesystem [1 ])
187+ confile = user_filesystem [0 ] / "diffpyconfig.json"
188+ expected = {"owner_name" : "home_ownername" , "owner_email" : "home@email.com" , "owner_orcid" : "home_orcid" }
189+ check_and_build_global_config ()
190+ with open (confile , "r" ) as f :
200191 actual = json .load (f )
201- print (actual )
202192 assert actual == expected
203193
204194
195+ def test_check_and_build_global_config_skipped (user_filesystem , mocker ):
196+ mocker .patch .object (Path , "home" , return_value = user_filesystem [0 ])
197+ os .chdir (user_filesystem [1 ])
198+ confile = user_filesystem [0 ] / "diffpyconfig.json"
199+ # remove the config file from home that came with user_filesystem
200+ os .remove (confile )
201+ check_and_build_global_config (skip_config_creation = True )
202+ assert not confile .exists ()
203+
204+
205205params_package_info = [
206206 (["diffpy.utils" , None ], {"package_info" : {"diffpy.utils" : "3.3.0" }}),
207207 (["package1" , None ], {"package_info" : {"package1" : "1.2.3" , "diffpy.utils" : "3.3.0" }}),
0 commit comments