-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anthony Horton
committed
Mar 7, 2018
1 parent
558daa0
commit f10372d
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
import astropy.units as u | ||
from astropy.table import Column | ||
|
||
from gunagala import utils | ||
|
||
|
||
def test_ensure_unit_quantity(): | ||
q = (1.0, 42) * u.imperial.furlong | ||
result = utils.ensure_unit(q, u.m) | ||
assert (result == q.to(u.m)).all() | ||
|
||
|
||
def test_ensure_unit_floats(): | ||
f = (1.0, 42.0) | ||
result = utils.ensure_unit(f, u.m) | ||
assert (result == f * u.m).all() | ||
|
||
|
||
def test_ensure_unit_column(): | ||
c = Column(data=(1.0, 42), name='test', unit=u.imperial.furlong) | ||
result = utils.ensure_unit(c, u.m) | ||
assert (result == c.to(u.m)).all() | ||
|
||
|
||
def test_ensure_unit_bad_unit(): | ||
with pytest.raises(u.UnitConversionError): | ||
q = (1.0, 42) * u.fortnight | ||
result = utils.ensure_unit(q, u.m) | ||
|
||
|
||
def test_ensure_unit_non_numeric(): | ||
with pytest.raises(ValueError): | ||
s = "fortytwo" | ||
result = utils.ensure_unit(s, u.m) |