2020-01-19 13:29:34 +01:00
|
|
|
import json
|
2020-02-02 14:18:13 +01:00
|
|
|
import unittest
|
2020-01-01 21:22:31 +01:00
|
|
|
|
2020-03-23 15:40:53 +01:00
|
|
|
import core.config
|
2020-01-19 13:29:34 +01:00
|
|
|
import core.output
|
2020-02-02 14:18:13 +01:00
|
|
|
import core.module
|
|
|
|
|
|
|
|
class TestModule(core.module.Module):
|
|
|
|
pass
|
2020-01-01 21:22:31 +01:00
|
|
|
|
2020-01-19 13:29:34 +01:00
|
|
|
class i3(unittest.TestCase):
|
2020-01-01 21:22:31 +01:00
|
|
|
def setUp(self):
|
2020-01-19 13:29:34 +01:00
|
|
|
self.i3 = core.output.i3()
|
2020-02-02 14:18:13 +01:00
|
|
|
widget = unittest.mock.MagicMock()
|
|
|
|
widget.full_text.return_value = "test"
|
2020-03-23 15:40:53 +01:00
|
|
|
self.someModule = TestModule(config=core.config.Config([]),
|
|
|
|
widgets=[widget, widget, widget])
|
2020-03-01 14:08:16 +01:00
|
|
|
self.paddedTheme = core.theme.Theme(raw_data = {
|
|
|
|
'defaults': { 'padding': ' ' }
|
|
|
|
});
|
2020-01-19 13:29:34 +01:00
|
|
|
|
|
|
|
def test_start(self):
|
2020-02-22 13:42:44 +01:00
|
|
|
core.event.clear()
|
|
|
|
|
2020-02-01 21:37:38 +01:00
|
|
|
all_data = self.i3.start()
|
|
|
|
data = all_data['data']
|
2020-01-19 15:36:52 +01:00
|
|
|
self.assertEqual(1, data['version'], 'i3bar protocol version 1 expected')
|
2020-01-19 13:29:34 +01:00
|
|
|
self.assertTrue(data['click_events'], 'click events should be enabled')
|
2020-02-01 21:37:38 +01:00
|
|
|
self.assertEqual('\n[', all_data['suffix'])
|
2020-01-19 13:29:34 +01:00
|
|
|
|
|
|
|
def test_stop(self):
|
2020-02-02 14:18:13 +01:00
|
|
|
self.assertEqual('\n]', self.i3.stop()['suffix'], 'wrong i3bar protocol during stop')
|
|
|
|
|
|
|
|
def test_no_modules_by_default(self):
|
|
|
|
self.assertEqual(0, len(self.i3.modules()), 'module list should be empty by default')
|
|
|
|
|
|
|
|
def test_register_single_module(self):
|
|
|
|
self.i3.modules(self.someModule)
|
|
|
|
self.assertEqual(1, len(self.i3.modules()), 'setting single module does not work')
|
|
|
|
|
|
|
|
def test_register_multiple_modules(self):
|
|
|
|
self.i3.modules([ self.someModule, self.someModule, self.someModule ])
|
|
|
|
self.assertEqual(3, len(self.i3.modules()), 'setting module list does not work')
|
|
|
|
|
|
|
|
def test_draw_existing_module(self):
|
|
|
|
self.i3.test_draw = unittest.mock.MagicMock(return_value={
|
|
|
|
'data': { 'test': True }, 'suffix': 'end'
|
|
|
|
})
|
|
|
|
self.i3.draw('test_draw')
|
|
|
|
self.i3.test_draw.assert_called_once_with()
|
|
|
|
|
|
|
|
def test_empty_status_line(self):
|
|
|
|
data = self.i3.statusline()
|
|
|
|
self.assertEqual([], data['data'], 'expected empty list of status line entries')
|
|
|
|
self.assertEqual(',', data['suffix'], 'expected "," as suffix')
|
2020-02-01 21:37:38 +01:00
|
|
|
|
2020-02-02 14:18:13 +01:00
|
|
|
def test_statusline(self):
|
|
|
|
self.i3.modules([ self.someModule, self.someModule, self.someModule ])
|
2020-02-09 13:25:34 +01:00
|
|
|
self.i3.update()
|
2020-02-02 14:18:13 +01:00
|
|
|
data = self.i3.statusline()
|
|
|
|
self.assertEqual(len(self.someModule.widgets())*3, len(data['data']), 'wrong number of widgets')
|
2020-01-19 13:29:34 +01:00
|
|
|
|
2020-03-01 14:08:16 +01:00
|
|
|
def test_padding(self):
|
|
|
|
self.i3.theme(self.paddedTheme)
|
2020-03-01 14:36:12 +01:00
|
|
|
result = self.i3.__pad(self.someModule, self.someModule.widget(), 'abc')
|
2020-03-01 14:08:16 +01:00
|
|
|
self.assertEqual(' abc ', result)
|
|
|
|
|
2020-01-19 13:29:34 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|