Skip to content

Commit 0d44944

Browse files
authored
feat: change EXTERNAL_SYSTEM() to give a boolean (#2417)
1 parent a1e7ffe commit 0d44944

File tree

7 files changed

+22
-23
lines changed

7 files changed

+22
-23
lines changed

test/test_available_fix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def arrange_data(self):
1717
check_json()
1818

1919
@pytest.mark.skipif(
20-
EXTERNAL_SYSTEM() != 1, reason="Skipping tests to reduce network calls"
20+
not EXTERNAL_SYSTEM(), reason="Skipping tests to reduce network calls"
2121
)
2222
def test_long_debian_backport_fix_output(
2323
self, caplog: pytest.LogCaptureFixture
@@ -52,7 +52,7 @@ def test_debian_backport_fix_output(
5252
assert expected_output == [rec.message for rec in caplog.records]
5353

5454
@pytest.mark.skipif(
55-
EXTERNAL_SYSTEM() != 1, reason="Skipping tests to reduce network calls"
55+
not EXTERNAL_SYSTEM(), reason="Skipping tests to reduce network calls"
5656
)
5757
def test_long_debian_available_fix_output(
5858
self, caplog: pytest.LogCaptureFixture
@@ -91,7 +91,7 @@ def test_debian_available_fix_output(
9191
assert expected_output == [rec.message for rec in caplog.records]
9292

9393
@pytest.mark.skipif(
94-
EXTERNAL_SYSTEM() != 1, reason="Skipping tests to reduce network calls"
94+
not EXTERNAL_SYSTEM(), reason="Skipping tests to reduce network calls"
9595
)
9696
def test_long_redhat_available_fix_output(
9797
self, caplog: pytest.LogCaptureFixture

test/test_cvedb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def teardown_class(cls):
2727

2828
@pytest.mark.asyncio
2929
@pytest.mark.skipif(
30-
EXTERNAL_SYSTEM() != 1, reason="Skipping NVD calls due to rate limits"
30+
not EXTERNAL_SYSTEM(), reason="Skipping NVD calls due to rate limits"
3131
)
3232
@pytest.mark.skipif(
3333
sys.platform == "win32", reason="Causing failures in CI on windows only"

test/test_nvd_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def teardown_class(cls):
2525

2626
@pytest.mark.asyncio
2727
@pytest.mark.skipif(
28-
EXTERNAL_SYSTEM() != 1 or not os.getenv("nvd_api_key"),
28+
not EXTERNAL_SYSTEM() or not os.getenv("nvd_api_key"),
2929
reason="NVD tests run only when EXTERNAL_SYSTEM=1",
3030
)
3131
async def test_get_nvd_params(self):
@@ -39,7 +39,7 @@ async def test_get_nvd_params(self):
3939

4040
@pytest.mark.asyncio
4141
@pytest.mark.skipif(
42-
EXTERNAL_SYSTEM() != 1 or not os.getenv("nvd_api_key"),
42+
not EXTERNAL_SYSTEM() or not os.getenv("nvd_api_key"),
4343
reason="NVD tests run only when EXTERNAL_SYSTEM=1",
4444
)
4545
async def test_total_results_count(self):
@@ -53,7 +53,7 @@ async def test_total_results_count(self):
5353

5454
@pytest.mark.asyncio
5555
@pytest.mark.skipif(
56-
EXTERNAL_SYSTEM() != 1 or not os.getenv("nvd_api_key"),
56+
not EXTERNAL_SYSTEM() or not os.getenv("nvd_api_key"),
5757
reason="NVD tests run only when EXTERNAL_SYSTEM=1",
5858
)
5959
async def test_nvd_incremental_update(self):
@@ -75,7 +75,7 @@ async def test_nvd_incremental_update(self):
7575

7676
@pytest.mark.asyncio
7777
@pytest.mark.skipif(
78-
EXTERNAL_SYSTEM() != 1 or not os.getenv("nvd_api_key"),
78+
not EXTERNAL_SYSTEM() or not os.getenv("nvd_api_key"),
7979
reason="NVD tests run only when EXTERNAL_SYSTEM=1",
8080
)
8181
async def test_empty_nvd_result(self):

test/test_source_gad.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def teardown_class(cls):
152152
}
153153

154154
@pytest.mark.asyncio
155-
@pytest.mark.skipif(EXTERNAL_SYSTEM() != 1, reason="Needs network connection.")
155+
@pytest.mark.skipif(not EXTERNAL_SYSTEM(), reason="Needs network connection.")
156156
async def test_update_slugs(self):
157157
connector = aiohttp.TCPConnector(limit_per_host=19)
158158
async with aiohttp.ClientSession(
@@ -163,7 +163,7 @@ async def test_update_slugs(self):
163163
assert all(x in self.gad.slugs for x in self.slugs)
164164

165165
@pytest.mark.asyncio
166-
@pytest.mark.skipif(EXTERNAL_SYSTEM() != 1, reason="Needs network connection.")
166+
@pytest.mark.skipif(not EXTERNAL_SYSTEM(), reason="Needs network connection.")
167167
async def test_get_slug_00(self):
168168
slug_url = f"{self.gad.gad_url}?path=conan/cairo"
169169

@@ -178,7 +178,7 @@ async def test_get_slug_00(self):
178178
assert ("CVE-2020-35492.yml" in x for x in z.namelist())
179179

180180
@pytest.mark.asyncio
181-
@pytest.mark.skipif(EXTERNAL_SYSTEM() != 1, reason="Needs network connection.")
181+
@pytest.mark.skipif(not EXTERNAL_SYSTEM(), reason="Needs network connection.")
182182
async def test_get_slug_01(self):
183183
slug_url = f"{self.gad.gad_compare_url}?from=aa3c4bf5605855aff8c26363a24bff6da45d4812&to=a0979afc34fc6692ae8e48b3d7604e27062add62"
184184

test/test_source_nvd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def teardown_class(cls):
2323

2424
@pytest.mark.asyncio
2525
@pytest.mark.skipif(
26-
EXTERNAL_SYSTEM() != 1, reason="Skipping NVD calls due to rate limits"
26+
not EXTERNAL_SYSTEM(), reason="Skipping NVD calls due to rate limits"
2727
)
2828
async def test_00_getmeta(self):
2929
connector = aiohttp.TCPConnector(limit_per_host=19)
@@ -38,7 +38,7 @@ async def test_00_getmeta(self):
3838

3939
@pytest.mark.asyncio
4040
@pytest.mark.skipif(
41-
EXTERNAL_SYSTEM() != 1, reason="Skipping NVD calls due to rate limits"
41+
not EXTERNAL_SYSTEM(), reason="Skipping NVD calls due to rate limits"
4242
)
4343
async def test_01_cache_update(self):
4444
async with aiohttp.ClientSession(trust_env=True) as session:

test/test_source_osv.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ def teardown_class(cls):
183183
}
184184

185185
@pytest.mark.asyncio
186-
@pytest.mark.skipif(EXTERNAL_SYSTEM() != 1, reason="Needs network connection.")
186+
@pytest.mark.skipif(not EXTERNAL_SYSTEM(), reason="Needs network connection.")
187187
async def test_update_ecosystems(self):
188188
await self.osv.update_ecosystems()
189189

190190
assert all(x in self.osv.ecosystems for x in self.ecosystems)
191191

192192
@pytest.mark.asyncio
193-
@pytest.mark.skipif(EXTERNAL_SYSTEM() != 1, reason="Needs network connection.")
193+
@pytest.mark.skipif(not EXTERNAL_SYSTEM(), reason="Needs network connection.")
194194
@pytest.mark.parametrize("ecosystem_url", [url for url in cve_file_data])
195195
async def test_get_ecosystem_00(self, ecosystem_url):
196196
connector = aiohttp.TCPConnector(limit_per_host=19)
@@ -205,7 +205,7 @@ async def test_get_ecosystem_00(self, ecosystem_url):
205205
assert content["published"] == cve_data["published"]
206206

207207
@pytest.mark.asyncio
208-
@pytest.mark.skipif(EXTERNAL_SYSTEM() != 1, reason="Needs network connection.")
208+
@pytest.mark.skipif(not EXTERNAL_SYSTEM(), reason="Needs network connection.")
209209
async def test_get_ecosystem_01(self):
210210
eco_url = f"{self.osv_url}DWF/all.zip"
211211

@@ -221,7 +221,7 @@ async def test_get_ecosystem_01(self):
221221
assert len(z.namelist()) == 0
222222

223223
@pytest.mark.asyncio
224-
@pytest.mark.skipif(EXTERNAL_SYSTEM() != 1, reason="Needs network connection.")
224+
@pytest.mark.skipif(not EXTERNAL_SYSTEM(), reason="Needs network connection.")
225225
async def test_fetch_cves(self):
226226
self.osv.ecosystems = ["PyPI"]
227227

test/utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ def LONG_TESTS():
5858
return LONG_TESTS
5959

6060

61-
def EXTERNAL_SYSTEM():
62-
EXTERNAL_SYSTEM = 0
63-
# override EXTERNAL_SYSTEM with environment variable if available
64-
if os.getenv("EXTERNAL_SYSTEM"):
65-
EXTERNAL_SYSTEM = int(os.getenv("EXTERNAL_SYSTEM"))
66-
return EXTERNAL_SYSTEM
61+
def EXTERNAL_SYSTEM() -> bool:
62+
env_var = os.getenv("EXTERNAL_SYSTEM")
63+
if env_var:
64+
return bool(int(env_var))
65+
return False
6766

6867

6968
@pytest.fixture

0 commit comments

Comments
 (0)