def test_get_user_configdir(tmpdir): # Default assert USER in CONFIG_DIR assert CONFIG_DIR.split(os.path.sep)[-1] == "sunpy" assert CONFIG_DIR == _get_user_configdir() # Try to set a manual one. tmp_config_dir = tmpdir.mkdir("config_here") os.environ["SUNPY_CONFIGDIR"] = tmp_config_dir.strpath assert tmp_config_dir == _get_user_configdir() # Bypass this under windows. if not (os.name == "nt"): os.unsetenv("SUNPY_CONFIGDIR") del os.environ["SUNPY_CONFIGDIR"]
def test_copy_default_config(tmpdir, undo_config_dir_patch, monkeypatch): config_filename = 'sunpyrc' # Try to set a manual one (already created) tmp_config_dir = tmpdir.mkdir("sunpy_test_configdir") monkeypatch.setenv("SUNPY_CONFIGDIR", tmp_config_dir.strpath) assert tmp_config_dir == _get_user_configdir() config_file = Path(sunpy.__file__).parent / 'data' / config_filename user_config_file = tmp_config_dir / config_filename # Create a new config file copy_default_config() assert open(user_config_file, 'r').read() == open(config_file, 'r').read()
def test_copy_default_config_with_overwrite(tmpdir, undo_config_dir_patch, monkeypatch): # Try to set a manual one (already created) tmp_config_dir = tmpdir.mkdir("sunpy_test_configdir") monkeypatch.setenv("SUNPY_CONFIGDIR", tmp_config_dir.strpath) assert tmp_config_dir == _get_user_configdir() # Create a new config file copy_default_config() # With the `overwrite` parameter # the function does not raise any error. with pytest.warns(SunpyUserWarning): copy_default_config(overwrite=True)