def test_no_json_file(cleared_global_settings): assert not settings._get_json_path().exists() settings._load_from_file() settings.add_option('foo', 'default') settings.set('foo', 'custom') assert not settings._get_json_path().exists() settings.reset_all() assert settings.get('foo', str) == 'default'
def test_no_json_file(cleared_global_settings): assert not settings._get_json_path().exists() settings._load_from_file() settings.add_option("foo", "default") settings.set_("foo", "custom") assert not settings._get_json_path().exists() settings.reset_all() assert settings.get("foo", str) == "default"
def test_save(cleared_global_settings): load_from_json_string('{"bar": "custom bar"}') settings.add_option('foo', 'default') settings.add_option('bar', 'default') settings.add_option('baz', 'default') settings.set('foo', 'custom foo') settings.save() with settings._get_json_path().open('r') as file: assert json.load(file) == {'foo': 'custom foo', 'bar': 'custom bar'}
def test_save(cleared_global_settings): load_from_json_string('{"bar": "custom bar"}') settings.add_option("foo", "default") settings.add_option("bar", "default") settings.add_option("baz", "default") settings.set_("foo", "custom foo") settings.save() with settings._get_json_path().open("r") as file: assert json.load(file) == {"foo": "custom foo", "bar": "custom bar"}
def save_and_read_file() -> str: settings.save() with settings._get_json_path().open('r', encoding='utf-8') as file: return json.load(file)
def load_from_json_string(json_string: str) -> None: with settings._get_json_path().open('x', encoding='utf-8') as file: file.write(json_string) settings._load_from_file()