def test_dump_path_name_exists(tmp_path): """ GIVEN path and name that does exist WHEN dump is called with the path THEN no exceptions are raised. """ dist_path = tmp_path / "dist" dist_path.mkdir() name = "name 1" setup = "setup file" manifest = "manifest file" spec_str = "spec file" init = "init file" (dist_path / name).mkdir() build.dump( path=str(dist_path), name=name, setup=setup, manifest=manifest, spec_str=spec_str, init=init, )
def test_dump_path_name_is_file(tmp_path): """ GIVEN path and name that points to a file WHEN dump is called with the path THEN BuildError is raised. """ dist_path = tmp_path / "dist" dist_path.mkdir() name = "name 1" setup = "setup file" manifest = "manifest file" spec_str = "spec file" init = "init file" with open(dist_path / name, "w") as out_file: out_file.write("") with pytest.raises(exceptions.BuildError): build.dump( path=str(dist_path), name=name, setup=setup, manifest=manifest, spec_str=spec_str, init=init, )
def test_dump(tmp_path): """ GIVEN path WHEN dump is called with the path THEN the expected directory structure is returned. """ dist_path = tmp_path / "dist" dist_path.mkdir() name = "name 1" setup = "setup file" manifest = "manifest file" spec_str = "spec file" init = "init file" build.dump( path=str(dist_path), name=name, setup=setup, manifest=manifest, spec_str=spec_str, init=init, ) # Define generated project directories project_path = dist_path / name package_path = project_path / name # Check setup file expected_setup_path = project_path / "setup.py" assert expected_setup_path.is_file() with open(expected_setup_path) as in_file: assert in_file.read() == setup # Check manifest file expected_manifest_path = project_path / "MANIFEST.in" assert expected_manifest_path.is_file() with open(expected_manifest_path) as in_file: assert in_file.read() == manifest # Check spec file expected_spec_path = package_path / "spec.json" assert expected_spec_path.is_file() with open(expected_spec_path) as in_file: assert in_file.read() == spec_str # Check cache expected_cache_path = cache.calculate_cache_path(expected_spec_path) assert expected_cache_path.is_file() assert cache.schemas_valid(str(expected_spec_path)) # Check init file expected_init_path = package_path / "__init__.py" assert expected_init_path.is_file() with open(expected_init_path) as in_file: assert in_file.read() == init