Coverage for tests/test_threads.py: 35%

27 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-09-11 01:01 -0700

1# This file is part of utils. 

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# Use of this source code is governed by a 3-clause BSD-style 

10# license that can be found in the LICENSE file. 

11# 

12 

13import os 

14import unittest 

15 

16from lsst.utils.threads import disable_implicit_threading, set_thread_envvars 

17 

18try: 

19 import numexpr 

20except ImportError: 

21 numexpr = None 

22try: 

23 import threadpoolctl 

24except ImportError: 

25 threadpoolctl = None 

26 

27 

28class ThreadsTestCase(unittest.TestCase): 

29 """Tests for threads.""" 

30 

31 def testDisable(self): 

32 set_thread_envvars(2, override=True) 

33 self.assertEqual(os.environ["OMP_NUM_THREADS"], "2") 

34 set_thread_envvars(3, override=False) 

35 self.assertEqual(os.environ["OMP_NUM_THREADS"], "2") 

36 

37 disable_implicit_threading() 

38 self.assertEqual(os.environ["OMP_NUM_THREADS"], "1") 

39 

40 # Check that we have only one thread. 

41 if numexpr: 

42 self.assertEqual(numexpr.utils.get_num_threads(), 1) 

43 if threadpoolctl: 

44 info = threadpoolctl.threadpool_info() 

45 for api in info: 

46 self.assertEqual(api["num_threads"], 1, f"API: {api}") 

47 

48 

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

50 unittest.main()