Skip to content

Commit

Permalink
add duplicate conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Aug 1, 2024
1 parent 8414c30 commit fba9814
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 19 deletions.
52 changes: 52 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# this contains imports plugins that configure py.test for astropy tests.
# by importing them here in conftest.py they are discoverable by py.test
# no matter how it is invoked within the source tree.

from astropy.version import version as astropy_version
if astropy_version < '3.0':
# With older versions of Astropy, we actually need to import the pytest
# plugins themselves in order to make them discoverable by pytest.
from astropy.tests.pytest_plugins import *
else:
# As of Astropy 3.0, the pytest plugins provided by Astropy are
# automatically made available when Astropy is installed. This means it's
# not necessary to import them here, but we still need to import global
# variables that are used for configuration.
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS

from astropy.tests.helper import enable_deprecations_as_exceptions

## Uncomment the following line to treat all DeprecationWarnings as
## exceptions
# enable_deprecations_as_exceptions()

## Uncomment and customize the following lines to add/remove entries from
## the list of packages for which version numbers are displayed when running
## the tests. Making it pass for KeyError is essential in some cases when
## the package uses other astropy affiliated packages.
try:
PYTEST_HEADER_MODULES['Astropy'] = 'astropy'
PYTEST_HEADER_MODULES['Pillow'] = 'PIL'
PYTEST_HEADER_MODULES['PyYAML'] = 'yaml'
del PYTEST_HEADER_MODULES['h5py']
del PYTEST_HEADER_MODULES['Pandas']
except (NameError, KeyError): # NameError is needed to support Astropy < 1.0
pass

## Uncomment the following lines to display the version number of the
## package rather than the version number of Astropy in the top line when
## running the tests.
# import os
#
## This is to figure out the affiliated package version, rather than
## using Astropy's
# try:
# from .version import version
# except ImportError:
# version = 'dev'
#
# try:
# packagename = os.path.basename(os.path.dirname(__file__))
# TESTED_VERSIONS[packagename] = version
# except NameError: # Needed to support Astropy <= 1.0.0
# pass
5 changes: 3 additions & 2 deletions speclite/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
## the package uses other astropy affiliated packages.
try:
PYTEST_HEADER_MODULES['Astropy'] = 'astropy'
PYTEST_HEADER_MODULES['PIL'] = 'pillow'
PYTEST_HEADER_MODULES['Pillow'] = 'PIL'
PYTEST_HEADER_MODULES['PyYAML'] = 'yaml'
del PYTEST_HEADER_MODULES['h5py']
del PYTEST_HEADER_MODULES['pandas']
del PYTEST_HEADER_MODULES['Pandas']
except (NameError, KeyError): # NameError is needed to support Astropy < 1.0
pass

Expand Down
8 changes: 4 additions & 4 deletions speclite/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import numpy as np
import numpy.ma as ma
import scipy.interpolate
import pkg_resources as pkgr
from packaging import version

if pkgr.parse_version(np.__version__) >= pkgr.parse_version('1.16'):
if version.parse(np.__version__) >= version.parse('1.16'):
import numpy.lib.recfunctions as rfn

def resample(data_in, x_in, x_out, y, data_out=None, kind='linear'):
Expand Down Expand Up @@ -168,7 +168,7 @@ def resample(data_in, x_in, x_out, y, data_out=None, kind='linear'):
for i,y in enumerate(y_names):
y_in[:,i] = data_in[y].filled(np.nan)
else:
if pkgr.parse_version(np.__version__) >= pkgr.parse_version('1.16'):
if version.parse(np.__version__) >= version.parse('1.16'):
# The slicing does not work in numpy 1.16 and above
# we use structured_to_unstructured to get the slice that we care about
y_in = rfn.structured_to_unstructured(
Expand All @@ -178,7 +178,7 @@ def resample(data_in, x_in, x_out, y, data_out=None, kind='linear'):
# View the structured 1D array as a 2D unstructured array (without
# copying any memory).
y_in = y_in.view(y_type).reshape(data_in.shape + y_shape)

# interp1d will only propagate NaNs correctly for certain values of `kind`.
# With numpy = 1.6 or 1.7, only 'nearest' and 'linear' work.
# With numpy = 1.8 or 1.9, 'slinear' and kind = 0 or 1 also work.
Expand Down
9 changes: 7 additions & 2 deletions speclite/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import os
import pathlib
from ..utils.package_data import get_path_of_data_file, get_path_of_data_dir


def test_get_path_of_data_file():
pass
data_file = get_path_of_data_file('filters/twomass-Ks.ecsv')
assert os.path.exists(data_file)


def test_get_path_of_data_dir():
pass
data_dir = get_path_of_data_dir()
assert isinstance(data_dir, pathlib.PosixPath)
assert os.path.isdir(data_dir)
16 changes: 5 additions & 11 deletions speclite/utils/package_data.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import os

import pkg_resources
from importlib import resources

# TODO: should make these Path objects

def get_path_of_data_file(data_file) -> str:
def get_path_of_data_file(data_file):
"""convenience wrapper to return location of data file
"""
file_path = pkg_resources.resource_filename(
"speclite", os.path.join("data", f"{data_file}"))

return file_path
return os.path.join(str(get_path_of_data_dir()), data_file)


def get_path_of_data_dir() -> str:
def get_path_of_data_dir():
"""convenience wrapper to return location of data directory
"""
file_path = pkg_resources.resource_filename("speclite", "data")

return file_path
return resources.files('speclite') / 'data'

0 comments on commit fba9814

Please sign in to comment.