Skip to content

Commit

Permalink
Merge pull request #343 from AstarVienna/hb/importall
Browse files Browse the repository at this point in the history
Add test to see whether all Python files can be imported.
  • Loading branch information
hugobuddel committed Jan 17, 2024
2 parents 44f5926 + a942ef7 commit 2c7a0f0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2,074 deletions.
4 changes: 2 additions & 2 deletions scopesim/detector/nghxrg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# import warnings

import numpy as np
from scipy.ndimage.interpolation import zoom
from scipy.ndimage import zoom
from astropy.io import fits
from astropy.stats.funcs import median_absolute_deviation as mad

Expand Down Expand Up @@ -199,7 +199,7 @@ def pink_noise(self, mode):
"""

# Configure depending on mode setting
if mode is 'pink':
if mode == 'pink':
nstep = 2*self.nstep
f = self.f2
p_filter = self.p_filter2
Expand Down
1,987 changes: 0 additions & 1,987 deletions scopesim/tests/profiling/profile_hawki_results.txt

This file was deleted.

26 changes: 0 additions & 26 deletions scopesim/tests/profiling/profile_hawki_run.py

This file was deleted.

26 changes: 26 additions & 0 deletions scopesim/tests/test_import_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Test whether all Python files can be imported."""
import importlib.util
import time
from pathlib import Path

import scopesim


def test_import_all():
"""Test whether all Python files can be imported.
This ensures that all files are included in the code coverage.
"""
for name_path_scopesim in scopesim.__path__:
path_scopesim = Path(name_path_scopesim)
fns_python = path_scopesim.glob("**/*.py")
for fn in fns_python:
name_package = ".".join(fn.relative_to(path_scopesim.parent).with_suffix("").parts)
time_1 = time.time()
importlib.import_module(name_package)
time_2 = time.time()
time_delta = time_2 - time_1
msg = f"{name_package} takes {time_delta} seconds to import"
# Assert the package is quick to import, because this can highlight
# broken packages. Requires running this test in isolation.
assert time_delta < 0.2, msg
51 changes: 0 additions & 51 deletions scopesim/tests/tests_integrations/tst_ScopeSim_MET_LSS.py

This file was deleted.

20 changes: 12 additions & 8 deletions scopesim/tests/tests_server/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def mock_client():
yield client


@pytest.fixture(scope="class")
def all_pkg():
# TODO: This could use some kind of mock to avoid server access
yield db.get_all_package_versions()


@pytest.mark.webtest
def test_package_list_loads():
with pytest.warns(DeprecationWarning):
Expand All @@ -40,22 +46,20 @@ def test_get_all_latest():

@pytest.mark.webtest
class TestGetZipname:
# TODO: This could use some kind of mock to avoid server access
all_pkg = db.get_all_package_versions()

def test_gets_stable(self):
zipname = db._get_zipname("test_package", "stable", self.all_pkg)
def test_gets_stable(self, all_pkg):
zipname = db._get_zipname("test_package", "stable", all_pkg)
assert zipname.startswith("test_package.")
assert zipname.endswith(".zip")

def test_gets_latest(self):
zipname = db._get_zipname("test_package", "latest", self.all_pkg)
def test_gets_latest(self, all_pkg):
zipname = db._get_zipname("test_package", "latest", all_pkg)
assert zipname.startswith("test_package.")
assert zipname.endswith(".dev.zip")

def test_throws_for_nonexisting_release(self):
def test_throws_for_nonexisting_release(self, all_pkg):
with pytest.raises(ValueError):
db._get_zipname("test_package", "bogus", self.all_pkg)
db._get_zipname("test_package", "bogus", all_pkg)


@pytest.mark.webtest
Expand Down

0 comments on commit 2c7a0f0

Please sign in to comment.