1 | # Licensed under a 3-clause BSD style license - see LICENSE.rst |
||
2 | from __future__ import absolute_import, division, print_function, unicode_literals |
||
3 | import pytest |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
4 | from collections import OrderedDict |
||
5 | from numpy.testing import assert_allclose |
||
6 | import astropy.units as u |
||
7 | from astropy.table import Table, Column |
||
8 | from ..table import table_standardise_units_copy, table_row_to_dict, table_from_row_data |
||
9 | |||
10 | |||
11 | def test_table_standardise_units(): |
||
12 | table = Table( |
||
13 | [ |
||
14 | Column([1], "a", unit="ph cm-2 s-1"), |
||
15 | Column([1], "b", unit="ct cm-2 s-1"), |
||
16 | Column([1], "c", unit="cm-2 s-1"), |
||
17 | Column([1], "d"), |
||
18 | ] |
||
19 | ) |
||
20 | |||
21 | table = table_standardise_units_copy(table) |
||
22 | |||
23 | assert table["a"].unit == "cm-2 s-1" |
||
24 | assert table["b"].unit == "cm-2 s-1" |
||
25 | assert table["c"].unit == "cm-2 s-1" |
||
26 | assert table["d"].unit is None |
||
27 | |||
28 | |||
29 | @pytest.fixture() |
||
30 | def table(): |
||
31 | return Table( |
||
32 | [Column([1, 2], "a"), Column([1, 2] * u.m, "b"), Column(["x", "yy"], "c")] |
||
33 | ) |
||
34 | |||
35 | |||
36 | def test_table_row_to_dict(table): |
||
37 | actual = table_row_to_dict(table[1]) |
||
38 | expected = OrderedDict([("a", 2), ("b", 2 * u.m), ("c", "yy")]) |
||
39 | assert actual == expected |
||
40 | |||
41 | |||
42 | def test_table_from_row_data(): |
||
43 | rows = [dict(a=1, b=1 * u.m, c="x"), dict(a=2, b=2 * u.km, c="yy")] |
||
44 | table = table_from_row_data(rows) |
||
45 | assert isinstance(table, Table) |
||
46 | assert table["b"].unit == "m" |
||
47 | assert_allclose(table["b"].data, [1, 2000]) |
||
48 |