Skip to content

Commit

Permalink
add pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Oct 25, 2024
1 parent be2aaa2 commit ab29e99
Showing 1 changed file with 42 additions and 21 deletions.
63 changes: 42 additions & 21 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
from nicegui.testing import Screen

example_file = Path(__file__).parent / '../examples/slideshow/slides/slide1.jpg'
example_data = ('data:image/png;base64,'
'iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABmJLR0QA/wD/AP+gvaeTAAAEHElEQVRo'
'ge2ZXUxbZRjHf6enH3QtBQ7paIFlMO2AMXTGqZE40bCpiRdzF06Nsu3O6G68MH5MnYkk3vhx4cWCJppF'
'lvgZ74wXbsZdLCYaQMeWUWM30EJZgVM+WtpS2uNFoQzTU3pKu2O0v8v38//Pe57ned8cKFOmTBk9EVR7'
'vrxsRlJ6gR7AfdMUrWcC6EcWTnK4fSnbAKPqVEl5C3ipRMLypR54GUkBeCXbAEOOyUdKoahAjqp15DKg'
'12eTDZdaRy4DN43p+1s55HTwVF0Vk/taNM3V3UCDxUStSWQ4HKPDXsFwOK5pvm4GTILADquZbslGPKUA'
'sNdRwXg8wQ6rOe911NPo2UvKplXmYOcWM957Par9wrnL6xv2786qVbcT8EUTSOdH+Co4T//kLE0Xfgfg'
'wcFRpPMjea+jm4GkohBaTuKxmhlaiNFoMZFS4Jf5KKHlZN7rqBeyEvPF7kYO11UBsKdyLUuGH2jjNV+Q'
't0en8lpHtxN41RfkyUt+APYPjfJNcJ7v5TB7f77KJxOhvNfRzcDVaPpqM51Ick6O4DQbuTC7yMBClMml'
'5bzX0bUOdNgtXAzHAGi3WRiOaKsBoGMa1cy/LY0Wi7IBvfl/GhCAJ+qq+HbPdgL7Whi8+5YN59zjsOLr'
'9ODr9PB6s7OQbbOiuRI7jAa+7tjGAcmeaQtukLdNgsBHbfWZW2atSdS6rSqaDAjAp7saOSDZSSoKpwOz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1kN41gqe38haPqE4imF7sFR3hmb'
'ZiyWIKEo+KJL9F6b4tFfx1jeINMMLcQYWIjijyU2JfpG/tMvsokSSSkAYVytJ5eB/hIoKQxBUdWiHsSy'
'cHLlz0gP6T8lepD+xTQjvKnT/mXKlCmzAX8Dl7JCqRHaepQAAAAASUVORK5CYII=')
ui.image(data).style('width: 50px;')
ui.image(example_data).style('width: 50px;')

screen.open('/')
screen.wait(0.2)
Expand Down Expand Up @@ -75,3 +75,24 @@ def test_removal_of_generated_routes(screen: Screen):
screen.click('Slide 3')
screen.wait(0.5)
assert len(app.routes) == number_of_routes


def test_force_reload(screen: Screen):
img1 = ui.image(example_file)
img2 = ui.image(example_data)

ui.button('Reload 1', on_click=img1.force_reload)
ui.button('Reload 2', on_click=img2.force_reload)

screen.open('/')
images = screen.find_all_by_class('q-img__image')
screen.should_load_image(images[0])
screen.should_load_image(images[1])

screen.click('Reload 1')
screen.wait(0.5)
assert not screen.caplog.records

screen.click('Reload 2')
screen.wait(0.5)
screen.assert_py_logger('WARNING', 'ui.image: force_reload() only works with network sources (not base64)')

0 comments on commit ab29e99

Please sign in to comment.