|
@@ -18,13 +18,17 @@ def assert_favicon_url_starts_with(screen: Screen, content: str):
|
|
assert icon_link['href'].startswith(content)
|
|
assert icon_link['href'].startswith(content)
|
|
|
|
|
|
|
|
|
|
-def assert_favicon(content: Union[Path, str], url_path: str = '/favicon.ico'):
|
|
|
|
|
|
+def assert_favicon(content: Union[Path, str, bytes], url_path: str = '/favicon.ico'):
|
|
response = requests.get(f'http://localhost:{PORT}{url_path}')
|
|
response = requests.get(f'http://localhost:{PORT}{url_path}')
|
|
assert response.status_code == 200
|
|
assert response.status_code == 200
|
|
if isinstance(content, Path):
|
|
if isinstance(content, Path):
|
|
assert content.read_bytes() == response.content
|
|
assert content.read_bytes() == response.content
|
|
- else:
|
|
|
|
|
|
+ elif isinstance(content, str):
|
|
assert content == response.text
|
|
assert content == response.text
|
|
|
|
+ elif isinstance(content, bytes):
|
|
|
|
+ assert content == response.content
|
|
|
|
+ else:
|
|
|
|
+ raise TypeError(f'Unexpected type: {type(content)}')
|
|
|
|
|
|
|
|
|
|
def test_default(screen: Screen):
|
|
def test_default(screen: Screen):
|
|
@@ -40,10 +44,20 @@ def test_emoji(screen: Screen):
|
|
screen.ui_run_kwargs['favicon'] = '👋'
|
|
screen.ui_run_kwargs['favicon'] = '👋'
|
|
screen.open('/')
|
|
screen.open('/')
|
|
assert_favicon_url_starts_with(screen, 'data:image/svg+xml')
|
|
assert_favicon_url_starts_with(screen, 'data:image/svg+xml')
|
|
- # the default favicon is still available (for example when accessing a plain FastAPI route with the browser)
|
|
|
|
assert_favicon(favicon.char_to_svg('👋'))
|
|
assert_favicon(favicon.char_to_svg('👋'))
|
|
|
|
|
|
|
|
|
|
|
|
+def test_data_url(screen: Screen):
|
|
|
|
+ ui.label('Hello, world')
|
|
|
|
+
|
|
|
|
+ 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')
|
|
|
|
+ _, bytes = favicon.data_url_to_bytes(icon)
|
|
|
|
+ assert_favicon(bytes)
|
|
|
|
+
|
|
|
|
+
|
|
def test_custom_file(screen: Screen):
|
|
def test_custom_file(screen: Screen):
|
|
ui.label('Hello, world')
|
|
ui.label('Hello, world')
|
|
|
|
|