Forráskód Böngészése

testing moving sphere in 3d scene (and fixing auto-context)

Rodja Trappe 2 éve
szülő
commit
ca2820666f
3 módosított fájl, 21 hozzáadás és 1 törlés
  1. 3 0
      nicegui/elements/scene.py
  2. 1 1
      tests/conftest.py
  3. 17 0
      tests/test_3d_scene.py

+ 3 - 0
nicegui/elements/scene.py

@@ -76,6 +76,9 @@ class SceneView(CustomView):
             pass
         return True
 
+    def __len__(self):
+        return len(self.objects)
+
 
 class Scene(Element):
     from .scene_objects import Box as box

+ 1 - 1
tests/conftest.py

@@ -19,7 +19,7 @@ icecream.install()
 def chrome_options(chrome_options: webdriver.ChromeOptions) -> webdriver.ChromeOptions:
     chrome_options.add_argument('headless')
     chrome_options.add_argument('disable-gpu')
-    chrome_options.add_argument('window-size=1200x600')
+    chrome_options.add_argument('window-size=600x600')
     chrome_options.add_experimental_option('w3c', False)
     return chrome_options
 

+ 17 - 0
tests/test_3d_scene.py

@@ -0,0 +1,17 @@
+
+from nicegui import ui
+
+from .user import User
+
+
+def test_moving_sphere_with_timer(user: User):
+    with ui.scene() as scene:
+        sphere = scene.sphere().move(0, -5, 2)
+        ui.timer(0.03, lambda: sphere.move(sphere.x, sphere.y + 0.05, sphere.z))
+
+    user.open('/')
+    user.sleep(0.1)
+    def position(): return user.selenium.execute_script('return scene.children[4].position.y')
+    pos = position()
+    user.sleep(0.1)
+    assert position() > pos