Skip to content

Commit

Permalink
set test env to switch numpy representation
Browse files Browse the repository at this point in the history
  • Loading branch information
floesche committed Dec 16, 2024
1 parent 3f2d47e commit f5b45ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ jobs:
with:
run: |
export NAVIS_HEADLESS=TRUE
export NAVIS_TEST_ENV=TRUE
pytest --verbose
12 changes: 7 additions & 5 deletions navis/morpho/mmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""This module contains functions to analyse and manipulate neuron morphology."""

import math
import os
import itertools
import scipy
import warnings
Expand All @@ -30,6 +31,12 @@
# Set up logging
logger = config.get_logger(__name__)

# Set up numpy number representation, see NEP51
# Once numpy<=2 is dropped from requirements, the doctest comparissons
# should become `np.float64(1.074)` instead of `1.074`
if os.environ.get('NAVIS_TEST_ENV', '').lower() == 'true':
np.set_printoptions(legacy="1.25")

__all__ = sorted(
[
"strahler_index",
Expand Down Expand Up @@ -1321,12 +1328,7 @@ def tortuosity(
Examples
--------
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `np.float64(1.074)` instead of `1.074`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(1)
>>> # Calculate tortuosity as-is
>>> T = navis.tortuosity(n)
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ doctest_optionflags = IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE
addopts = --doctest-modules
env =
NAVIS_HEADLESS=TRUE
NAVIS_TEST_ENV=TRUE

0 comments on commit f5b45ab

Please sign in to comment.