Skip to content

Commit

Permalink
Adapt tests for updated dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
kbengs committed Sep 3, 2023
1 parent 893ff03 commit e9238aa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
1 change: 1 addition & 0 deletions pdfarranger/pdfarranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ def retitle(self):
return False

def update_thumbnail(self, _obj, ref, thumbnail, zoom, scale, is_preview):
print('update_thumbnail')
"""Update thumbnail emitted from rendering thread."""
if ref is None:
# Rendering ended
Expand Down
30 changes: 22 additions & 8 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,18 @@ def _assert_selected(self, selection):

def _assert_page_size(self, width, height, pageid=None):
if pageid is not None:
viewport = self._app().child(roleName="layered pane")
viewport.grabFocus()

for icon in self._icons(): # NEW
time.sleep(2)
icon.click()
time.sleep(2)
print('statusbar text: ',self._status_text()) # END NEW

self._wait_cond(lambda: viewport.sensitive)
self._icons()[pageid].click()
print(self._status_text()) # NEW
self._wait_cond(lambda: self._status_text().startswith(f"Selected pages: {pageid+1}"))
label = " {:.1f}mm \u00D7 {:.1f}mm".format(width, height)
self.assertTrue(self._status_text().endswith("Page Size:" + label))
Expand Down Expand Up @@ -326,7 +337,7 @@ def _save_as_chooser(self, filebasename, expected=None):

def _scale_selected(self, scale):
app = self._app()
app.keyCombo("C")
app.keyCombo("S")
dialog = app.child(roleName="dialog")
from dogtail import rawinput
rawinput.keyCombo("Tab")
Expand Down Expand Up @@ -430,19 +441,18 @@ def test_05_duplicate(self):
app.keyCombo("Up")
self._assert_selected("2")

def test_06_page_format(self):
def test_06_crop_margins(self):
self._popupmenu(0, ["Select", "Select Odd Pages"])
self._assert_selected("1, 3, 5, 7")
self._popupmenu(0, "Page Format…")
self._popupmenu(0, "Crop Margins…")
dialog = self._app().child(roleName="dialog")
dialog.child(name="Show values").click()
time.sleep(0.2) # Avoid 'GTK_IS_RANGE (range)' failed
croppanel = dialog.child(name="Crop Margins")
cropbuttons = self._find_by_role("spin button", croppanel)
for i in range(4):
cropbuttons[i].click()
cropbuttons[i].text = str((i+1)*4)
scalebutton = dialog.child(roleName="spin button")
scalebutton.click()
scalebutton.text = "120"
dialog.child(name="OK").click()
# TODO: find the condition which could replace this ugly sleep
time.sleep(0.5)
Expand Down Expand Up @@ -511,6 +521,8 @@ def test_04_past_overlay(self):
app.keyCombo("Right")
app.keyCombo("<shift><ctrl>o")
dialog = self._app().child(roleName="dialog")
dialog.child(name="Show values").click()
time.sleep(0.2) # Avoid 'GTK_IS_RANGE (range)' failed
spinbtns = self._find_by_role("spin button", dialog)
spinbtns[0].click()
spinbtns[0].text = "10"
Expand Down Expand Up @@ -656,8 +668,10 @@ def test_03_booklet(self):
self._popupmenu(0, ["Select", "Select All"])
self._popupmenu(0, ["Generate Booklet"])
self._wait_cond(lambda: len(self._icons()) == 2)
self._assert_page_size(489, 212.2, 0)
self._assert_page_size(489, 212.2, 1)
self._app().keyCombo("Home")
self._assert_page_size(489, 212.2)
self._app().keyCombo("End")
self._assert_page_size(489, 212.2)

def test_04_crop_white_border(self):
# Test selection with shift+arrow
Expand Down
20 changes: 10 additions & 10 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ def _lpage1_270() -> core.LayerPage:

def _page1(self) -> core.Page:
"""Sample page 1"""
return core.Page(1, 2, 0.55, 'copy', 0, 2, core.Sides(0.1, 0.2, 0.3, 0.4), core.Dims(100.33, 200.66), 'base',
[self._lpage1()])
return core.Page(1, 2, 0.55, 'copy', 0, 2, core.Sides(0.1, 0.2, 0.3, 0.4),
core.Sides(0.11, 0.21, 0.31, 0.41), core.Dims(100.33, 200.66), 'base', [self._lpage1()])

def _page1_90(self) -> core.Page:
"""Sample page 1 rotated 90 degrees"""
return core.Page(1, 2, 0.55, 'copy', 90, 2, core.Sides(0.4, 0.3, 0.1, 0.2), core.Dims(100.33, 200.66), 'base',
[self._lpage1_90()])
return core.Page(1, 2, 0.55, 'copy', 90, 2, core.Sides(0.4, 0.3, 0.1, 0.2),
core.Sides(0.41, 0.31, 0.11, 0.21), core.Dims(100.33, 200.66), 'base', [self._lpage1_90()])

def _page1_180(self) -> core.Page:
"""Sample page 1 rotated 90 degrees"""
return core.Page(1, 2, 0.55, 'copy', 180, 2, core.Sides(0.2, 0.1, 0.4, 0.3), core.Dims(100.33, 200.66), 'base',
[self._lpage1_180()])
return core.Page(1, 2, 0.55, 'copy', 180, 2, core.Sides(0.2, 0.1, 0.4, 0.3),
core.Sides(0.21, 0.11, 0.41, 0.31), core.Dims(100.33, 200.66), 'base', [self._lpage1_180()])

def _page1_270(self) -> core.Page:
"""Sample page 1 rotated 90 degrees"""
return core.Page(1, 2, 0.55, 'copy', 270, 2, core.Sides(0.3, 0.4, 0.2, 0.1), core.Dims(100.33, 200.66), 'base',
[self._lpage1_270()])
return core.Page(1, 2, 0.55, 'copy', 270, 2, core.Sides(0.3, 0.4, 0.2, 0.1),
core.Sides(0.31, 0.41, 0.21, 0.11), core.Dims(100.33, 200.66), 'base', [self._lpage1_270()])


class BasePageTest(PTest):
Expand Down Expand Up @@ -109,8 +109,8 @@ def test02(self):
def test03(self):
"""Test serialize"""
self.assertEqual(self._page1().serialize(),
'copy\n2\nbase\n0\n2\n0.1\n0.2\n0.3\n0.4\nlcopy\n4\n90\n2\nOVERLAY\n0.11\n0.21\n0.31\n0.41\n'
'0.12\n0.22\n0.32\n0.42')
'copy\n2\nbase\n0\n2\n0.1\n0.2\n0.3\n0.4\n0.11\n0.21\n0.31\n0.41\n'
'lcopy\n4\n90\n2\nOVERLAY\n0.11\n0.21\n0.31\n0.41\n0.12\n0.22\n0.32\n0.42')

def test04(self):
"""Test width | height | size_in_pixel"""
Expand Down

0 comments on commit e9238aa

Please sign in to comment.