Skip to content

Commit

Permalink
Update conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Dec 15, 2023
1 parent 94ccf49 commit 779f94d
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
python: 3.x
toxenv: codestyle

- name: Code style checks
- name: Documentation build check
os: ubuntu-latest
python: 3.x
toxenv: build_docs
Expand Down
22 changes: 22 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
try:
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS
ASTROPY_HEADER = True
except ImportError:
ASTROPY_HEADER = False


# Repeat this from specutils/conftest.py so tox picks it up.
def pytest_configure(config):

if ASTROPY_HEADER:
config.option.astropy_header = True

# Customize the following lines to add/remove entries from the list of
# packages for which version numbers are displayed when running the tests.
PYTEST_HEADER_MODULES.pop('Pandas', None)
PYTEST_HEADER_MODULES.pop('h5py', None)
PYTEST_HEADER_MODULES['Astropy'] = 'astropy'
PYTEST_HEADER_MODULES['PyDL'] = 'pydl'

from pydl import __version__
TESTED_VERSIONS['pydl'] = __version__
7 changes: 3 additions & 4 deletions pydl/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"""

import os
# import os

from astropy.version import version as astropy_version
# from astropy.version import version as astropy_version

try:
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS
Expand Down Expand Up @@ -38,5 +38,4 @@ def pytest_configure(config):
PYTEST_HEADER_MODULES['PyDL'] = 'pydl'

from . import __version__
packagename = os.path.basename(os.path.dirname(__file__))
TESTED_VERSIONS[packagename] = __version__
TESTED_VERSIONS['pydl'] = __version__
14 changes: 7 additions & 7 deletions pydl/pydlutils/tests/test_bspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def test_iterfit():


def test_cholesky_band():
ab = np.array([[ 8., 9., 10., 11., 12., 13., 14., 0., 0., 0.],
[ 1., 2., 3., 4., 5., 6., 0., 0., 0., 0.],
[ 1., 2., 3., 4., 5., 0., 0., 0., 0., 0.]])
l = np.array([[2.82842712, 2.97909382, 3.07877788, 3.1382224, 3.16559183, 3.16295604, 3.12782377, 0., 0., 0.],
[0.35355339, 0.62938602, 0.8371714, 1.01466666, 1.17093392, 1.31223108, 0., 0., 0., 0.],
ab = np.array([[ 8., 9., 10., 11., 12., 13., 14., 0., 0., 0.],
[ 1., 2., 3., 4., 5., 6., 0., 0., 0., 0.],
[ 1., 2., 3., 4., 5., 0., 0., 0., 0., 0.]])
l = np.array([[2.82842712, 2.97909382, 3.07877788, 3.1382224, 3.16559183, 3.16295604, 3.12782377, 0., 0., 0.],
[0.35355339, 0.62938602, 0.8371714, 1.01466666, 1.17093392, 1.31223108, 0., 0., 0., 0.],
[0.35355339, 0.67134509, 0.97441261, 1.27460692, 1.57948348, 0., 0., 0., 0., 0.]])
i, ll = cholesky_band(ab)
assert np.allclose(l, ll)
Expand All @@ -65,8 +65,8 @@ def test_cholesky_band():


def test_cholesky_solve():
l = np.array([[2.82842712, 2.97909382, 3.07877788, 3.1382224, 3.16559183, 3.16295604, 3.12782377, 0., 0., 0.],
[0.35355339, 0.62938602, 0.8371714, 1.01466666, 1.17093392, 1.31223108, 0., 0., 0., 0.],
l = np.array([[2.82842712, 2.97909382, 3.07877788, 3.1382224, 3.16559183, 3.16295604, 3.12782377, 0., 0., 0.],
[0.35355339, 0.62938602, 0.8371714, 1.01466666, 1.17093392, 1.31223108, 0., 0., 0., 0.],
[0.35355339, 0.67134509, 0.97441261, 1.27460692, 1.57948348, 0., 0., 0., 0., 0.]])
b = np.ones((10,), dtype=l.dtype)
xx = np.array([0.10848432, 0.07752049, 0.05460496, 0.04231068, 0.02116434, 0.03276732, 0.04982674, 0., 0., 0.])
Expand Down
18 changes: 8 additions & 10 deletions pydl/pydlutils/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,14 @@ def func_fit(x, y, ncoeff, invvar=None, function_name='legendre', ia=None,
yfit += y[igood[0]]
else:
ncfit = min(ngood, ncoeff)
function_map = {
'legendre': flegendre,
'flegendre': flegendre,
'chebyshev': fchebyshev,
'fchebyshev': fchebyshev,
'chebyshev_split': fchebyshev_split,
'fchebyshev_split': fchebyshev_split,
'poly': fpoly,
'fpoly': fpoly
}
function_map = {'legendre': flegendre,
'flegendre': flegendre,
'chebyshev': fchebyshev,
'fchebyshev': fchebyshev,
'chebyshev_split': fchebyshev_split,
'fchebyshev_split': fchebyshev_split,
'poly': fpoly,
'fpoly': fpoly}
try:
legarr = function_map[function_name](x, ncfit)
except KeyError:
Expand Down
35 changes: 22 additions & 13 deletions pydl/pydlutils/yanny.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,8 @@ def new_dict_from_pairs(self):
>>> from os.path import dirname
>>> from pydl.pydlutils.yanny import yanny
>>> new_dict = yanny(dirname(__file__)+'/tests/t/test.par').new_dict_from_pairs()
>>> y = yanny(dirname(__file__)+'/tests/t/test.par')
>>> new_dict = y.new_dict_from_pairs()
>>> new_dict['mjd']
'54579'
>>> new_dict['alpha']
Expand All @@ -835,12 +836,13 @@ def write(self, newfile=None, comments=None):
This assumes that the filename used to create the object was not that
of a pre-existing file. If a file of the same name is detected,
this method will *not* attempt to overwrite it, but will print a warning.
This also assumes that the special 'symbols' key has been properly
created. This will not necessarily make the file very human-readable,
especially if the data lines are long. If the name of a new file is
given, it will write to the new file (assuming it doesn't exist).
If the writing is successful, the data in the object will be updated.
this method will *not* attempt to overwrite it, but will print a
warning. This also assumes that the special 'symbols' key has been
properly created. This will not necessarily make the file very
human-readable, especially if the data lines are long. If the name of a
new file is given, it will write to the new file (assuming it doesn't
exist). If the writing is successful, the data in the object will be
updated.
Parameters
----------
Expand All @@ -865,7 +867,14 @@ def write(self, newfile=None, comments=None):
basefile = os.path.basename(newfile)
timestamp = datetime.datetime.utcnow().strftime(
'%Y-%m-%d %H:%M:%S UTC')
comments = "#\n# {0}\n#\n# Created by pydl.pydlutils.yanny.yanny\n#\n# {1}\n#\n".format(basefile, timestamp)
comments = f"""#
# {basefile}
#
# Created by pydl.pydlutils.yanny.yanny
#
# {timestamp}
#
"""
else:
if isinstance(comments, (str,)):
if not comments.startswith('#'):
Expand Down Expand Up @@ -997,7 +1006,7 @@ def _parse(self):
Parsing proceeds in this order:
#. Lines that end with a backslash character ``\`` are reattached
#. Lines that end with a backslash character are reattached
to following lines.
#. Structure & enum definitions are identified, saved into the
'symbols' dictionary & stripped from the contents.
Expand Down Expand Up @@ -1110,8 +1119,8 @@ def _parse(self):
if self.isarray(uckey, column):
#
# An array value
# if it's character data, it won't be
# delimited by {} unless it is a multidimensional
# if it's character data, it won't be delimited
# by {} unless it is a multidimensional
# string array. It may or may not be delimited
# by double quotes
#
Expand Down Expand Up @@ -1159,9 +1168,9 @@ def write_ndarray_to_yanny(filename, datatables, structnames=None,
----------
filename : :class:`str`
The name of a parameter file.
datatables : :class:`numpy.ndarray`, :class:`numpy.recarray` or :class:`list` of these.
datatables : :class:`numpy.ndarray`, :class:`numpy.recarray`, :class:`list`
A NumPy record array containing data that can be copied into a
`yanny` object.
`yanny` object. A :class:`list` *containing* arrays can also be passed.
structnames : :class:`str` or :class:`list` of :class:`str`, optional
The name(s) to give the structure(s) in the yanny file. Defaults to
'MYSTRUCT0'.
Expand Down
124 changes: 63 additions & 61 deletions pydl/tests/test_pydl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ def test_file_lines():
# Find the test files
#
line_numbers = (1, 42, 137)
plainfiles = [get_pkg_data_filename('t/this-file-contains-{0:d}-lines.txt'.format(l)) for l in line_numbers]
gzfiles = [get_pkg_data_filename('t/this-file-contains-{0:d}-lines.txt.gz'.format(l)) for l in line_numbers]
plainfiles = [get_pkg_data_filename('t/this-file-contains-{0:d}-lines.txt'.format(l))
for l in line_numbers]
gzfiles = [get_pkg_data_filename('t/this-file-contains-{0:d}-lines.txt.gz'.format(l))
for l in line_numbers]
for i, p in enumerate(plainfiles):
n = file_lines(p)
assert n == line_numbers[i]
Expand Down Expand Up @@ -55,7 +57,7 @@ def test_median():
assert median(even_data, even=True) == 6.5
assert (median(odd_data, 3) == odd_data).all()
with pytest.raises(ValueError):
foo = median(np.ones((9, 9, 9)), 3)
_ = median(np.ones((9, 9, 9)), 3)
odd_data2 = np.vstack((odd_data, odd_data, odd_data, odd_data, odd_data))
assert (median(odd_data2, 3) == odd_data2).all()
assert (median(odd_data2, axis=0) == odd_data).all()
Expand Down Expand Up @@ -169,36 +171,36 @@ def test_rebin_int():
IDL> array = FIX(RANDOMN(seed, 10, 20) * 100, TYPE=1) ; UINT8
IDL> array_rebin = REBIN(array, 5, 10)
"""
array = np.array([[188, 186, 25, 212, 34, 98, 3, 235, 155, 148],
[107, 166, 4, 41, 101, 190, 39, 154, 153, 239],
[135, 181, 92, 161, 213, 136, 35, 61, 80, 164],
[123, 248, 8, 157, 96, 118, 99, 1, 109, 246],
[226, 71, 183, 27, 46, 99, 8, 239, 66, 25],
[ 27, 219, 37, 130, 5, 81, 65, 250, 96, 14],
[ 71, 157, 156, 136, 47, 225, 247, 191, 49, 12],
[231, 133, 9, 38, 243, 2, 235, 145, 23, 22],
[146, 38, 49, 89, 42, 57, 220, 214, 135, 47],
[101, 116, 122, 209, 141, 37, 158, 224, 245, 82],
[ 15, 47, 51, 250, 207, 193, 209, 228, 110, 1],
[ 59, 232, 216, 224, 24, 118, 190, 10, 107, 27],
[ 84, 193, 112, 206, 113, 171, 138, 117, 244, 20],
[ 5, 31, 128, 214, 200, 119, 59, 27, 57, 10],
[226, 71, 177, 85, 0, 68, 54, 207, 141, 250],
[ 52, 119, 121, 177, 165, 99, 68, 29, 137, 200],
[172, 91, 181, 187, 87, 250, 45, 154, 58, 83],
[ 56, 175, 189, 35, 203, 223, 243, 187, 252, 97],
[186, 172, 207, 128, 61, 231, 89, 57, 131, 222],
[206, 96, 29, 60, 3, 8, 221, 55, 60, 17]], dtype=np.uint8)
array_rebin = np.array([[161, 70, 105, 107, 173],
[171, 104, 140, 49, 149],
[135, 94, 57, 140, 50],
[148, 84, 129, 204, 26],
[100, 117, 69, 204, 127],
[ 88, 185, 135, 159, 61],
[ 78, 165, 150, 85, 82],
[116, 140, 83, 89, 181],
array = np.array([[188, 186, 25, 212, 34, 98, 3, 235, 155, 148],
[107, 166, 4, 41, 101, 190, 39, 154, 153, 239],
[135, 181, 92, 161, 213, 136, 35, 61, 80, 164],
[123, 248, 8, 157, 96, 118, 99, 1, 109, 246],
[226, 71, 183, 27, 46, 99, 8, 239, 66, 25],
[ 27, 219, 37, 130, 5, 81, 65, 250, 96, 14],
[ 71, 157, 156, 136, 47, 225, 247, 191, 49, 12],
[231, 133, 9, 38, 243, 2, 235, 145, 23, 22],
[146, 38, 49, 89, 42, 57, 220, 214, 135, 47],
[101, 116, 122, 209, 141, 37, 158, 224, 245, 82],
[ 15, 47, 51, 250, 207, 193, 209, 228, 110, 1],
[ 59, 232, 216, 224, 24, 118, 190, 10, 107, 27],
[ 84, 193, 112, 206, 113, 171, 138, 117, 244, 20],
[ 5, 31, 128, 214, 200, 119, 59, 27, 57, 10],
[226, 71, 177, 85, 0, 68, 54, 207, 141, 250],
[ 52, 119, 121, 177, 165, 99, 68, 29, 137, 200],
[172, 91, 181, 187, 87, 250, 45, 154, 58, 83],
[ 56, 175, 189, 35, 203, 223, 243, 187, 252, 97],
[186, 172, 207, 128, 61, 231, 89, 57, 131, 222],
[206, 96, 29, 60, 3, 8, 221, 55, 60, 17]], dtype=np.uint8)
array_rebin = np.array([[161, 70, 105, 107, 173],
[171, 104, 140, 49, 149],
[135, 94, 57, 140, 50],
[148, 84, 129, 204, 26],
[100, 117, 69, 204, 127],
[ 88, 185, 135, 159, 61],
[ 78, 165, 150, 85, 82],
[116, 140, 83, 89, 181],
[123, 148, 190, 157, 122],
[165, 105, 75, 105, 107]], dtype=np.uint8)
[165, 105, 75, 105, 107]], dtype=np.uint8)

