Răsfoiți Sursa

fix some first issues with pytests

Falko Schindler 2 ani în urmă
părinte
comite
da14684156
4 a modificat fișierele cu 23 adăugiri și 19 ștergeri
  1. 18 14
      nicegui/element.py
  2. 0 1
      tests/test_auto_context.py
  3. 3 2
      tests/test_element.py
  4. 2 2
      tests/test_pages.py

+ 18 - 14
nicegui/element.py

@@ -72,24 +72,35 @@ class Element(ABC, Visibility):
             self.update()
         return self
 
+    @staticmethod
+    def parse_style(text: Optional[str]) -> Dict[str, str]:
+        return dict((word.strip() for word in part.split(':')) for part in text.strip('; ').split(';')) if text else {}
+
     def style(self, add: Optional[str] = None, *, remove: Optional[str] = None, replace: Optional[str] = None):
         '''CSS style sheet definitions to modify the look of the element.
         Every style in the `remove` parameter will be removed from the element.
         Styles are separated with a semicolon.
         This can be helpful if the predefined style sheet definitions by NiceGUI are not wanted in a particular styling.
         '''
-        def parse_style(text: Optional[str]) -> Dict[str, str]:
-            return dict((word.strip() for word in part.split(':')) for part in text.strip('; ').split(';')) if text else {}
         style_dict = deepcopy(self._style) if replace is None else {}
-        for key in parse_style(remove):
+        for key in self._parse_style(remove):
             del style_dict[key]
-        style_dict.update(parse_style(add))
-        style_dict.update(parse_style(replace))
+        style_dict.update(self._parse_style(add))
+        style_dict.update(self._parse_style(replace))
         if self._style != style_dict:
             self._style = style_dict
             self.update()
         return self
 
+    @staticmethod
+    def _parse_props(text: Optional[str]) -> Dict[str, str]:
+        if not text:
+            return {}
+        lexer = shlex.shlex(text, posix=True)
+        lexer.whitespace = ' '
+        lexer.wordchars += '=-.%'
+        return dict(word.split('=', 1) if '=' in word else (word, True) for word in lexer)
+
     def props(self, add: Optional[str] = None, *, remove: Optional[str] = None):
         '''Quasar props https://quasar.dev/vue-components/button#design to modify the look of the element.
         Boolean props will automatically activated if they appear in the list of the `add` property.
@@ -97,19 +108,12 @@ class Element(ABC, Visibility):
         Every prop passed to the `remove` parameter will be removed from the element.
         This can be helpful if the predefined props by NiceGUI are not wanted in a particular styling.
         '''
-        def parse_props(text: Optional[str]) -> Dict[str, str]:
-            if not text:
-                return {}
-            lexer = shlex.shlex(text, posix=True)
-            lexer.whitespace = ' '
-            lexer.wordchars += '=-.%'
-            return dict(word.split('=', 1) if '=' in word else (word, True) for word in lexer)
         needs_update = False
-        for key in parse_props(remove):
+        for key in self._parse_props(remove):
             if key in self._props:
                 needs_update = True
                 del self._props[key]
-        for key, value in parse_props(add).items():
+        for key, value in self._parse_props(add).items():
             if self._props.get(key) != value:
                 needs_update = True
                 self._props[key] = value

+ 0 - 1
tests/test_auto_context.py

@@ -2,7 +2,6 @@ import asyncio
 from typing import Generator
 
 from nicegui import ui
-from nicegui.events import PageEvent
 from nicegui.task_logger import create_task
 
 from .screen import Screen

+ 3 - 2
tests/test_element.py

@@ -1,8 +1,9 @@
-from nicegui import ui
-from nicegui.elements.element import Element
 from selenium.webdriver.common.action_chains import ActionChains
 from selenium.webdriver.common.by import By
 
+from nicegui import ui
+from nicegui.element import Element
+
 from .screen import Screen
 
 

+ 2 - 2
tests/test_pages.py

@@ -4,10 +4,10 @@ from typing import Generator
 from uuid import uuid4
 
 import justpy.htmlcomponents
-from nicegui import task_logger, ui
-from nicegui.events import PageEvent
 from starlette.requests import Request
 
+from nicegui import task_logger, ui
+
 from .screen import Screen