Skip to content

Commit

Permalink
Another implementation of assert raises from numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
Caisusandy committed Jun 12, 2024
1 parent 04dc7b6 commit a3a8ebb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ${{ matrix.path }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
Expand Down
14 changes: 2 additions & 12 deletions msmbuilder/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@ def test_1():
assert set(os.listdir(path)) == set(('PROVENANCE.txt', '00000000.npy'))
np.testing.assert_array_equal(ds[0], X)


try:
with np.testing.assert_raises(IndexError):
_ = ds[1]
except IndexError:
pass
else:
assert False
assert len(ds) == 1

Y = np.zeros((10, 1))
Z = np.ones((2, 2))
Expand Down Expand Up @@ -173,12 +167,8 @@ def test_hdf5_3():


def test_union_no_longer_exists():
try:
with np.testing.assert_raises_regex(ValueError, r".*[Uu]se msmbuilder\.featurizer\.FeatureUnion.*"):
mds = dataset(['ds1.h5', 'ds2.h5'], fmt='hdf5-union')
except ValueError as e:
assert re.match(r".*[Uu]se msmbuilder\.featurizer\.FeatureUnion.*", repr(e))
else:
assert False



Expand Down
19 changes: 3 additions & 16 deletions msmbuilder/tests/test_featureunion.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,8 @@ def test_uneven_n():
# Uneven number of trajs!

fu = FeatureUnion(normalize=False)
try:
with np.testing.assert_raises(ValueError):
fu.fit((ds1, ds2))
except ValueError:
pass
else:
assert False


def test_uneven_len():
with tempdir():
Expand All @@ -99,12 +94,8 @@ def test_uneven_len():
# Uneven length!

fu = FeatureUnion(normalize=False)
try:
with np.testing.assert_raises(ValueError):
fu.fit_transform((ds1, ds2))
except ValueError:
pass
else:
assert False


def test_uneven_width():
Expand All @@ -116,9 +107,5 @@ def test_uneven_width():
ds2[1] = np.random.randn(5, 3)

fu = FeatureUnion(normalize=True)
try:
with np.testing.assert_raises(ValueError):
fu.fit_transform((ds1, ds2))
except ValueError:
pass
else:
assert False

0 comments on commit a3a8ebb

Please sign in to comment.