Skip to content

Commit

Permalink
adapt test resize to work with changed ratio calc
Browse files Browse the repository at this point in the history
The changed ratio calculation changes the behaviour.
This commit modifies the "test_resizing" test.
A sequence of images that draws the window layout that
will be visible on the screen with the changed ratio calculation,
compared to the layout that is visible without it, is uploaded on github.
I extracted the data for the images with a modified version of this
test by writing the "layout_info" in a file
together with the expected "layout_info".

I made this test a bit more extensive than the original one.
  • Loading branch information
alexander-n8hgeg5e committed Dec 21, 2023
1 parent 1c07a15 commit 9bd4bdb
Showing 1 changed file with 111 additions and 7 deletions.
118 changes: 111 additions & 7 deletions test/layouts/test_ratiotile.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,39 @@ def test_resizing(manager):
def sizes():
return manager.c.layout.info()["layout_info"]

for i in range(5):
def ratio():
return manager.c.layout.info()["ratio"]

# pretend the user wants ratio 0.5
# in this layout it means very "tall" windows
# on a 800x600 screen
for i in range(4):
manager.test_window(str(i))
assert ratio() == 0.5
assert sizes() == [
(0, 0, 200, 600),
(200, 0, 200, 600),
(400, 0, 200, 600),
(600, 0, 200, 600),
]

# 5 windows are too much of "tall"
# the layout needs to switch
manager.test_window(str(i))
assert sizes() == [
(0, 0, 266, 300),
(266, 0, 266, 300),
(532, 0, 268, 300),
(0, 300, 400, 300),
(400, 300, 400, 300),
]

# the user really likes "tall"
# try to have all windows upright
manager.c.layout.decrease_ratio()
manager.c.layout.decrease_ratio()
# make sure the ratio is about 0.3
assert ratio() - 0.3 < 0.1
assert sizes() == [
(0, 0, 160, 600),
(160, 0, 160, 600),
Expand All @@ -397,7 +427,18 @@ def sizes():
(640, 0, 160, 600),
]

# the user got tired of tall windows
# and wants them all square
manager.c.layout.increase_ratio()
manager.c.layout.increase_ratio()
manager.c.layout.increase_ratio()
manager.c.layout.increase_ratio()
manager.c.layout.increase_ratio()
manager.c.layout.increase_ratio()
manager.c.layout.increase_ratio()
# make sure the ratio is about 1
assert ratio() - 1 < 0.1
# this is the most square it gets with 5 windows
assert sizes() == [
(0, 0, 266, 300),
(266, 0, 266, 300),
Expand All @@ -406,11 +447,74 @@ def sizes():
(400, 300, 400, 300),
]

manager.c.layout.decrease_ratio()
# from pprint import pformat as pf
# with open("/tmp/output","wt") as f:
# sizes_history = []
# changed_at = []
# sizes_history.append((ratio(),sizes()))
# def _print(f,data):
# # things 2print
# sizes2p = data[1]
# ratio2p = data[0]
# f.write(f"assert ratio() - {ratio2p:.1f} < 0.1\n")
# formated = pf(sizes2p).splitlines()
# formated[0] = "assert sizes() == " + formated[0]
# formated[1:]=[" "*18 + line for line in formated[1:]]
# formated[-1]+="\n\n"
# f.write("\n".join(formated))
# _print(f,(ratio(),sizes()))
# for i in range(50):
# manager.c.layout.increase_ratio()
# f.write('manager.c.layout.increase_ratio()\n')
# sizes_history.append((ratio(),sizes()))
# if sizes() != sizes_history[-2][1]:
# # something changed
# changed_at.append(i)
# _print(f,(ratio(),sizes()))
# f.write(pf(changed_at))

# now the user wants "landscape" windows
manager.c.layout.increase_ratio()
manager.c.layout.increase_ratio()
manager.c.layout.increase_ratio()
manager.c.layout.increase_ratio()
assert ratio() - 1.4 < 0.1
assert sizes() == [
(0, 0, 160, 600),
(160, 0, 160, 600),
(320, 0, 160, 600),
(480, 0, 160, 600),
(640, 0, 160, 600),
(0, 0, 400, 200),
(0, 200, 400, 200),
(0, 400, 400, 200),
(400, 0, 400, 300),
(400, 300, 400, 300),
]

# the user wants the windows all stacked
# vertically (5 windows with height=120)
# It needs to go up to ratio 3.7
for i in range(23):
manager.c.layout.increase_ratio()

# do it one more time to be tolerant
manager.c.layout.increase_ratio()
assert ratio() - 3.8 < 0.1
assert sizes() == [
(0, 0, 800, 120),
(0, 120, 800, 120),
(0, 240, 800, 120),
(0, 360, 800, 120),
(0, 480, 800, 120),
]

# just in case to be sure it can go back to normal
for i in range(23 + 1 + 4):
manager.c.layout.decrease_ratio()

# make sure the ratio is about 1
assert ratio() - 1 < 0.1
# this is the most square it gets with 5 windows
assert sizes() == [
(0, 0, 266, 300),
(266, 0, 266, 300),
(532, 0, 268, 300),
(0, 300, 400, 300),
(400, 300, 400, 300),
]

0 comments on commit 9bd4bdb

Please sign in to comment.