Coverage for tests/test_shadowing.py: 35%
40 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-02 09:54 +0000
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-02 09:54 +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):
40 with self.assertLogs("astro_metadata_translator", level="WARN") as cm:
42 class ShadowTranslator(StubTranslator):
43 _const_map = {"instrument": "InstrumentC"}
44 _trivial_map = {"instrument": "INSTRUME"}
46 def to_instrument(self):
47 return "Instrument3"
49 self.assertIn("defined in both", cm.output[0])
50 self.assertIn("replaced by _const_map", cm.output[1])
52 s = ShadowTranslator({})
53 self.assertEqual(s.to_instrument(), "InstrumentC")
55 with self.assertLogs("astro_metadata_translator", level="WARN") as cm:
57 class ShadowTranslator(StubTranslator):
58 _trivial_map = {"instrument": "INSTRUME"}
60 def to_instrument(self):
61 return "Instrument3"
63 self.assertIn("replaced by _trivial_map", cm.output[0])
65 s = ShadowTranslator({"INSTRUME": "InstrumentT"})
66 self.assertEqual(s.to_instrument(), "InstrumentT")
68 def test_auto_maps1(self):
69 t = TrivialTranslator({"INSTRUME": "InstrumentX"})
70 self.assertEqual(t.to_instrument(), "InstrumentX")
72 def test_auto_maps2(self):
73 t = ExplicitTranslator({})
74 self.assertEqual(t.to_instrument(), "InstrumentE")
77if __name__ == "__main__": 77 ↛ 78line 77 didn't jump to line 78, because the condition on line 77 was never true
78 unittest.main()