Coverage for tests/test_config_formatter.py: 53%

28 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-18 01:59 -0800

1# This file is part of pipe_base. 

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 

22"""Tests for PexConfigFormatter. 

23""" 

24 

25import os 

26import unittest 

27 

28import lsst.pex.config 

29from lsst.daf.butler import Butler, DatasetType 

30from lsst.daf.butler.tests.utils import makeTestTempDir, removeTestTempDir 

31 

32TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

33 

34 

35class SimpleConfig(lsst.pex.config.Config): 

36 """Config to use in tests for butler put/get""" 

37 

38 i = lsst.pex.config.Field("integer test", int) 

39 c = lsst.pex.config.Field("string", str) 

40 

41 

42class PexConfigFormatterTestCase(unittest.TestCase): 

43 """Tests for PexConfigFormatter, using local file datastore.""" 

44 

45 def setUp(self): 

46 """Create a new butler root for each test.""" 

47 self.root = makeTestTempDir(TESTDIR) 

48 Butler.makeRepo(self.root) 

49 self.butler = Butler(self.root, run="test_run") 

50 # No dimensions in dataset type so we don't have to worry about 

51 # inserting dimension data or defining data IDs. 

52 self.datasetType = DatasetType( 

53 "config", dimensions=(), storageClass="Config", universe=self.butler.registry.dimensions 

54 ) 

55 self.butler.registry.registerDatasetType(self.datasetType) 

56 

57 def tearDown(self): 

58 removeTestTempDir(self.root) 

59 

60 def testPexConfig(self) -> None: 

61 """Test that we can put and get pex_config Configs""" 

62 c = SimpleConfig(i=10, c="hello") 

63 self.assertEqual(c.i, 10) 

64 ref = self.butler.put(c, "config") 

65 butler_c = self.butler.get(ref) 

66 self.assertEqual(c, butler_c) 

67 self.assertIsInstance(butler_c, SimpleConfig) 

68 

69 

70if __name__ == "__main__": 70 ↛ 71line 70 didn't jump to line 71, because the condition on line 70 was never true

71 unittest.main()