Skip to content

Commit

Permalink
try to fix flaky interactive_image tests (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Apr 4, 2024
1 parent ed16463 commit a2ab6d8
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions tests/test_interactive_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,26 @@ async def page(client: Client):
with ui.tab_panel('B'):
ui.label('Tab B')
await client.connected()
img.set_source('https://nicegui.io/logo.png')
img.set_source('https://picsum.photos/id/29/640/360')

screen.open('/')
screen.wait(0.5)
assert screen.find_by_tag('img').get_attribute('src') == 'https://nicegui.io/logo.png'
assert screen.find_by_tag('img').get_attribute('src') == 'https://picsum.photos/id/29/640/360'
screen.click('B')
screen.wait(0.5)
screen.click('A')
assert screen.find_by_tag('img').get_attribute('src') == 'https://nicegui.io/logo.png'
assert screen.find_by_tag('img').get_attribute('src') == 'https://picsum.photos/id/29/640/360'


@pytest.mark.parametrize('cross, number_of_lines', [(True, 2), (False, 0)])
def test_with_cross(screen: Screen, cross: bool, number_of_lines: int):
ii = ui.interactive_image('https://nicegui.io/logo.png', cross=cross)
ii.content = '<circle cx="100" cy="100" r="15" fill="none" stroke="red" stroke-width="4" />'
@pytest.mark.parametrize('cross', [True, False])
def test_with_cross(screen: Screen, cross: bool):
ui.interactive_image('https://picsum.photos/id/29/640/360',
content='<circle cx="100" cy="100" r="15" />', cross=cross)

screen.open('/')
screen.wait(0.5)
screen.find_by_tag('svg')
with screen.implicitly_wait(0.5):
assert len(screen.find_all_by_tag('line')) == number_of_lines
assert len(screen.find_all_by_tag('line')) == (2 if cross else 0)
assert len(screen.find_all_by_tag('circle')) == 1


Expand All @@ -56,11 +55,10 @@ def replace():
ui.button('Replace', on_click=replace)

screen.open('/')
screen.wait(0.5)
assert screen.find_by_tag('img').get_attribute('src').endswith('id/29/640/360')
assert (screen.find_by_tag('img').get_attribute('src') or '').endswith('id/29/640/360')
screen.click('Replace')
screen.wait(0.5)
assert screen.find_by_tag('img').get_attribute('src').endswith('id/30/640/360')
assert (screen.find_by_tag('img').get_attribute('src') or '').endswith('id/30/640/360')


@pytest.mark.parametrize('cross', [True, False])
Expand Down

0 comments on commit a2ab6d8

Please sign in to comment.