Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip NNDC/XCOM tests if databases are down #333

Merged
merged 25 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5e55195
Increase number of flaky reruns and add 2 s delay
jvavrek Apr 1, 2022
80852ed
Merge branch 'main' into patch-flaky-tests
jvavrek Apr 4, 2022
f1f572d
Merge branch 'main' into patch-flaky-tests
jvavrek Apr 4, 2022
2b8a6a7
add initial checks of nndc database connection
jvavrek Apr 4, 2022
f430676
add nndc_is_up() util
jvavrek Apr 4, 2022
2d16d78
change nndc check to xcom where relevant
jvavrek Apr 4, 2022
ce4cd6d
reorder reqs
jvavrek Apr 4, 2022
d02923b
add database checks to other tests
jvavrek Apr 4, 2022
9339872
return False in database checks if a ConnectionError occurs
jvavrek Apr 4, 2022
486fc18
dry refactor database_is_up
jvavrek Apr 4, 2022
08debf8
try fixing a race condition
jvavrek Apr 5, 2022
8e51d29
try removing pytest version upper bound
jvavrek Apr 5, 2022
651ae5d
try 6.3.1
jvavrek Apr 5, 2022
bfcf5b4
version for coverage, not pytest-cov
jvavrek Apr 5, 2022
98e2942
drop python 3.6, not supported by newer coverage
jvavrek Apr 5, 2022
ed84022
revert version hacking
jvavrek Apr 5, 2022
1e0e6b9
try downgrading pytest-cov
jvavrek Apr 5, 2022
d45cfdd
remove xdist
jvavrek Apr 5, 2022
401456c
don't bound pytest-cov
jvavrek Apr 5, 2022
0623efe
try one last combination
jvavrek Apr 5, 2022
e5f1218
revert last
jvavrek Apr 5, 2022
acea1b4
remove pytest-xdist from requirements-dev.txt
jvavrek Apr 5, 2022
81994d7
Merge branch 'main' into patch-flaky-tests
jvavrek Apr 8, 2022
94aaa66
Merge branch 'main' into patch-flaky-tests
jvavrek May 16, 2022
7b4154a
Merge branch 'main' into patch-flaky-tests
jvavrek May 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ bump2version
coverage
flake8>=4.0.1
pre-commit
pytest<7.0.0
pytest
pytest-black
pytest-cov
pytest-rerunfailures
pytest-xdist
requests
1 change: 1 addition & 0 deletions tests/df_cache_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_bad_path(self):
"""Test ExampleCache.check_path() exception for a bad path."""
d = ExampleCache()
d.path = "/bad/path"
d.filename = "/bad/path/filename.csv"
with pytest.raises(CacheError):
d.check_path()
with pytest.raises(CacheError):
Expand Down
8 changes: 8 additions & 0 deletions tests/materials_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import becquerel.tools.materials as materials
import becquerel.tools.materials_compendium as materials_compendium
import pytest
from utils import xcom_is_up


@pytest.mark.webtest
@pytest.mark.skipif(not xcom_is_up(), reason="XCOM is down.")
class TestConvertComposition:
"""Test convert_composition."""

Expand Down Expand Up @@ -51,13 +53,15 @@ def test_z_out_of_range(self):


@pytest.mark.webtest
@pytest.mark.skipif(not xcom_is_up(), reason="XCOM is down.")
def test_materials():
"""Test fetch_materials."""
fetch_materials()
assert os.path.exists(materials.FILENAME)


@pytest.mark.webtest
@pytest.mark.skipif(not xcom_is_up(), reason="XCOM is down.")
def test_materials_force():
"""Test fetch_materials with force=True."""
assert os.path.exists(materials.FILENAME)
Expand Down Expand Up @@ -87,6 +91,7 @@ def test_materials_dummy_csv():


@pytest.mark.webtest
@pytest.mark.skipif(not xcom_is_up(), reason="XCOM is down.")
def test_materials_dummy_compendium_pre2022():
"""Test fetch_materials with a dummy Compendium JSON file.

Expand Down Expand Up @@ -132,6 +137,7 @@ def test_materials_dummy_compendium_pre2022():


@pytest.mark.webtest
@pytest.mark.skipif(not xcom_is_up(), reason="XCOM is down.")
def test_materials_dummy_compendium_2022():
"""Test fetch_materials with a dummy Compendium JSON file.

