Coverage for tests/test_materialization.py: 33%
31 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-07 10:05 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-07 10:05 +0000
1# This file is part of daf_relation.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22from __future__ import annotations
24import unittest
26from lsst.daf.relation import ColumnExpression, Materialization, iteration, tests
29class MaterializationTestCase(tests.RelationTestCase):
30 """Tests for the Materialization operation and relations based on it."""
32 def setUp(self) -> None:
33 self.a = tests.ColumnTag("a")
34 self.engine = iteration.Engine(name="preferred")
35 self.leaf = self.engine.make_leaf(
36 {self.a}, payload=iteration.RowSequence([{self.a: 0}, {self.a: 1}]), name="leaf"
37 )
38 # Materializing a leaf just returns the leaf, so we add a Selection to
39 # make applying it nontrivial.
40 self.target = self.leaf.with_rows_satisfying(
41 ColumnExpression.reference(self.a).gt(ColumnExpression.literal(0))
42 )
44 def test_attributes(self) -> None:
45 """Check that all UnaryOperation and Relation attributes have the
46 expected values.
47 """
48 relation = self.target.materialized(name_prefix="prefix")
49 assert isinstance(relation, Materialization)
50 self.assertEqual(relation.columns, {self.a})
51 self.assertEqual(relation.engine, self.engine)
52 self.assertEqual(relation.min_rows, self.target.min_rows)
53 self.assertEqual(relation.max_rows, self.target.max_rows)
54 self.assertTrue(relation.is_locked)
55 self.assertTrue(relation.name.startswith("prefix"))
57 def test_apply_simplify(self) -> None:
58 """Test that applying a Materialization to a leaf or an existing
59 materialization does nothing.
60 """
61 self.assertEqual(self.leaf.materialized(), self.leaf)
62 self.assertEqual(self.target.materialized(name="a").materialized("b"), self.target.materialized("a"))
64 def test_iteration(self) -> None:
65 """Test Materialization execution in the iteration engine."""
66 relation = self.target.materialized(name="m")
67 self.assertEqual(
68 list(self.engine.execute(relation)),
69 [{self.a: 1}],
70 )
71 self.assertIsNotNone(relation.payload)
72 self.assertIsInstance(relation.payload, iteration.MaterializedRowIterable)
74 def test_str(self) -> None:
75 """Test str(Materialization) and
76 str(UnaryOperationRelation[Materialization]).
77 """
78 relation = self.target.materialized(name="m")
79 self.assertEqual(str(relation), f"materialize['m']({self.target})")
82if __name__ == "__main__": 82 ↛ 83line 82 didn't jump to line 83, because the condition on line 82 was never true
83 unittest.main()