Coverage for tests/test_shadowing.py: 43%
40 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-08-18 18:35 +0000
« prev ^ index » next coverage.py v6.4.4, created at 2022-08-18 18:35 +0000
1# This file is part of astro_metadata_translator.
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 LICENSE file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
12import unittest
14from astro_metadata_translator import StubTranslator
17class ShadowBase(StubTranslator):
18 def to_instrument(self):
19 return "BaseInstrument"
22class ConstTranslator(StubTranslator):
23 _const_map = {"instrument": "InstrumentB"}
26class TrivialTranslator(ConstTranslator):
27 # This should not pick up the _const_map from parent class
28 _trivial_map = {"instrument": "INSTRUME"}
31class ExplicitTranslator(TrivialTranslator):
32 # The explicit method should override the parent implementations
33 # and not inherit the _trivial_map from parent.
34 def to_instrument(self):
35 return "InstrumentE"
38class TranslatorShadowing(unittest.TestCase):
39 def test_shadowing(self):
41 with self.assertLogs("astro_metadata_translator", level="WARN") as cm:
43 class ShadowTranslator(StubTranslator):
44 _const_map = {"instrument": "InstrumentC"}
45 _trivial_map = {"instrument": "INSTRUME"}
47 def to_instrument(self):
48 return "Instrument3"
50 self.assertIn("defined in both", cm.output[0])
51 self.assertIn("replaced by _const_map", cm.output[1])
53 s = ShadowTranslator({})
54 self.assertEqual(s.to_instrument(), "InstrumentC")
56 with self.assertLogs("astro_metadata_translator", level="WARN") as cm:
58 class ShadowTranslator(StubTranslator):
59 _trivial_map = {"instrument": "INSTRUME"}
61 def to_instrument(self):
62 return "Instrument3"
64 self.assertIn("replaced by _trivial_map", cm.output[0])
66 s = ShadowTranslator({"INSTRUME": "InstrumentT"})
67 self.assertEqual(s.to_instrument(), "InstrumentT")
69 def test_auto_maps1(self):
70 t = TrivialTranslator({"INSTRUME": "InstrumentX"})
71 self.assertEqual(t.to_instrument(), "InstrumentX")
73 def test_auto_maps2(self):
74 t = ExplicitTranslator({})
75 self.assertEqual(t.to_instrument(), "InstrumentE")
78if __name__ == "__main__": 78 ↛ 79line 78 didn't jump to line 79, because the condition on line 78 was never true
79 unittest.main()