Skip to content

Commit

Permalink
Add tests for ensure_unit
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Horton committed Mar 7, 2018
1 parent 558daa0 commit f10372d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions gunagala/tests/test_utils.py
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)

0 comments on commit f10372d

Please sign in to comment.