Skip to content

Commit dcd4003

Browse files
committed
fix: support Verbum/beta
1 parent ca92aa7 commit dcd4003

File tree

1 file changed

+67
-24
lines changed

1 file changed

+67
-24
lines changed

tests/integration.py

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import abc
88
import os
99
from pathlib import Path
10+
import tempfile
1011
import psutil
1112
import shutil
1213
import subprocess
13-
import tempfile
1414
import threading
1515
import time
1616
from typing import Callable, Optional, Union
@@ -94,7 +94,7 @@ def isolate_files(self):
9494
if self._temp_dir is not None:
9595
shutil.rmtree(self._temp_dir)
9696
# FIXME: this isn't properly cleaned up when tests fail. Context manager?
97-
self._temp_dir = tempfile.mkdtemp()
97+
self._temp_dir = tempfile.mkdtemp(prefix="oudedetai_test_")
9898
self.config = Path(self._temp_dir) / "config.json"
9999
self.install_dir = Path(self._temp_dir) / "install_dir"
100100

@@ -145,6 +145,8 @@ def run(self, *args, **kwargs):
145145
env["PATH"] = os.environ.get("PATH", "")
146146
env["HOME"] = os.environ.get("HOME", "")
147147
env["DISPLAY"] = os.environ.get("DISPLAY", "")
148+
env["logos_release_channel"] = os.environ.get("logos_release_channel", "stable")
149+
env["FLPRODUCT"] = os.environ.get("FLPRODUCT", "Logos")
148150
kwargs["env"] = env
149151
log_level = ""
150152
if self.log_level == "debug":
@@ -175,14 +177,14 @@ def uninstall(self):
175177
# Open an issue for this.
176178
self.run(["--uninstall", "-y"])
177179

178-
def start_app(self) -> "Logos":
180+
def start_app(self) -> "FaithLifeProduct":
179181
# Start a thread, as this command doesn't exit
180182
threading.Thread(target=self.run, args=[["--run-installed-app"]]).start()
181183
# There is only one thing we need to check generally for logos.
182184
# Consider making display_server a paramater in the future if
183185
# this needs to be something else.
184186
display_server = DisplayServer.detect(raise_if_winedbg_is_running)
185-
logos = Logos(self, display_server)
187+
logos = FaithLifeProduct(self, display_server)
186188
# Now wait for the window to open before returning the open window.
187189
wait_for_true(logos.is_window_open)
188190
display_server.window_name = logos.window_name()
@@ -191,17 +193,16 @@ def start_app(self) -> "Logos":
191193
return logos
192194

193195
def stop_app(self):
196+
# FIXME: this didn't close Verbum (well it does after a click)
194197
self.run(["--stop-installed-app"])
195198
# FIXME: wait for close?
196199

197200

198201
# FIXME: test this against Verbum too. It should be the same.
199202
# If not, make this an abstract class w/overrides.
200203

201-
class Logos:
202-
"""Class for interacting with Logos
203-
204-
May also work for Verbum, tested against Logos"""
204+
class FaithLifeProduct:
205+
"""Class for interacting with Logos/Verbum"""
205206
_ou_dedetai: OuDedetai
206207
_display_server: "DisplayServer"
207208

@@ -288,9 +289,39 @@ def is_crashed(self) -> bool:
288289
return False
289290

290291
@classmethod
291-
def window_name(_cls):
292-
# FIXME: This will need to be overridden for Verbum
293-
return "Logos Bible Study"
292+
def name(cls) -> str:
293+
"""Returns the target faithlife product
294+
295+
reads FLPRODUCT
296+
297+
returns: Verbum or Logos"""
298+
faithlife_product = os.environ.get("FLPRODUCT", "Logos")
299+
if faithlife_product not in ["Logos", "Verbum"]:
300+
raise ValueError(f"Unknown Faithlife product: {faithlife_product}")
301+
return faithlife_product
302+
303+
@classmethod
304+
def window_name(cls):
305+
faithlife_product = cls.name()
306+
if faithlife_product == "Logos":
307+
return "Logos Bible Study"
308+
elif faithlife_product == "Verbum":
309+
return "Verbum"
310+
311+
@property
312+
def appdata_dir(self) -> str:
313+
"""Returns the appdata dir of the install product
314+
315+
raises a FileNotFoundError if it cannot be found"""
316+
assert self._ou_dedetai.install_dir, "The test must start in isolated mode so we know where the install dir is reliably" #noqa: E501
317+
appdata_dir = None
318+
glob = f"data/wine64_bottle/drive_c/users/*/AppData/Local/{self.name()}" #noqa: E501
319+
for file in Path(self._ou_dedetai.install_dir).glob(glob): #noqa: E501
320+
appdata_dir = str(file)
321+
break
322+
if not appdata_dir:
323+
raise FileNotFoundError("Failed to find product's appdata dir. Did installation succeed?") # noqa: E501
324+
return appdata_dir
294325

