def test_makeconfig_failure(tmpdir): baddir = tmpdir / "baddir" os.mkdir(str(baddir), mode=0o444) cfg = moduledev.Config(_filename=os.path.join(baddir, "config.yml")) with pytest.raises(SystemExit): cfg.save() os.chmod(baddir, mode=0o777)
def example_config(tmpdir): cfg = moduledev.Config(_filename=tmpdir / "config.yaml") cfg.set("maintainer", "Example <*****@*****.**>") cfg.set("package_name", "package") cfg.set("helptext", "some help") cfg.set("description", "a description") return cfg
def empty_config(tmpdir): cfg = moduledev.Config(_filename=tmpdir / "config.yaml") return cfg
def test_save_load(empty_config): empty_config.set("test_setting", "test_value") empty_config.save() loaded_config = moduledev.Config(_filename=empty_config.filename()) assert loaded_config.get("test_setting") == "test_value"
def test_load_unparseable(data_dir): with pytest.raises(SystemExit): moduledev.Config(_filename=os.path.join(data_dir, "bad_config.yaml"))
def test_load_nothing(): cfg = moduledev.Config(_filename="nonexistentfile") assert len(cfg.config) == 0
def test_load(data_dir): cfg = moduledev.Config( _filename=os.path.join(data_dir, "good_config.yaml")) assert cfg.get("maintainer") == "Example <*****@*****.**>"