Browse Source

pytest: implemented remove_prefix for python 3.8 and lower

Rodja Trappe 2 năm trước cách đây
mục cha
commit
9c7290f637
2 tập tin đã thay đổi với 8 bổ sung2 xóa
  1. 4 0
      tests/helper.py
  2. 4 2
      tests/screen.py

+ 4 - 0
tests/helper.py

@@ -0,0 +1,4 @@
+def remove_prefix(text: str, prefix: str):
+    if prefix and text.startswith(prefix):
+        return text[len(prefix):]
+    return text

+ 4 - 2
tests/screen.py

@@ -10,6 +10,8 @@ from selenium.common.exceptions import NoSuchElementException
 from selenium.webdriver.common.by import By
 from selenium.webdriver.remote.webelement import WebElement
 
+from .helper import remove_prefix
+
 PORT = 3392
 IGNORED_CLASSES = ['row', 'column', 'q-card', 'q-field', 'q-field__label', 'q-input']
 
@@ -81,13 +83,13 @@ class Screen():
             classes = child.get('class', '')
             if classes:
                 if classes[0] in ['row', 'column', 'q-card']:
-                    content += depth + classes[0].removeprefix('q-')
+                    content += depth + remove_prefix(classes[0], 'q-')
                     is_element = True
                 if classes[0] == 'q-field':
                     pass
                 [classes.remove(c) for c in IGNORED_CLASSES if c in classes]
                 for i, c in enumerate(classes):
-                    classes[i] = c.removeprefix('q-field--')
+                    classes[i] = remove_prefix(c, 'q-field--')
                 if is_element and with_extras:
                     content += f' [class: {" ".join(classes)}]'