Skip to content

Commit cfd3be3

Browse files
authored
Merge pull request #18 from MattShannon/claude/modernize-python-codebase-ur34X
Follow-up modernization: tests, cleanup, and CI improvements
2 parents 49ea164 + 9a9caa9 commit cfd3be3

File tree

7 files changed

+49
-24
lines changed

7 files changed

+49
-24
lines changed

.appveyor_update_version.ps1

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
os: [ubuntu-latest, windows-latest]
15+
os: [ubuntu-latest, windows-latest, macos-latest]
1616
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
1717

1818
steps:
@@ -26,8 +26,7 @@ jobs:
2626
- name: Install dependencies
2727
run: |
2828
python -m pip install --upgrade pip
29-
pip install cython numpy scipy
3029
pip install -e .
3130
3231
- name: Run tests
33-
run: python -m unittest discover bandmat
32+
run: python -W error::DeprecationWarning -m unittest discover bandmat

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include License
22
include README.rst
33
include requirements.txt
4-
include bandmat/*.c
4+
include bandmat/*.pyx
55
include example.py
66
include example_spg.py

bandmat/test_examples.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Tests that the example scripts run successfully."""
2+
3+
# Copyright 2013, 2014, 2015, 2016, 2017, 2018 Matt Shannon
4+
5+
# This file is part of bandmat.
6+
# See `License` for details of license and warranty.
7+
8+
import unittest
9+
import subprocess
10+
import sys
11+
import os
12+
13+
example_dir = os.path.join(os.path.dirname(__file__), '..')
14+
15+
class TestExamples(unittest.TestCase):
16+
def test_example(self):
17+
"""Checks example.py runs without error (has its own assertions)."""
18+
subprocess.check_call(
19+
[sys.executable, os.path.join(example_dir, 'example.py')]
20+
)
21+
22+
def test_example_spg(self):
23+
"""Checks example_spg.py runs without error."""
24+
subprocess.check_call(
25+
[sys.executable, os.path.join(example_dir, 'example_spg.py')]
26+
)
27+
28+
if __name__ == '__main__':
29+
unittest.main()

bandmat/test_testhelp.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,17 @@ def test_get_array_mem(self, its=50):
104104

105105
x = gen_array(ranks=[1, 2, 3])
106106
array_mem = th.get_array_mem(x)
107-
shape = x.shape
108-
strides = x.strides
107+
shape_orig = x.shape
108+
strides_orig = x.strides
109109
shape_new = x.T.shape
110110
strides_new = x.T.strides
111-
if np.prod(shape_new) != 0:
112-
x.shape = shape_new
113-
x.strides = strides_new
114-
if shape_new != shape or strides_new != strides:
115-
# FIXME : re-enable once I understand better when this may
116-
# fail (i.e. when memory may be unexpectedly shared).
117-
#assert th.get_array_mem(x) != array_mem
118-
pass
111+
if (np.prod(shape_new) != 0 and
112+
(shape_new != shape_orig or
113+
strides_new != strides_orig)):
114+
x = np.lib.stride_tricks.as_strided(
115+
x, shape=shape_new, strides=strides_new
116+
)
117+
assert th.get_array_mem(x) != array_mem
119118

120119
if __name__ == '__main__':
121120
unittest.main()

bandmat/testhelp.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,10 @@ def get_array_mem(*arrays):
6969
>>> x *= 2.0
7070
>>> assert get_array_mem(x) == array_mem
7171
"""
72-
return [ array.__array_interface__ for array in arrays ]
72+
mems = []
73+
for array in arrays:
74+
d = dict(array.__array_interface__)
75+
if d['strides'] is None:
76+
d['strides'] = array.strides
77+
mems.append(d)
78+
return mems

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
author_email='matt.shannon@cantab.net',
4242
license='3-clause BSD (see License file)',
4343
packages=['bandmat'],
44+
python_requires='>=3.9',
4445
install_requires=requires,
4546
long_description=long_description,
4647
ext_modules=ext_modules,

0 commit comments

Comments
 (0)