Hide keyboard shortcuts

Hot-keys 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

1import unittest 

2from unittest import mock 

3from pi3bar.plugins.uptime import get_uptime_seconds, uptime_format, Uptime 

4 

5 

6class GetUptimeSecondsTestCase(unittest.TestCase): 

7 def test(self): 

8 m = mock.mock_open(read_data='5') 

9 m.return_value.readline.return_value = '5' # py33 

10 with mock.patch('pi3bar.plugins.uptime.open', m, create=True): 

11 seconds = get_uptime_seconds() 

12 self.assertEqual(5, seconds) 

13 

14 

15class UptimeFormatTestCase(unittest.TestCase): 

16 def test_seconds(self): 

17 s = uptime_format(5) 

18 self.assertEqual('0:00:00:05', s) 

19 

20 def test_minutes(self): 

21 s = uptime_format(3540) 

22 self.assertEqual('0:00:59:00', s) 

23 

24 def test_hours(self): 

25 s = uptime_format(49020) 

26 self.assertEqual('0:13:37:00', s) 

27 

28 def test_days(self): 

29 s = uptime_format(135420) 

30 self.assertEqual('1:13:37:00', s) 

31 

32 def test_format_days_applied_to_hours(self): 

33 s = uptime_format(135420, '%H:%M:%S') 

34 self.assertEqual('37:37:00', s) 

35 

36 def test_format_hours_applied_to_minutes(self): 

37 s = uptime_format(49020, '%M:%S') 

38 self.assertEqual('817:00', s) 

39 

40 

41class UptimeTestCase(unittest.TestCase): 

42 def test(self): 

43 plugin = Uptime() 

44 self.assertEqual('%d days %H:%M:%S up', plugin.full_format) 

45 self.assertEqual('%dd %H:%M up', plugin.short_format) 

46 

47 @mock.patch('pi3bar.plugins.uptime.get_uptime_seconds') 

48 def test_cycle(self, mock_get_uptime_seconds): 

49 plugin = Uptime() 

50 

51 mock_get_uptime_seconds.return_value = 49020 

52 plugin.cycle() 

53 

54 self.assertEqual('0 days 13:37:00 up', plugin.full_text) 

55 self.assertEqual('0d 13:37 up', plugin.short_text)