Răsfoiți Sursa

code review

Falko Schindler 1 an în urmă
părinte
comite
7099eb200b
4 a modificat fișierele cu 9 adăugiri și 7 ștergeri
  1. 3 3
      nicegui/functions/download.py
  2. 3 1
      tests/conftest.py
  3. 3 2
      tests/test_download.py
  4. 0 1
      tests/test_helpers.py

+ 3 - 3
nicegui/functions/download.py

@@ -1,7 +1,7 @@
 from pathlib import Path
 from pathlib import Path
 from typing import Optional, Union
 from typing import Optional, Union
 
 
-from .. import globals
+from .. import globals, helpers
 
 
 
 
 def download(src: Union[str, Path], filename: Optional[str] = None) -> None:
 def download(src: Union[str, Path], filename: Optional[str] = None) -> None:
@@ -9,9 +9,9 @@ def download(src: Union[str, Path], filename: Optional[str] = None) -> None:
 
 
     Function to trigger the download of a file.
     Function to trigger the download of a file.
 
 
-    :param src: target URL or local filename which should be downloaded
+    :param src: target URL or local path of the file which should be downloaded
     :param filename: name of the file to download (default: name of the file on the server)
     :param filename: name of the file to download (default: name of the file on the server)
     """
     """
-    if Path(src).is_file():
+    if helpers.is_file(src):
         src = globals.app.add_static_file(local_file=src)
         src = globals.app.add_static_file(local_file=src)
     globals.get_client().download(src, filename)
     globals.get_client().download(src, filename)

+ 3 - 1
tests/conftest.py

@@ -1,6 +1,7 @@
 import importlib
 import importlib
 import os
 import os
 import shutil
 import shutil
+from pathlib import Path
 from typing import Dict, Generator
 from typing import Dict, Generator
 
 
 import icecream
 import icecream
@@ -11,10 +12,11 @@ from webdriver_manager.chrome import ChromeDriverManager
 
 
 from nicegui import Client, globals
 from nicegui import Client, globals
 from nicegui.page import page
 from nicegui.page import page
-from .test_helpers import DOWNLOAD_DIR
 
 
 from .screen import Screen
 from .screen import Screen
 
 
+DOWNLOAD_DIR = Path(__file__).parent / 'download'
+
 icecream.install()
 icecream.install()
 
 
 
 

+ 3 - 2
tests/test_download.py

@@ -1,12 +1,13 @@
 from pathlib import Path
 from pathlib import Path
+
 from fastapi.responses import PlainTextResponse
 from fastapi.responses import PlainTextResponse
 
 
 from nicegui import app, ui
 from nicegui import app, ui
 
 
+from .conftest import DOWNLOAD_DIR
 from .screen import Screen
 from .screen import Screen
-from .test_helpers import TEST_DIR, DOWNLOAD_DIR
 
 
-IMAGE_FILE = Path(TEST_DIR).parent / 'examples' / 'slideshow' / 'slides' / 'slide1.jpg'
+IMAGE_FILE = Path(__file__).parent.parent / 'examples' / 'slideshow' / 'slides' / 'slide1.jpg'
 
 
 
 
 def test_download_text_file(screen: Screen):
 def test_download_text_file(screen: Screen):

+ 0 - 1
tests/test_helpers.py

@@ -7,7 +7,6 @@ from pathlib import Path
 from nicegui import helpers
 from nicegui import helpers
 
 
 TEST_DIR = Path(__file__).parent
 TEST_DIR = Path(__file__).parent
-DOWNLOAD_DIR = TEST_DIR / 'download'
 
 
 
 
 def test_is_port_open():
 def test_is_port_open():