Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/tests/conftest.py
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | def test_sample_folder(datadir, tmp_path): | ||||
assert archive_path.exists() | assert archive_path.exists() | ||||
shutil.unpack_archive(archive_path, extract_dir=tmp_path) | shutil.unpack_archive(archive_path, extract_dir=tmp_path) | ||||
test_sample_folder = Path(os.path.join(tmp_path, "sample-folder")) | test_sample_folder = Path(os.path.join(tmp_path, "sample-folder")) | ||||
assert test_sample_folder.exists() | assert test_sample_folder.exists() | ||||
return test_sample_folder | return test_sample_folder | ||||
@pytest.fixture(scope="function") | @pytest.fixture(scope="function") | ||||
def test_sample_folder_policy(datadir, tmp_path): | |||||
"""Location of the sample source code project to test the scanner policies""" | |||||
archive_path = Path(os.path.join(datadir, "sample-folder-policy.tgz")) | |||||
assert archive_path.exists() | |||||
shutil.unpack_archive(archive_path, extract_dir=tmp_path) | |||||
test_sample_folder = Path(os.path.join(tmp_path, "sample-folder-policy")) | |||||
assert test_sample_folder.exists() | |||||
return test_sample_folder | |||||
@pytest.fixture(scope="function") | |||||
def source_tree(test_sample_folder): | def source_tree(test_sample_folder): | ||||
"""Generate a model.from_disk.Directory object from the test sample | """Generate a model.from_disk.Directory object from the test sample | ||||
folder | folder | ||||
""" | """ | ||||
return model_of_dir(str(test_sample_folder).encode()) | return model_of_dir(str(test_sample_folder).encode()) | ||||
@pytest.fixture(scope="function") | @pytest.fixture(scope="function") | ||||
def source_tree_policy(test_sample_folder_policy): | |||||
"""Generate a model.from_disk.Directory object from the test sample | |||||
folder | |||||
""" | |||||
return model_of_dir(str(test_sample_folder_policy).encode()) | |||||
@pytest.fixture(scope="function") | |||||
def source_tree_dirs(source_tree): | def source_tree_dirs(source_tree): | ||||
"""Returns a list of all directories contained inside the test sample | """Returns a list of all directories contained inside the test sample | ||||
folder | folder | ||||
""" | """ | ||||
root = source_tree.data["path"] | root = source_tree.data["path"] | ||||
return list( | return list( | ||||
map( | map( | ||||
lambda n: Path(n.data["path"].decode()).relative_to(Path(root.decode())), | lambda n: Path(n.data["path"].decode()).relative_to(Path(root.decode())), | ||||
Show All 25 Lines | def test_swhids_sample(tmp_path): | ||||
with open(test_swhids_sample, "w") as f: | with open(test_swhids_sample, "w") as f: | ||||
f.write("\n".join(swhid for swhid in present_swhids)) | f.write("\n".join(swhid for swhid in present_swhids)) | ||||
assert test_swhids_sample.exists() | assert test_swhids_sample.exists() | ||||
return open(test_swhids_sample, "r") | return open(test_swhids_sample, "r") | ||||
@pytest.fixture(scope="session") | @pytest.fixture(scope="session") | ||||
def app(): | def tmp_requests(tmpdir_factory): | ||||
requests_file = tmpdir_factory.mktemp("data").join("requests.json") | |||||
return requests_file | |||||
@pytest.fixture(scope="session") | |||||
def app(tmp_requests): | |||||
"""Flask backend API (used by live_server).""" | """Flask backend API (used by live_server).""" | ||||
app = create_app() | app = create_app(tmp_requests) | ||||
return app | return app |