Skip to content

Commit

Permalink
tester for models.py
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHancock committed Aug 27, 2017
1 parent ab3df35 commit c30a012
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#! python

__author__ = 'Paul Hancock'
__date__ = ''

from AegeanTools import models
import numpy as np


def test_simple_source():
# make a new source without failing
ss = models.SimpleSource()
ss.ra = np.float32(12)
ss.sanitise()
assert isinstance(ss.ra, np.float64)
# convert to string without failing
a = "{0}".format(ss)
assert a == ' 12.0000000 0.0000000 0.000000 0.000000 0.00 0.00 0.0 000000'
assert ss.__repr__() == ss.__str__()
assert np.all(ss.as_list()[:-1] == [0.0, 0.0, 12.0, 0.0, 0.0, 0.0, 0, 0.0, 0.0, 0.0, 0.0])
isl = models.IslandSource()
isl2 = models.IslandSource()
assert isl < ss
assert isl <= ss
assert not(isl > ss)
assert not(isl >= ss)
assert isl == isl2
assert not(isl != isl2)
out = models.OutputSource()
out.source = 1
out2 = models.OutputSource()
out2.source = 2
out3 = models.OutputSource()
out3.island = 1
assert out < out2
assert out3 > out2
assert out <= out2
assert out3 >= out
assert out != out2
assert out == out


def test_global_fitting_data():
models.GlobalFittingData()


def test_island_fitting_data():
models.IslandFittingData()


def test_classify_catalogue():
ss = []
isl = []
out = []
all = []
for i in range(10):
a = models.SimpleSource()
ss.append(a)
b = models.IslandSource()
b.island = i
isl.append(b)
c = models.OutputSource()
c.island = i
d = models.OutputSource()
d.island = i
d.source = 1
out.extend([c, d])
all.extend([a, b, c, d])
a, b, c = models.classify_catalog(all)
assert np.all(b == isl)
assert np.all(a == out)
groups = list(models.island_itergen(a))
assert len(groups) == 10


if __name__ == "__main__":
# introspect and run all the functions starting with 'test'
for f in dir():
if f.startswith('test'):
print(f)
exec(f+"()")

0 comments on commit c30a012

Please sign in to comment.