Coverage for tests/test_threads.py: 31%
27 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-06 20:24 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-06 20:24 +0000
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#
13import os
14import unittest
16from lsst.utils.threads import disable_implicit_threading, set_thread_envvars
18try:
19 import numexpr
20except ImportError:
21 numexpr = None
22try:
23 import threadpoolctl
24except ImportError:
25 threadpoolctl = None
28class ThreadsTestCase(unittest.TestCase):
29 """Tests for threads."""
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")
37 disable_implicit_threading()
38 self.assertEqual(os.environ["OMP_NUM_THREADS"], "1")
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}")
49if __name__ == "__main__": 49 ↛ 50line 49 didn't jump to line 50, because the condition on line 49 was never true
50 unittest.main()