Coverage for tests/test_transfer.py: 33%

24 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-19 10:06 +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/>. 

21 

22from __future__ import annotations 

23 

24import unittest 

25 

26from lsst.daf.relation import Transfer, iteration, tests 

27 

28 

29class TransferTestCase(tests.RelationTestCase): 

30 """Tests for the Transfer operation and relations based on it.""" 

31 

32 def setUp(self) -> None: 

33 self.a = tests.ColumnTag("a") 

34 self.source_engine = iteration.Engine(name="source") 

35 self.destination_engine = iteration.Engine(name="destination") 

36 self.leaf = self.source_engine.make_leaf( 

37 {self.a}, payload=iteration.RowSequence([{self.a: 0}, {self.a: 1}]), name="leaf" 

38 ) 

39 

40 def test_attributes(self) -> None: 

41 """Check that all UnaryOperation and Relation attributes have the 

42 expected values. 

43 """ 

44 relation = self.leaf.transferred_to(self.destination_engine) 

45 assert isinstance(relation, Transfer) 

46 self.assertEqual(relation.columns, self.leaf.columns) 

47 self.assertEqual(relation.engine, self.destination_engine) 

48 self.assertEqual(relation.min_rows, self.leaf.min_rows) 

49 self.assertEqual(relation.max_rows, self.leaf.max_rows) 

50 self.assertFalse(relation.is_locked) 

51 self.assertTrue(relation.destination, self.destination_engine) 

52 

53 def test_apply_simplify(self) -> None: 

54 """Test simplification logic in Transfer.apply.""" 

55 self.assert_relations_equal(self.leaf.transferred_to(self.source_engine), self.leaf) 

56 self.assert_relations_equal( 

57 self.leaf.transferred_to(self.destination_engine).transferred_to(self.source_engine), self.leaf 

58 ) 

59 

60 def test_str(self) -> None: 

61 """Test str(Transfer) and 

62 str(UnaryOperationRelation[Transfer]). 

63 """ 

64 relation = self.leaf.transferred_to(self.destination_engine) 

65 self.assertEqual(str(relation), f"→[destination]({self.leaf})") 

66 

67 

68if __name__ == "__main__": 

69 unittest.main()