Falko Schindler 2 lat temu
rodzic
commit
043a0a9cec
2 zmienionych plików z 10 dodań i 11 usunięć
  1. 7 8
      nicegui/helpers.py
  2. 3 3
      tests/test_helpers.py

+ 7 - 8
nicegui/helpers.py

@@ -55,17 +55,16 @@ def is_port_open(host: str, port: int) -> bool:
 def schedule_browser(host: str, port: int) -> Tuple[threading.Thread, threading.Event]:
     """Wait non-blockingly for the port to be open, then start a webbrowser.
 
-    This function launches a thread in order to be non-blocking. This thread then uses
-    `is_port_open` to check when the port opens. When connectivity is confirmed, the
-    webbrowser is launched using `webbrowser.open`
+    This function launches a thread in order to be non-blocking.
+    This thread then uses `is_port_open` to check when the port opens.
+    When connectivity is confirmed, the webbrowser is launched using `webbrowser.open`.
 
     The thread is created as a daemon thread, in order to not interfere with Ctrl+C.
 
-    If you need to stop this thread, you can do this by setting the Event, that gets
-    returned. The thread will stop with the next loop without opening the browser.
+    If you need to stop this thread, you can do this by setting the Event, that gets returned.
+    The thread will stop with the next loop without opening the browser.
 
-    :return: A tuple consisting of the actual thread object and an event for stopping
-        the thread.
+    :return: A tuple consisting of the actual thread object and an event for stopping the thread.
     """
     cancel = threading.Event()
 
@@ -76,7 +75,7 @@ def schedule_browser(host: str, port: int) -> Tuple[threading.Thread, threading.
             time.sleep(0.1)
         webbrowser.open(f'http://{host}:{port}/')
 
-    host = host if host != "0.0.0.0" else "127.0.0.1"
+    host = host if host != '0.0.0.0' else '127.0.0.1'
     thread = threading.Thread(target=in_thread, args=(host, port), daemon=True)
     thread.start()
     return thread, cancel

+ 3 - 3
tests/test_helpers.py

@@ -29,7 +29,7 @@ def test_schedule_browser(monkeypatch):
         nonlocal called_with_url
         called_with_url = url
 
-    monkeypatch.setattr(webbrowser, "open", mock_webbrowser_open)
+    monkeypatch.setattr(webbrowser, 'open', mock_webbrowser_open)
 
     with contextlib.closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
 
@@ -45,7 +45,7 @@ def test_schedule_browser(monkeypatch):
             sock.listen()
             # port opened
             time.sleep(1)
-            assert called_with_url == f"http://{host}:{port}/"
+            assert called_with_url == f'http://{host}:{port}/'
         finally:
             cancel_event.set()
 
@@ -58,7 +58,7 @@ def test_canceling_schedule_browser(monkeypatch):
         nonlocal called_with_url
         called_with_url = url
 
-    monkeypatch.setattr(webbrowser, "open", mock_webbrowser_open)
+    monkeypatch.setattr(webbrowser, 'open', mock_webbrowser_open)
 
     # find a free port ...
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)