Coverage for python/lsst/daf/relation/_transfer.py: 56%

28 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-08-19 09:55 +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 

24__all__ = ("Transfer",) 

25 

26import dataclasses 

27from typing import TYPE_CHECKING, final 

28 

29from ._engine import Engine 

30from ._marker_relation import MarkerRelation 

31 

32if TYPE_CHECKING: 

33 from ._relation import Relation 

34 

35 

36@final 

37@dataclasses.dataclass(frozen=True, kw_only=True) 

38class Transfer(MarkerRelation): 

39 """A `MarkerRelation` operation that represents moving relation content 

40 from one engine to another. 

41 

42 A single `Engine` cannot generally process a relation tree that contains 

43 transfers. The `Processor` class provides a framework for handling these 

44 trees. 

45 """ 

46 

47 destination: Engine 

48 """Engine the target relation content will be transferred to (`Engine`). 

49 """ 

50 

51 @property 

52 def engine(self) -> Engine: 

53 # Docstring inherited. 

54 return self.destination 

55 

56 def __str__(self) -> str: 

57 return f"→[{self.destination}]({self.target})" 

58 

59 @classmethod 

60 def simplify(cls, target: Relation, destination: Engine) -> Relation | None: 

61 if target.is_locked: 

62 return None 

63 match target: 

64 case Transfer(target=new_target): 

65 if destination == new_target.engine: 

66 return new_target 

67 else: 

68 return cls.simplify(new_target, destination) 

69 case MarkerRelation(target=new_target): 

70 return cls.simplify(new_target, destination) 

71 return None