Coverage for tests/test_utils.py: 92%

20 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-25 22:00 -0800

1# This file is part of sconsUtils. 

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/>. 

21 

22"""Tests for `lsst.sconsUtils.utils`.""" 

23 

24import os 

25import unittest 

26from unittest import mock 

27 

28from lsst.sconsUtils.utils import conda_compilers 

29 

30 

31class CondaCompilersTestCase(unittest.TestCase): 

32 """Test the choice of compilers when using conda compilers.""" 

33 

34 def test_environment_is_used(self): 

35 with mock.patch.dict(os.environ, {"CC": "conda-cc", "CXX": "conda-c++"}): 

36 self.assertEqual(conda_compilers(), ("conda-cc", "conda-c++")) 

37 

38 def test_defaults_without_environment(self): 

39 for platform, expected in (("linux", ("gcc", "g++")), ("darwin", ("clang", "clang++"))): 

40 with ( 

41 self.subTest(platform=platform), 

42 mock.patch.dict(os.environ), 

43 mock.patch("sys.platform", platform), 

44 ): 

45 os.environ.pop("CC", None) 

46 os.environ.pop("CXX", None) 

47 self.assertEqual(conda_compilers(), expected) 

48 

49 def test_each_variable_falls_back_independently(self): 

50 with mock.patch.dict(os.environ, {"CC": "my-cc"}), mock.patch("sys.platform", "linux"): 

51 os.environ.pop("CXX", None) 

52 self.assertEqual(conda_compilers(), ("my-cc", "g++")) 

53 

54 

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

56 unittest.main()