Skip to content

Commit

Permalink
catch deprecationwarning different way
Browse files Browse the repository at this point in the history
  • Loading branch information
adrn committed Dec 12, 2016
1 parent ef3a1e2 commit 641a370
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
10 changes: 2 additions & 8 deletions gala/dynamics/mockstream/tests/test_mockstream.py
Expand Up @@ -82,17 +82,11 @@ def test_each_type(mock_func, extra_kwargs):
# Test expected failures:

# Deprecation warning for passing in potential
with warnings.catch_warnings(record=True) as wa:
warnings.simplefilter('always')

warnings.simplefilter('always')
with pytest.warns(DeprecationWarning):
stream = mock_func(potential, prog_orbit=prog, prog_mass=1E4*u.Msun,
Integrator=DOPRI853Integrator, **extra_kwargs)

check = False
for www in wa:
check = check or issubclass(www.category, DeprecationWarning)
assert check

# Integrator not supported
with pytest.raises(ValueError):
stream = mock_func(potential, prog_orbit=prog, prog_mass=1E4*u.Msun,
Expand Down
19 changes: 4 additions & 15 deletions gala/dynamics/tests/test_core.py
Expand Up @@ -145,15 +145,9 @@ def test_to_coord_frame():
coo,vel = o.to_coord_frame(Galactic)
assert coo.name == 'galactic'

with warnings.catch_warnings(record=True) as wa:
warnings.simplefilter('always')
warnings.simplefilter('always')
with pytest.warns(DeprecationWarning):
o.to_frame(Galactic)
# assert len(wa) == 1

check = False
for www in wa:
check = check or issubclass(www.category, DeprecationWarning)
assert check

# doesn't work for 2D
x = np.random.random(size=(2,10))*u.kpc
Expand Down Expand Up @@ -214,15 +208,10 @@ def test_energy():
PE = o.potential_energy(p)
E = o.energy(H)

with warnings.catch_warnings(record=True) as wa:
warnings.simplefilter('always')
warnings.simplefilter('always')
with pytest.warns(DeprecationWarning):
o.energy(p)

check = False
for www in wa:
check = check or issubclass(www.category, DeprecationWarning)
assert check

def test_angular_momentum():

w = CartesianPhaseSpacePosition([1.,0.,0.], [0.,0.,1.])
Expand Down

0 comments on commit 641a370

Please sign in to comment.