Expand Down Expand Up @@ -186,6 +192,7 @@ def test_materials_dummy_compendium_2022():


@pytest.mark.webtest
@pytest.mark.skipif(not xcom_is_up(), reason="XCOM is down.")
def test_materials_dummy_compendium_error():
"""Test fetch_materials with a dummy Compendium JSON file.

Expand All @@ -205,6 +212,7 @@ def test_materials_dummy_compendium_error():


@pytest.mark.webtest
@pytest.mark.skipif(not xcom_is_up(), reason="XCOM is down.")
def test_materials_no_compendium():
"""Test fetch_materials with no Compendium JSON file."""
# point to a dummy JSON file that does not exist
Expand Down
10 changes: 7 additions & 3 deletions tests/nndc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import pandas as pd
from becquerel.tools import nndc
from utils import nndc_is_up
import pytest


Expand Down Expand Up @@ -137,7 +138,8 @@ def test_20(self):
nndc._parse_float_uncertainty("7", "@")


@pytest.mark.flaky(reruns=3)
@pytest.mark.skipif(not nndc_is_up(), reason="NNDC is down.")
@pytest.mark.flaky(reruns=10)
class NNDCQueryTests:
"""Tests common to NNDCQuery-derived classes."""

Expand Down Expand Up @@ -559,7 +561,8 @@ def test_query_zrange_7_20_elevelrange_01_inf(self):


@pytest.mark.webtest
@pytest.mark.flaky(reruns=3)
@pytest.mark.skipif(not nndc_is_up(), reason="NNDC is down.")
@pytest.mark.flaky(reruns=10)
class TestNuclearWalletCard(NNDCQueryTests):
"""Test NNDC nuclear_wallet_card query."""

Expand Down Expand Up @@ -703,7 +706,8 @@ def test_wallet_exception_too_many(self):


@pytest.mark.webtest
@pytest.mark.flaky(reruns=3)
@pytest.mark.skipif(not nndc_is_up(), reason="NNDC is down.")
@pytest.mark.flaky(reruns=10)
class TestDecayRadiationQuery(NNDCQueryTests):
"""Test NNDC decay_radiation."""

Expand Down
25 changes: 25 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
"""Helpers for testing."""
from pathlib import Path
import requests

TESTS_PATH = Path(__file__).parent.absolute()
REPO_PATH = TESTS_PATH.parent


def database_is_up(url):
"""Check whether an online database can be reached.

Parameters
----------
url : str
URL to query.
"""
try:
return requests.post(url).status_code == requests.codes.ok
except requests.exceptions.ConnectionError:
return False


def nndc_is_up():
"""Check whether the NNDC databases can be reached."""
return database_is_up("https://www.nndc.bnl.gov/nudat3/indx_sigma.jsp")


def xcom_is_up():
"""Check whether the NIST XCOM databases can be reached."""
return database_is_up("https://physics.nist.gov/PhysRefData/Xcom/html/xcom1.html")
2 changes: 2 additions & 0 deletions tests/wallet_cache_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import uncertainties
import becquerel.tools.wallet_cache as wallet_cache
import pytest
from utils import nndc_is_up


@pytest.mark.parametrize(
Expand Down Expand Up @@ -49,6 +50,7 @@ def test_format_ufloat(arg, result):

@pytest.mark.webtest
@pytest.mark.flaky(reruns=3)
@pytest.mark.skipif(not nndc_is_up(), reason="NNDC is down.")
class TestWalletCardCache:
"""Test functionality of wallet_cache."""

Expand Down
2 changes: 2 additions & 0 deletions tests/xcom_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np
from becquerel.tools import xcom
from utils import xcom_is_up
import pytest

XCOM_URL_ORIG = xcom._URL
Expand Down Expand Up @@ -122,6 +123,7 @@


@pytest.mark.webtest
@pytest.mark.skipif(not xcom_is_up(), reason="XCOM is down.")
class TestFetchXCOMData:
"""Test fetch_xcom_data function."""

Expand Down