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 datetime
2import unittest
3from unittest import mock
4from pi3bar.plugins.clock import Clock
7class ClockTestCase(unittest.TestCase):
8 def test_default_values(self):
9 plugin = Clock()
10 full_format = '%Y-%m-%d %H:%M:%S'
11 self.assertEqual(full_format, plugin.full_format)
12 self.assertEqual('%d. %H:%M', plugin.short_format)
13 self.assertIsNone(plugin.instance)
14 self.assertIsNone(plugin.timezone)
16 def test_timezone(self):
17 plugin = Clock(timezone='actually_not_a_timezone')
18 self.assertEqual('actually_not_a_timezone', plugin.timezone)
20 def test_cycle(self):
21 plugin = Clock()
22 dt = datetime.datetime(2014, 7, 12, 2, 13, 37)
23 with mock.patch('pi3bar.plugins.clock.datetime') as mock_datetime:
24 mock_datetime.datetime.now.return_value.strftime = datetime.datetime.strftime
25 mock_datetime.datetime.now.return_value = dt
26 plugin.cycle()
27 self.assertEqual('2014-07-12 02:13:37', plugin.full_text)
28 self.assertEqual('12. 02:13', plugin.short_text)
30 def test_cycle_format(self):
31 plugin = Clock(full_format='%d.%m.%Y %H:%M:%S')
32 dt = datetime.datetime(2014, 7, 12, 2, 13, 37)
33 with mock.patch('pi3bar.plugins.clock.datetime') as mock_datetime:
34 mock_datetime.datetime.now.return_value.strftime = datetime.datetime.strftime
35 mock_datetime.datetime.now.return_value = dt
36 plugin.cycle()
37 self.assertEqual('12.07.2014 02:13:37', plugin.full_text)
38 self.assertEqual('12. 02:13', plugin.short_text)