[core/output] Rewrite to hide sys.stout

Add generic "draw()" method that redirects internally to the actual
calls. These can now produce JSON, which is nicer because:

1. Easier to use during testing
2. More flexible
3. Centralizes printing (somewhat)

Still, the "suffix" concept isn't really nice, but so far, I have no
better approach.
This commit is contained in:
Tobias Witek 2020-02-01 21:37:38 +01:00
parent b7ca5eb3a5
commit 66537fbe05
4 changed files with 44 additions and 20 deletions

View file

@ -11,17 +11,15 @@ class i3(unittest.TestCase):
pass
def test_start(self):
data = json.loads(self.i3.start())
all_data = self.i3.start()
data = all_data['data']
self.assertEqual(1, data['version'], 'i3bar protocol version 1 expected')
self.assertTrue(data['click_events'], 'click events should be enabled')
def test_begin_status_line(self):
self.assertEqual('[', self.i3.begin_status_line(), 'each line must be a JSON array')
def test_end_status_line(self):
self.assertEqual('],\n', self.i3.end_status_line(), 'each line must terminate properly')
self.assertEqual('\n[', all_data['suffix'])
def test_stop(self):
self.assertEqual(']\n', self.i3.stop())
self.assertEqual('\n]', self.i3.stop()['suffix'])
# TODO: mock a "draw" call
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4