From 0ec537d405f5327b86aee09bbdb0986dc136ff8f Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 9 Nov 2020 19:51:37 -0500 Subject: [PATCH] test: add resize test --- Dockerfile | 3 ++- test/aio/ipctest.py | 3 ++- test/aio/test_window.py | 28 ++++++++++++++++++++++++++++ test/ipctest.py | 15 +++++++++++++++ test/test_window.py | 17 +++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b26f380..279e55b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,4 +31,5 @@ RUN git clone https://github.com/i3/i3 && \ ADD . /app -CMD ["./run-tests.py"] +#CMD ["bash", "-c", "./run-tests.py ./test/aio/test_window.py"] +CMD ["bash", "-c", "./run-tests.py"] diff --git a/test/aio/ipctest.py b/test/aio/ipctest.py index 88e4cda..5dd649b 100644 --- a/test/aio/ipctest.py +++ b/test/aio/ipctest.py @@ -57,10 +57,11 @@ async def command_checked(self, cmd): result = await i3.command(cmd) assert type(result) is list + assert result for r in result: assert type(r) is CommandReply - assert r.success is True + assert r.success is True, r.error return result diff --git a/test/aio/test_window.py b/test/aio/test_window.py index 56cdc2e..c66ace3 100644 --- a/test/aio/test_window.py +++ b/test/aio/test_window.py @@ -72,3 +72,31 @@ async def test_marks(self, i3): await i3.command('mark foo') tree = await i3.get_tree() assert 'foo' in tree.find_focused().marks + + @pytest.mark.asyncio + async def test_resize(self, i3): + + ws1 = await self.fresh_workspace() + win = self.open_window() + await self.command_checked(f'[id="{win}"] floating enable') + + # XXX: uncomment and it will fail + # ws2 = await self.fresh_workspace() + + def height_width(c): + return c.rect.height + c.deco_rect.height, c.rect.width + + async def do_resize(h, w): + result = await self.command_checked(f'[id="{win}"] resize set {w}px {h}px') + + size1 = 200, 250 + size2 = 350, 300 + + await do_resize(*size1) + con = (await i3.get_tree()).find_by_window(win) + + await do_resize(*size2) + con2 = (await i3.get_tree()).find_by_window(win) + + assert height_width(con) == size1 + assert height_width(con2) == size2 diff --git a/test/ipctest.py b/test/ipctest.py index 20ef975..5ef17e2 100644 --- a/test/ipctest.py +++ b/test/ipctest.py @@ -1,6 +1,7 @@ from subprocess import Popen import pytest import i3ipc +from i3ipc import CommandReply import math from random import random import time @@ -58,3 +59,17 @@ def fresh_workspace(self): if not any(w for w in workspaces if w.name == new_name): i3.command('workspace %s' % new_name) return new_name + + def command_checked(self, cmd): + i3 = IpcTest.i3_conn + assert i3 + + result = i3.command(cmd) + + assert type(result) is list + + for r in result: + assert type(r) is CommandReply + assert r.success is True + + return result diff --git a/test/test_window.py b/test/test_window.py index 2e266e3..614d591 100644 --- a/test/test_window.py +++ b/test/test_window.py @@ -60,3 +60,20 @@ def on_window(i3, e): assert len(events) for e in events: assert e.change == 'focus' + + def test_resize(self, i3): + self.fresh_workspace() + self.open_window() + i3.command('floating enable') + + self.command_checked('resize set height 200 px; resize set width 250 px') + con = i3.get_tree().find_focused() + + self.command_checked('resize set width 300 px; resize set height 350 px') + con2 = i3.get_tree().find_focused() + + def height_width(c): + return (c.rect.height + c.deco_rect.height, c.rect.width) + + assert height_width(con) == (200, 250) + assert height_width(con2) == (350, 300)