Coverage for tests/test_bps_utils.py: 44%
24 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-09 03:04 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-09 03:04 -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
26from lsst.ctrl.bps.bps_utils import chdir
28TESTDIR = os.path.abspath(os.path.dirname(__file__))
31class TestChdir(unittest.TestCase):
32 def setUp(self):
33 self.cwd = os.getcwd()
34 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR)
36 def tearDown(self):
37 shutil.rmtree(self.tmpdir, ignore_errors=True)
39 def testSuccessfulChdir(self):
40 self.assertNotEqual(os.getcwd(), self.tmpdir)
41 with chdir(self.tmpdir):
42 self.assertEqual(os.getcwd(), self.tmpdir)
43 self.assertNotEqual(os.getcwd(), self.tmpdir)
45 def testFailingChdir(self):
46 dir_not_there = os.path.join(self.tmpdir, "notthere")
47 with self.assertRaises(FileNotFoundError):
48 with chdir(dir_not_there):
49 pass # should not get here
52if __name__ == "__main__": 52 ↛ 53line 52 didn't jump to line 53, because the condition on line 52 was never true
53 unittest.main()