Skip to content

Commit

Permalink
test: add resize test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Crisci committed Nov 10, 2020
1 parent abd242b commit 0ec537d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
3 changes: 2 additions & 1 deletion test/aio/ipctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions test/aio/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions test/ipctest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from subprocess import Popen
import pytest
import i3ipc
from i3ipc import CommandReply
import math
from random import random
import time
Expand Down Expand Up @@ -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
17 changes: 17 additions & 0 deletions test/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 0ec537d

Please sign in to comment.