Skip to content

Commit

Permalink
remove usage of nose.tools
Browse files Browse the repository at this point in the history
- They aren't supported by Python 3.12 due to their usage on imp library
  • Loading branch information
Caisusandy committed Jun 12, 2024
1 parent 5c622eb commit 04dc7b6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ develop-eggs
lib
lib64
__pycache__
Scripts/*
pyvenv.cfg

# Installer logs
pip-log.txt
Expand Down
19 changes: 14 additions & 5 deletions msmbuilder/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import os
import shutil
import tempfile

import re
import numpy as np
from mdtraj.testing import get_fn
from nose.tools import assert_raises, assert_raises_regexp
# sklearn.externals.joblib is removed in scikit-learn v0.23
try:
from joblib import Parallel, delayed
Expand Down Expand Up @@ -34,7 +33,13 @@ def test_1():
assert set(os.listdir(path)) == set(('PROVENANCE.txt', '00000000.npy'))
np.testing.assert_array_equal(ds[0], X)

assert_raises(IndexError, lambda: ds[1])

try:
_ = ds[1]
except IndexError:
pass
else:
assert False
assert len(ds) == 1

Y = np.zeros((10, 1))
Expand Down Expand Up @@ -168,9 +173,13 @@ def test_hdf5_3():


def test_union_no_longer_exists():
with assert_raises_regexp(ValueError,
r".*[Uu]se msmbuilder\.featurizer\.FeatureUnion.*"):
try:
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



def test_order_1():
Expand Down
44 changes: 26 additions & 18 deletions msmbuilder/tests/test_featureunion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import print_function, absolute_import, division

import numpy as np
from nose.tools import assert_raises

from msmbuilder.dataset import dataset
from msmbuilder.featurizer import FeatureUnion
Expand Down Expand Up @@ -29,14 +28,8 @@ def test_union():


def test_normalize():
ds1 = [
np.random.randn(10, 2),
np.random.randn(5, 2)
]
ds2 = [
100 * np.random.randn(10, 3),
100 * np.random.randn(5, 3)
]
ds1 = [np.random.randn(10, 2), np.random.randn(5, 2)]
ds2 = [100 * np.random.randn(10, 3), 100 * np.random.randn(5, 3)]

fu = FeatureUnion(normalize=True)
mds = fu.fit_transform((ds1, ds2))
Expand All @@ -51,8 +44,9 @@ def test_normalize():
def test_dataset():
with tempdir():
# This doesn't work with py2.6
with dataset('ds1.h5', 'w', 'hdf5') as ds1, \
dataset('ds2.h5', 'w', 'hdf5') as ds2:
with dataset("ds1.h5", "w", "hdf5") as ds1, dataset(
"ds2.h5", "w", "hdf5"
) as ds2:
ds1[0] = np.random.randn(10, 2)
ds1[1] = np.random.randn(5, 2)
ds2[0] = np.random.randn(10, 4)
Expand All @@ -75,32 +69,42 @@ def test_dataset():
def test_uneven_n():
with tempdir():
# This doesn't work with py2.6
with dataset('ds1/', 'w', 'dir-npy') as ds1, \
dataset('ds2/', 'w', 'dir-npy') as ds2:
with dataset("ds1/", "w", "dir-npy") as ds1, dataset(
"ds2/", "w", "dir-npy"
) as ds2:
ds1[0] = np.random.randn(10, 2)
ds1[1] = np.random.randn(5, 2)
ds2[0] = np.random.randn(10, 4)
# Uneven number of trajs!

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


def test_uneven_len():
with tempdir():
# This doesn't work with py2.6
with dataset('ds1/', 'w', 'dir-npy') as ds1, \
dataset('ds2/', 'w', 'dir-npy') as ds2:
with dataset("ds1/", "w", "dir-npy") as ds1, dataset(
"ds2/", "w", "dir-npy"
) as ds2:
ds1[0] = np.random.randn(10, 2)
ds1[1] = np.random.randn(5, 2)
ds2[0] = np.random.randn(10, 4)
ds2[1] = np.random.randn(10, 4)
# Uneven length!

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


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

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

0 comments on commit 04dc7b6

Please sign in to comment.