def test_from_file(path): datafile = path.with_suffix('.json') try: data = json.loads(datafile.read_text()) except FileNotFoundError: cfg = None else: cfg = Configuration.parse_obj(data) assert Configuration.from_file(path) == cfg
def test_resolve_paths(data, expected, monkeypatch, tmp_path): for path in [ 'usr/src/project/path/foo', 'usr/src/project/path/bar', 'usr/src/project/path/bar,baz', 'usr/src/project/path/test/data', ]: create_file(tmp_path / path) monkeypatch.chdir(tmp_path / "usr" / "src" / "project") if isinstance(data.get("package"), str): data["package"] = data["package"].format(tmp_path=tmp_path) elif isinstance(data.get("package"), list): data["package"] = [ p.format(tmp_path=tmp_path) for p in data["package"] ] cfg = Configuration.parse_obj(data) cfg.resolve_paths(Path('path/foo.cfg')) if expected is not None: expected = [tmp_path / p for p in expected] assert cfg.package_paths == expected
def test_convert_check_set_error(field, value, badbit): with pytest.raises(ValidationError) as excinfo: Configuration.parse_obj({field: value}) assert f'Unknown/invalid check prefix: {badbit!r}' in str(excinfo.value)
def test_convert_check_set(data, expected): cfg = Configuration.parse_obj(data) assert cfg.select == expected
def test_convert_comma_list_error(field, value): if field in ('toplevel', 'package_omit') and value in ([42], ["foo", 42]): pytest.skip("pydantic allows int input to string fields") with pytest.raises(ValidationError): Configuration.parse_obj({field: value})
def test_convert_comma_list(data, expected): cfg = Configuration.parse_obj(data) assert cfg.package_omit == expected