Coverage for tests/conftest.py: 71%
38 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-17 04:01 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-17 04:01 +0000
1import os
2import subprocess
3from atexit import register
5import pytest
7from bbconf.bbagent import BedBaseAgent
9from .utils import BED_TEST_ID
11DB_CMD = """
12docker run --rm -it --name bedbase-test \
13 -e POSTGRES_USER=postgres \
14 -e POSTGRES_PASSWORD=docker\
15 -e POSTGRES_DB=bedbase \
16 -p 5432:5432 postgres
17"""
19try:
20 subprocess.check_output(
21 "docker inspect bedbase-test --format '{{.State.Status}}'", shell=True
22 )
23 SERVICE_UNAVAILABLE = False
24except:
25 register(
26 print, f"Some tests require a test database. To initiate it, run:\n{DB_CMD}"
27 )
28 SERVICE_UNAVAILABLE = True
31TESTS_DIR = os.path.dirname(os.path.abspath(__file__))
33CONFIG_PATH = os.path.join(
34 TESTS_DIR,
35 "config_test.yaml",
36)
37DATA_PATH = os.path.join(
38 TESTS_DIR,
39 "data",
40)
42if not SERVICE_UNAVAILABLE:
43 agent = BedBaseAgent(config=CONFIG_PATH)
46def get_bbagent():
47 return agent
50@pytest.fixture(scope="function")
51def bbagent_obj():
52 yield agent
55@pytest.fixture()
56def example_bedset_plot():
57 return {
58 "name": "chrombins",
59 "description": "Regions distribution over chromosomes",
60 "title": "Regions distribution over chromosomes",
61 "path": "data/plots/bbad85f21962bb8d972444f7f9a3a932_chrombins.pdf",
62 "path_thumbnail": "data/plots/bbad85f21962bb8d972444f7f9a3a932_chrombins.png",
63 "bedset_id": BED_TEST_ID,
64 }
67@pytest.fixture()
68def example_dict():
69 plots = {
70 "chrombins": {
71 "name": "Regions distribution over chromosomes",
72 "path": "plots/bbad85f21962bb8d972444f7f9a3a932_chrombins.pdf",
73 "path_thumbnail": "plots/bbad85f21962bb8d972444f7f9a3a932_chrombins.png",
74 }
75 }
76 files = {
77 "bedfile": {
78 "name": "Bed file",
79 "path": os.path.join(
80 DATA_PATH, "files/bbad85f21962bb8d972444f7f9a3a932.bed.gz"
81 ),
82 "description": "Bed file with regions",
83 }
84 }
85 classification = {
86 "bed_format": "narrowpeak",
87 "bed_type": "bed6+4",
88 "genome_alias": "hg38",
89 "genome_digest": "2230c535660fb4774114bfa966a62f823fdb6d21acf138d4",
90 "name": "bbad85f21962bb8d972444f7f9a3a932",
91 }
93 return dict(
94 identifier="bbad85f21962bb8d972444f7f9a3a932",
95 stats={
96 "number_of_regions": 1,
97 "median_tss_dist": 2,
98 "mean_region_width": 3,
99 "exon_frequency": 4,
100 "exon_percentage": 5,
101 "intron_frequency": 6,
102 "intron_percentage": 7,
103 "intergenic_percentage": 8,
104 "intergenic_frequency": 9,
105 "promotercore_frequency": 10,
106 "promotercore_percentage": 11,
107 "fiveutr_frequency": 12,
108 "fiveutr_percentage": 13,
109 "threeutr_frequency": 14,
110 "threeutr_percentage": 15,
111 "promoterprox_frequency": 16,
112 "promoterprox_percentage": 17,
113 },
114 metadata={"sample_name": "sample_name_1"},
115 plots=plots,
116 files=files,
117 classification=classification,
118 upload_qdrant=False,
119 upload_pephub=False,
120 upload_s3=True,
121 local_path=DATA_PATH,
122 overwrite=False,
123 nofail=False,
124 )
127@pytest.fixture
128def load_test_data():
129 get_bbagent().config.db_engine()
132@pytest.fixture()
133def mocked_phc(mocker):
134 mocker.patch(
135 "pephubclient.modules.sample.PEPHubSample.get",
136 return_value={"sample_name": BED_TEST_ID, "other_metadata": "other_metadata_1"},
137 )