Skip to content

Commit db1958a

Browse files
committed
Enabled coverage testing of cache.py module
1 parent 3676545 commit db1958a

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

stumpy/cache.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get_njit_funcs():
5050
func_name = node.name
5151
for decorator in node.decorator_list:
5252
decorator_name = None
53-
if isinstance(decorator, ast.Name):
53+
if isinstance(decorator, ast.Name): # pragma: no cover
5454
# Bare decorator
5555
decorator_name = decorator.id
5656
if isinstance(decorator, ast.Call) and isinstance(
@@ -79,7 +79,7 @@ def _enable():
7979
"""
8080
frame = inspect.currentframe()
8181
caller_name = inspect.getouterframes(frame)[1].function
82-
if caller_name != "_save":
82+
if caller_name != "_save": # pragma: no cover
8383
msg = (
8484
"The 'cache._enable()' function is deprecated and no longer supported. "
8585
+ "Please use 'cache.save()' instead"
@@ -90,7 +90,16 @@ def _enable():
9090
for module_name, func_name in njit_funcs:
9191
module = importlib.import_module(f".{module_name}", package="stumpy")
9292
func = getattr(module, func_name)
93-
func.enable_caching()
93+
try:
94+
func.enable_caching()
95+
except AttributeError as e:
96+
if (
97+
numba.config.DISABLE_JIT
98+
and str(e) == "'function' object has no attribute 'enable_caching'"
99+
):
100+
pass
101+
else: # pragma: no cover
102+
raise
94103

95104

96105
def _clear():
@@ -167,7 +176,16 @@ def _recompile():
167176
for module_name, func_name in get_njit_funcs():
168177
module = importlib.import_module(f".{module_name}", package="stumpy")
169178
func = getattr(module, func_name)
170-
func.recompile()
179+
try:
180+
func.recompile()
181+
except AttributeError as e:
182+
if (
183+
numba.config.DISABLE_JIT
184+
and str(e) == "'function' object has no attribute 'recompile'"
185+
):
186+
pass
187+
else: # pragma: no cover
188+
raise
171189

172190
return
173191

@@ -206,8 +224,9 @@ def save():
206224
if numba.config.DISABLE_JIT:
207225
msg = "Could not save/cache function because NUMBA JIT is disabled"
208226
warnings.warn(msg)
209-
else:
227+
else: # pragma: no cover
210228
warnings.warn(CACHE_WARNING)
211-
_save()
229+
230+
_save()
212231

213232
return

test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ set_ray_coveragerc()
170170
show_coverage_report()
171171
{
172172
set_ray_coveragerc
173-
coverage report -m --fail-under=100 --skip-covered --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py,stumpy/cache.py,tests/test_cache.py,tests/test_fastmath.py $fcoveragerc
173+
coverage report -m --fail-under=100 --skip-covered --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py,tests/test_fastmath.py $fcoveragerc
174174
}
175175

176176
gen_coverage_xml_report()
177177
{
178178
# This function saves the coverage report in Cobertura XML format, which is compatible with codecov
179179
set_ray_coveragerc
180-
coverage xml -o $fcoveragexml --fail-under=100 --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py,stumpy/cache.py,tests/test_cache.py,tests/test_fastmath.py $fcoveragerc
180+
coverage xml -o $fcoveragexml --fail-under=100 --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py,tests/test_fastmath.py $fcoveragerc
181181
}
182182

183183
test_custom()

tests/test_cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import numba
21
import numpy as np
3-
import pytest
42

53
from stumpy import cache, stump
64

7-
if numba.config.DISABLE_JIT:
8-
pytest.skip("Skipping Tests JIT is disabled", allow_module_level=True)
5+
6+
def test_cache_get_njit_funcs():
7+
njit_funcs = cache.get_njit_funcs()
8+
assert len(njit_funcs) > 0
99

1010

1111
def test_cache_save_after_clear():

0 commit comments

Comments
 (0)