Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sherlock-project
GitHub Repository: sherlock-project/sherlock
Path: blob/master/tests/conftest.py
761 views
1
import os
2
import json
3
import urllib
4
import pytest
5
from sherlock_project.sites import SitesInformation
6
7
def fetch_local_manifest(honor_exclusions: bool = True) -> dict[str, dict[str, str]]:
8
sites_obj = SitesInformation(data_file_path=os.path.join(os.path.dirname(__file__), "../sherlock_project/resources/data.json"), honor_exclusions=honor_exclusions)
9
sites_iterable: dict[str, dict[str, str]] = {site.name: site.information for site in sites_obj}
10
return sites_iterable
11
12
@pytest.fixture()
13
def sites_obj():
14
sites_obj = SitesInformation(data_file_path=os.path.join(os.path.dirname(__file__), "../sherlock_project/resources/data.json"))
15
yield sites_obj
16
17
@pytest.fixture(scope="session")
18
def sites_info():
19
yield fetch_local_manifest()
20
21
@pytest.fixture(scope="session")
22
def remote_schema():
23
schema_url: str = 'https://raw.githubusercontent.com/sherlock-project/sherlock/master/sherlock_project/resources/data.schema.json'
24
with urllib.request.urlopen(schema_url) as remoteschema:
25
schemadat = json.load(remoteschema)
26
yield schemadat
27
28
def pytest_addoption(parser):
29
parser.addoption(
30
"--chunked-sites",
31
action="store",
32
default=None,
33
help="For tests utilizing chunked sites, include only the (comma-separated) site(s) specified.",
34
)
35
36
def pytest_generate_tests(metafunc):
37
if "chunked_sites" in metafunc.fixturenames:
38
sites_info = fetch_local_manifest(honor_exclusions=False)
39
40
# Ingest and apply site selections
41
site_filter: str | None = metafunc.config.getoption("--chunked-sites")
42
if site_filter:
43
selected_sites: list[str] = [site.strip() for site in site_filter.split(",")]
44
sites_info = {
45
site: data for site, data in sites_info.items()
46
if site in selected_sites
47
}
48
49
params = [{name: data} for name, data in sites_info.items()]
50
ids = list(sites_info.keys())
51
metafunc.parametrize("chunked_sites", params, ids=ids)
52
53