Coverage for tests/test_usage.py: 33%
26 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-11 01:01 -0700
« 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.
12import unittest
14from astropy import units as u
15from lsst.utils.usage import get_current_mem_usage, get_peak_mem_usage
18class UsageTestCase(unittest.TestCase):
19 def testGetCurrentMemUsage(self):
20 main1, children1 = get_current_mem_usage()
21 self.assertGreater(main1, 0 * u.byte)
22 self.assertGreaterEqual(children1.value, 0)
24 self.assertTrue(main1.unit.is_equivalent(u.byte))
25 self.assertTrue(children1.unit.is_equivalent(u.byte))
27 # Allocate some memory.
28 arr = [None] * 1_000_000 # noqa: F841
30 main2, children2 = get_current_mem_usage()
31 self.assertGreater(main2, main1)
32 self.assertGreaterEqual(children2, children1)
34 def testGetPeakMemUsage(self):
35 main1, child1 = get_peak_mem_usage()
36 self.assertGreater(main1, 0 * u.byte)
37 self.assertGreaterEqual(child1, 0 * u.byte)
39 self.assertTrue(main1.unit.is_equivalent(u.byte))
40 self.assertTrue(child1.unit.is_equivalent(u.byte))
42 # Allocate some memory.
43 arr = [None] * 2_000_000 # noqa: F841
45 main2, child2 = get_peak_mem_usage()
46 self.assertGreater(main2, main1)
47 self.assertGreaterEqual(child2, child1)
50if __name__ == "__main__": 50 ↛ 51line 50 didn't jump to line 51, because the condition on line 50 was never true
51 unittest.main()