Coverage for tests/test_inheritDoc.py: 67%
48 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-27 11:49 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-27 11:49 +0000
1# This file is part of utils.
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/>.
22import inspect
23import unittest
25from lsst.utils import inheritDoc
28class Base:
29 """Base class containing some docstrings."""
31 def method1() -> None:
32 """Return Method 1.
34 A note.
35 """
36 pass
38 def method2() -> None:
39 """Return Method 2."""
40 pass
42 def method3() -> None:
43 pass
45 def method4() -> None:
46 """Return Method 4."""
47 pass
49 def method5() -> None:
50 pass
52 def method6() -> None:
53 """Return Method 6.
55 Content.""" # noqa: D209
56 pass
59class NoInheritDoc(Base):
60 """Class that inherits from base class and inherits docstring."""
62 def method2() -> None:
63 # Docstring inherited.
64 pass
67class InheritDoc:
68 """Class that uses inheritDoc and no explicit inheritance."""
70 @inheritDoc(Base)
71 def method1() -> None:
72 """Note on method 1.
74 New line.
75 """
76 pass
78 @inheritDoc(Base)
79 def method2() -> None:
80 """Note on method 2."""
82 @inheritDoc(Base)
83 def method3() -> None:
84 """Note on method 3."""
86 @inheritDoc(Base)
87 def method4() -> None:
88 # Will inherit even though not parent class.
89 pass
91 @inheritDoc(Base)
92 def method5() -> None:
93 # No doc string here or in Base.
94 pass
96 @inheritDoc(Base)
97 def method6() -> None:
98 """
99 Notes
100 -----
101 A note.
102 """ # noqa: D401
103 pass
106class InheritDocTestCase(unittest.TestCase):
107 """Test inheritDoc functionality."""
109 def test_no_inheritdoc(self):
110 self.assertIsNone(NoInheritDoc.method2.__doc__)
111 self.assertEqual(inspect.getdoc(NoInheritDoc.method2), "Return Method 2.")
112 self.assertIsNone(inspect.getdoc(NoInheritDoc.method5))
114 def test_inheritDoc(self):
115 self.assertEqual(
116 inspect.getdoc(InheritDoc.method1),
117 """Return Method 1.
119A note.
121Note on method 1.
123New line.""",
124 )
125 self.assertEqual(
126 inspect.getdoc(InheritDoc.method2),
127 """Return Method 2.
129Note on method 2.""",
130 )
131 self.assertEqual(inspect.getdoc(InheritDoc.method3), "Note on method 3.")
132 self.assertEqual(inspect.getdoc(InheritDoc.method4), "Return Method 4.")
133 self.assertIsNone(inspect.getdoc(InheritDoc.method5))
135 self.assertEqual(
136 inspect.getdoc(InheritDoc.method6),
137 """Return Method 6.
139Content.
141Notes
142-----
143A note.""",
144 )
147if __name__ == "__main__":
148 unittest.main()