Coverage for tests/test_usage.py: 33%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

26 statements  

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 

12import unittest 

13 

14from astropy import units as u 

15from lsst.utils.usage import get_current_mem_usage, get_peak_mem_usage 

16 

17 

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) 

23 

24 self.assertTrue(main1.unit.is_equivalent(u.byte)) 

25 self.assertTrue(children1.unit.is_equivalent(u.byte)) 

26 

27 # Allocate some memory. 

28 arr = [None] * 1_000_000 # noqa: F841 

29 

30 main2, children2 = get_current_mem_usage() 

31 self.assertGreater(main2, main1) 

32 self.assertGreaterEqual(children2, children1) 

33 

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) 

38 

39 self.assertTrue(main1.unit.is_equivalent(u.byte)) 

40 self.assertTrue(child1.unit.is_equivalent(u.byte)) 

41 

42 # Allocate some memory. 

43 arr = [None] * 2_000_000 # noqa: F841 

44 

45 main2, child2 = get_peak_mem_usage() 

46 self.assertGreater(main2, main1) 

47 self.assertGreaterEqual(child2, child1) 

48 

49 

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

51 unittest.main()