295326
def wait_for_true(
296327
callable: Callable[[], Optional[bool]],
@@ -619,16 +650,20 @@ def test_first_run_resource_download(
619650
time.sleep(20)
620651

621652
# Three tabs and a space agrees with second option (essential/minimal).
622-
# Some accounts with very little resources do not have 3 options, but 2.
623-
logos.press_keys([KeyCodeTab()] *4 + [KeyCodeSpace()])
653+
# On Logos some accounts with very little resources do not have 3 options, but 2.
654+
# On Verbum this takes an extra Tab, and always has three options Full/Quick/Minimal
655+
logos.press_keys([KeyCodeTab()] *4)
656+
logos.press_keys(KeyCodeSpace())
624657
# Then shift+Tab three times to get to the continue button.
625658
# We need to use shift tab, as some accounts have three options in the radio
626659
# (Full/essential/minimal), others only have (full/minimal)
627660
# so we can't count on how many tabs to go down
628661
logos.press_keys(
629-
[KeyCodeModified(KeyCodeShift(), KeyCodeTab())] *3
630-
+ [KeyCodeReturn()]
662+
[KeyCodeModified(KeyCodeShift(), KeyCodeTab())] *3
631663
)
664+
# if logos.faithlife_product() == "Verbum": #XXX: It looks like this is required if there are three options. Can we just require an account with three options? And if that isn't the case login to Verbum?
665+
logos.press_keys(KeyCodeModified(KeyCodeShift(), KeyCodeTab()))
666+
logos.press_keys(KeyCodeReturn())
632667
# Wait for the UI to settle - we can wait here longer than we need to
633668
time.sleep(30)
634669
# Hit Continue again
@@ -641,14 +676,7 @@ def test_first_run_resource_download(
641676
# For example when testing this my download got stuck at 66%
642677
# But stopping and restarting fixed.
643678

644-
assert ou_dedetai.install_dir, "The test must start in isolated mode so we know where the install dir is realiably" #noqa: E501
645-
logos_appdata_dir = None
646-
for file in Path(ou_dedetai.install_dir).glob("data/wine64_bottle/drive_c/users/*/AppData/Local/Logos"): #noqa: E501
647-
logos_appdata_dir = str(file)
648-
break
649-
assert logos_appdata_dir
650-
651-
wait_for_directory_to_be_untouched(logos_appdata_dir, 60)
679+
wait_for_directory_to_be_untouched(logos.appdata_dir, 60)
652680

653681
logos.close()
654682

@@ -691,6 +719,12 @@ def test_logos_features(ou_dedetai: OuDedetai):
691719
# Let it settle
692720
time.sleep(4)
693721

722+
logos.open_guide("passage guide")
723+
logos.type_string("John 3:16")
724+
logos.press_keys(KeyCodeReturn())
725+
# Let it settle
726+
time.sleep(4)
727+
694728
logos.open_tool("copy bible verses")
695729

696730
# Now ensure the Logos window is still open
@@ -705,6 +739,13 @@ def test_logos_crash_is_detected_by_test_code(ou_dedetai: OuDedetai):
705739
706740
This scenario forces a known-crash - in this case a missing arial font and opening
707741
copy bible verses - to ensure our code detects that Logos did indeed crash."""
742+
743+
# FIXME: Find a way to crash Verbum too
744+
# For some reason this doesn't crash Verbum, but crashes logos.
745+
if FaithLifeProduct.name() == "Verbum":
746+
print("Skipping test (doesn't work on Verbum)")
747+
return
748+
708749
# Now check to see if our test code properly detects a crash
709750
logos = ou_dedetai.start_app()
710751

@@ -717,6 +758,8 @@ def test_logos_crash_is_detected_by_test_code(ou_dedetai: OuDedetai):
717758
fake_font_dir = font_dir + "_"
718759
shutil.move(font_dir, fake_font_dir)
719760

761+
# This also causes a crash on Logos, but this tool doesn't appear to be working
762+
# In the latest Verbum
720763
logos.open_tool("copy bible verses")
721764
# Let it settle
722765
time.sleep(2)
@@ -738,7 +781,7 @@ def test_logos_crash_is_detected_by_test_code(ou_dedetai: OuDedetai):
738781

739782
logos.close()
740783

741-
784+
# Xephyr is very useful for testing this - it is a nested Xorg server
742785
def main():
743786
# FIXME: also test the beta channel of Logos?
744787
# FIXME: also test verbum

0 commit comments

Comments
 (0)