rmm commited on
Commit
64361a0
·
1 Parent(s): cfbfcc8

test: make the visual test standalone (launch its own app instance)

Browse files
tests/visual_selenium/test_visual_main.py CHANGED
@@ -1,11 +1,14 @@
1
  from pathlib import Path
2
  import time
 
 
3
  import pytest
4
  from seleniumbase import BaseCase
5
  from selenium.webdriver.common.by import By
6
  from selenium.webdriver.support.ui import WebDriverWait
7
  from selenium.webdriver.support import expected_conditions as EC
8
 
 
9
  BaseCase.main(__name__, __file__)
10
 
11
  # Set the paths to the images and csv file
@@ -24,6 +27,43 @@ mk_visible = """
24
  input.style.visibility = 'visible';
25
  """
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  def wait_for_element(self, by, selector, timeout=10):
28
  # example usage:
29
  # element = self.wait_for_element(By.XPATH, "//p[contains(text(), 'Species for observation')]")
@@ -215,8 +255,11 @@ class RecorderTest(BaseCase):
215
  self.click(".st-key-button_infer_ceteans button")
216
 
217
  # check the state has advanced
 
 
218
  self.assert_exact_text("Progress: 3/5. Current: ml_classification_completed.",
219
- 'div[data-testid="stMarkdownContainer"] p em')
 
220
 
221
  # on the inference tab, check the columns and images are rendered correctly
222
  # - normally it is selected by default, but we can switch to it to be sure
 
1
  from pathlib import Path
2
  import time
3
+ from contextlib import contextmanager
4
+
5
  import pytest
6
  from seleniumbase import BaseCase
7
  from selenium.webdriver.common.by import By
8
  from selenium.webdriver.support.ui import WebDriverWait
9
  from selenium.webdriver.support import expected_conditions as EC
10
 
11
+
12
  BaseCase.main(__name__, __file__)
13
 
14
  # Set the paths to the images and csv file
 
27
  input.style.visibility = 'visible';
28
  """
29
 
30
+ PORT = "8501"
31
+
32
+ # - _before_module and run_streamlit taken from
33
+ # https://github.com/randyzwitch/streamlit-folium/blob/master/tests/test_frontend.py
34
+ # example given via streamlit blog
35
+ # - note: to use pytest fixtures x unittest we have to use autouse=True.
36
+ @pytest.fixture(scope="module", autouse=True)
37
+ def _before_module():
38
+ # Run the streamlit app before each module
39
+ with run_streamlit():
40
+ yield
41
+
42
+ @contextmanager
43
+ def run_streamlit():
44
+ """Run the streamlit app at src/main.py on port PORT"""
45
+
46
+ import subprocess
47
+
48
+ p = subprocess.Popen(
49
+ [
50
+ "streamlit",
51
+ "run",
52
+ "src/main.py",
53
+ "--server.port",
54
+ PORT,
55
+ "--server.headless",
56
+ "true",
57
+ ]
58
+ )
59
+
60
+ time.sleep(5)
61
+
62
+ try:
63
+ yield 1
64
+ finally:
65
+ p.kill()
66
+
67
  def wait_for_element(self, by, selector, timeout=10):
68
  # example usage:
69
  # element = self.wait_for_element(By.XPATH, "//p[contains(text(), 'Species for observation')]")
 
255
  self.click(".st-key-button_infer_ceteans button")
256
 
257
  # check the state has advanced
258
+ # NOTE: FOR REMOTE RUN, IT IS STARTING FROM ZERO, SO IT HAS TO DOWNLOAD
259
+ # ALL MODEL FILES -> 60s timeout for this one step
260
  self.assert_exact_text("Progress: 3/5. Current: ml_classification_completed.",
261
+ 'div[data-testid="stMarkdownContainer"] p em',
262
+ timeout=60)
263
 
264
  # on the inference tab, check the columns and images are rendered correctly
265
  # - normally it is selected by default, but we can switch to it to be sure