[2481] | 1 | from nose.tools import *
|
---|
| 2 | from asap.selector import selector
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 | # call constructor with args
|
---|
| 6 | def constructor(d):
|
---|
| 7 | p = selector(**d)
|
---|
| 8 | for k, v in d.items():
|
---|
| 9 | meth = getattr(p, 'get_%s' % k)
|
---|
| 10 | val = v
|
---|
| 11 | if not hasattr(val, "__len__"):
|
---|
| 12 | val = [val]
|
---|
| 13 | assert_equals(meth(), val)
|
---|
| 14 |
|
---|
| 15 | # generator for constructor arguments
|
---|
| 16 | def test_constructor_keys():
|
---|
| 17 | args = [ { 'rows': 0 },
|
---|
| 18 | { 'rows': [1,2]},
|
---|
| 19 | { 'ifs': 0 },
|
---|
| 20 | { 'ifs': [1,2]},
|
---|
| 21 | { 'beams': 0 },
|
---|
| 22 | { 'beams': [1,2] },
|
---|
| 23 | { 'pols': 0 },
|
---|
| 24 | { 'pols': range(4) },
|
---|
| 25 | { 'cycles': 0 },
|
---|
| 26 | { 'cycles': range(5) },
|
---|
| 27 | { 'scans': 0 },
|
---|
| 28 | { 'scans': range(5) },
|
---|
| 29 | { 'scans': range(5), 'beams': 0 },
|
---|
| 30 | ]
|
---|
| 31 | for arg in args:
|
---|
| 32 | yield constructor, arg
|
---|
| 33 |
|
---|
| 34 | def test_copy_constructor():
|
---|
| 35 | v = [0]
|
---|
| 36 | s = selector(ifs=v)
|
---|
| 37 | scpy = selector(s)
|
---|
| 38 | assert_equals(s.get_ifs(), scpy.get_ifs())
|
---|
| 39 | scpy.set_beams(v)
|
---|
| 40 | assert_not_equals(s.get_beams(), scpy.get_beams())
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | def test_add():
|
---|
| 44 | v = [0]
|
---|
| 45 | s1 = selector(ifs=v)
|
---|
| 46 | s2 = selector(beams=v)
|
---|
| 47 | s3 = s1 + s2
|
---|
| 48 | assert_equals(s3.get_ifs(), v)
|
---|
| 49 | assert_equals(s3.get_beams(), v)
|
---|
| 50 | assert_not_equals(id(s3), id(s1))
|
---|
| 51 | assert_not_equals(id(s3), id(s2))
|
---|
| 52 |
|
---|
| 53 | def test_fields():
|
---|
| 54 | base = ['pols', 'ifs', 'beams', 'scans', 'cycles', 'name',
|
---|
| 55 | 'query', 'types', 'rows']
|
---|
| 56 | assert_equals(selector.fields, base)
|
---|
| 57 |
|
---|
| 58 | def test_reset():
|
---|
| 59 | v = [0]
|
---|
| 60 | s = selector(ifs=v)
|
---|
| 61 | assert_equals(s.get_ifs(), v)
|
---|
| 62 | s.reset()
|
---|
| 63 | assert_true(s.is_empty())
|
---|
| 64 |
|
---|