Skip to content

Commit

Permalink
fix favicon tests after removing bs4
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Jul 16, 2024
1 parent e9dfc84 commit 8c84ad4
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions tests/test_favicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest
import requests
from bs4 import BeautifulSoup

from nicegui import favicon, ui
from nicegui.testing import Screen
Expand All @@ -12,10 +11,8 @@
LOGO_FAVICON_PATH = Path(__file__).parent.parent / 'website' / 'static' / 'logo_square.png'


def assert_favicon_url_starts_with(screen: Screen, content: str):
soup = BeautifulSoup(screen.selenium.page_source, 'html.parser')
icon_link = soup.find('link', rel='icon')
assert icon_link['href'].startswith(content)
def get_favicon_url(screen: Screen) -> str:
return screen.find_by_css('link[rel="shortcut icon"]').get_attribute('href')


def assert_favicon(content: Union[Path, str, bytes], url_path: str = '/favicon.ico'):
Expand Down Expand Up @@ -44,7 +41,7 @@ def test_emoji(emoji: str, screen: Screen):

screen.ui_run_kwargs['favicon'] = emoji
screen.open('/')
assert_favicon_url_starts_with(screen, 'data:image/svg+xml')
assert get_favicon_url(screen).startswith('data:image/svg+xml')
assert_favicon(favicon._char_to_svg(emoji))


Expand All @@ -54,7 +51,7 @@ def test_data_url(screen: Screen):
icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
screen.ui_run_kwargs['favicon'] = icon
screen.open('/')
assert_favicon_url_starts_with(screen, 'data:image/png;base64')
assert get_favicon_url(screen).startswith('data:image/png;base64')
_, bytes_ = favicon._data_url_to_bytes(icon)
assert_favicon(bytes_)

Expand All @@ -64,7 +61,7 @@ def test_custom_file(screen: Screen):

screen.ui_run_kwargs['favicon'] = LOGO_FAVICON_PATH
screen.open('/')
assert_favicon_url_starts_with(screen, '/favicon.ico')
assert get_favicon_url(screen).endswith('/favicon.ico')
assert_favicon(screen.ui_run_kwargs['favicon'])


Expand All @@ -88,6 +85,6 @@ def sub():
ui.label('Main')

screen.open('/subpage')
assert_favicon_url_starts_with(screen, 'data:image/svg+xml')
assert get_favicon_url(screen).startswith('data:image/svg+xml')
screen.open('/')
assert_favicon(DEFAULT_FAVICON_PATH)

0 comments on commit 8c84ad4

Please sign in to comment.