Coverage for tests/test_bps_utils.py: 50%

24 statements  

« prev     ^ index     » next       coverage.py v7.2.1, created at 2023-03-12 03:01 -0700

1# This file is part of ctrl_bps. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://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 <https://www.gnu.org/licenses/>. 

21import os 

22import shutil 

23import tempfile 

24import unittest 

25 

26from lsst.ctrl.bps.bps_utils import chdir 

27 

28 

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

30 

31 

32class TestChdir(unittest.TestCase): 

33 

34 def setUp(self): 

35 self.cwd = os.getcwd() 

36 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR) 

37 

38 def tearDown(self): 

39 shutil.rmtree(self.tmpdir, ignore_errors=True) 

40 

41 def testSuccessfulChdir(self): 

42 self.assertNotEqual(os.getcwd(), self.tmpdir) 

43 with chdir(self.tmpdir): 

44 self.assertEqual(os.getcwd(), self.tmpdir) 

45 self.assertNotEqual(os.getcwd(), self.tmpdir) 

46 

47 def testFailingChdir(self): 

48 dir_not_there = os.path.join(self.tmpdir, "notthere") 

49 with self.assertRaises(FileNotFoundError): 

50 with chdir(dir_not_there): 

51 pass # should not get here 

52 

53 

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

55 unittest.main()