ar = rebin(array, (10, 5))
assert (array_rebin == ar).all()
Expand All @@ -207,36 +209,36 @@ def test_rebin_int():
def test_rebin_int_sample():
"""Similar to test_rebin_int(), but using the sample option.
"""
array = np.array([[188, 186, 25, 212, 34, 98, 3, 235, 155, 148],
[107, 166, 4, 41, 101, 190, 39, 154, 153, 239],
[135, 181, 92, 161, 213, 136, 35, 61, 80, 164],
[123, 248, 8, 157, 96, 118, 99, 1, 109, 246],
[226, 71, 183, 27, 46, 99, 8, 239, 66, 25],
[ 27, 219, 37, 130, 5, 81, 65, 250, 96, 14],
[ 71, 157, 156, 136, 47, 225, 247, 191, 49, 12],
[231, 133, 9, 38, 243, 2, 235, 145, 23, 22],
[146, 38, 49, 89, 42, 57, 220, 214, 135, 47],
[101, 116, 122, 209, 141, 37, 158, 224, 245, 82],
[ 15, 47, 51, 250, 207, 193, 209, 228, 110, 1],
[ 59, 232, 216, 224, 24, 118, 190, 10, 107, 27],
[ 84, 193, 112, 206, 113, 171, 138, 117, 244, 20],
[ 5, 31, 128, 214, 200, 119, 59, 27, 57, 10],
[226, 71, 177, 85, 0, 68, 54, 207, 141, 250],
[ 52, 119, 121, 177, 165, 99, 68, 29, 137, 200],
[172, 91, 181, 187, 87, 250, 45, 154, 58, 83],
[ 56, 175, 189, 35, 203, 223, 243, 187, 252, 97],
[186, 172, 207, 128, 61, 231, 89, 57, 131, 222],
[206, 96, 29, 60, 3, 8, 221, 55, 60, 17]], dtype=np.uint8)
array_sample = np.array([[188, 25, 34, 3, 155],
[135, 92, 213, 35, 80],
[226, 183, 46, 8, 66],
[ 71, 156, 47, 247, 49],
[146, 49, 42, 220, 135],
[ 15, 51, 207, 209, 110],
array = np.array([[188, 186, 25, 212, 34, 98, 3, 235, 155, 148],
[107, 166, 4, 41, 101, 190, 39, 154, 153, 239],
[135, 181, 92, 161, 213, 136, 35, 61, 80, 164],
[123, 248, 8, 157, 96, 118, 99, 1, 109, 246],
[226, 71, 183, 27, 46, 99, 8, 239, 66, 25],
[ 27, 219, 37, 130, 5, 81, 65, 250, 96, 14],
[ 71, 157, 156, 136, 47, 225, 247, 191, 49, 12],
[231, 133, 9, 38, 243, 2, 235, 145, 23, 22],
[146, 38, 49, 89, 42, 57, 220, 214, 135, 47],
[101, 116, 122, 209, 141, 37, 158, 224, 245, 82],
[ 15, 47, 51, 250, 207, 193, 209, 228, 110, 1],
[ 59, 232, 216, 224, 24, 118, 190, 10, 107, 27],
[ 84, 193, 112, 206, 113, 171, 138, 117, 244, 20],
[ 5, 31, 128, 214, 200, 119, 59, 27, 57, 10],
[226, 71, 177, 85, 0, 68, 54, 207, 141, 250],
[ 52, 119, 121, 177, 165, 99, 68, 29, 137, 200],
[172, 91, 181, 187, 87, 250, 45, 154, 58, 83],
[ 56, 175, 189, 35, 203, 223, 243, 187, 252, 97],
[186, 172, 207, 128, 61, 231, 89, 57, 131, 222],
[206, 96, 29, 60, 3, 8, 221, 55, 60, 17]], dtype=np.uint8)
array_sample = np.array([[188, 25, 34, 3, 155],
[135, 92, 213, 35, 80],
[226, 183, 46, 8, 66],
[ 71, 156, 47, 247, 49],
[146, 49, 42, 220, 135],
[ 15, 51, 207, 209, 110],
[ 84, 112, 113, 138, 244],
[226, 177, 0, 54, 141],
[172, 181, 87, 45, 58],
[186, 207, 61, 89, 131]], dtype=np.uint8)
[226, 177, 0, 54, 141],
[172, 181, 87, 45, 58],
[186, 207, 61, 89, 131]], dtype=np.uint8)
ars = rebin(array, (10, 5), sample=True)
assert (array_sample == ars).all()

Expand Down
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,11 @@ exclude_lines =
# E227 missing whitespace around bitwise or shift operator
# E231 missing whitespace after ','
# E251 unexpected spaces around keyword / parameter equals
# E501 line too long
# E731 do not assign a lambda expression, use a def
# E741 ambiguous variable name 'l'
# W503 line break before binary operator
# W504 line break after binary operator
# W505 doc line too long
[flake8]
max-line-length = 100
max-doc-length = 79
ignore = E126,E127,E128,E201,E202,E203,E221,E225,E226,E227,E231,E251,E501,E731,E741,W503,W504,W505
ignore = E126,E127,E128,E201,E202,E203,E221,E225,E226,E227,E231,E251,E731,E741,W503,W504
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ changedir = .
description = check code style, e.g. with flake8
deps = flake8
commands =
-flake8 pydl -qq --statistics --select=E501,W505
-flake8 pydl -qq --statistics --select=E126,E127,E128
flake8 pydl --count

0 comments on commit 779f94d

Please sign in to comment.