7
7
import abc
8
8
import os
9
9
from pathlib import Path
10
+ import tempfile
10
11
import psutil
11
12
import shutil
12
13
import subprocess
13
- import tempfile
14
14
import threading
15
15
import time
16
16
from typing import Callable , Optional , Union
@@ -94,7 +94,7 @@ def isolate_files(self):
94
94
if self ._temp_dir is not None :
95
95
shutil .rmtree (self ._temp_dir )
96
96
# 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_" )
98
98
self .config = Path (self ._temp_dir ) / "config.json"
99
99
self .install_dir = Path (self ._temp_dir ) / "install_dir"
100
100
@@ -145,6 +145,8 @@ def run(self, *args, **kwargs):
145
145
env ["PATH" ] = os .environ .get ("PATH" , "" )
146
146
env ["HOME" ] = os .environ .get ("HOME" , "" )
147
147
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" )
148
150
kwargs ["env" ] = env
149
151
log_level = ""
150
152
if self .log_level == "debug" :
@@ -175,14 +177,14 @@ def uninstall(self):
175
177
# Open an issue for this.
176
178
self .run (["--uninstall" , "-y" ])
177
179
178
- def start_app (self ) -> "Logos " :
180
+ def start_app (self ) -> "FaithLifeProduct " :
179
181
# Start a thread, as this command doesn't exit
180
182
threading .Thread (target = self .run , args = [["--run-installed-app" ]]).start ()
181
183
# There is only one thing we need to check generally for logos.
182
184
# Consider making display_server a paramater in the future if
183
185
# this needs to be something else.
184
186
display_server = DisplayServer .detect (raise_if_winedbg_is_running )
185
- logos = Logos (self , display_server )
187
+ logos = FaithLifeProduct (self , display_server )
186
188
# Now wait for the window to open before returning the open window.
187
189
wait_for_true (logos .is_window_open )
188
190
display_server .window_name = logos .window_name ()
@@ -191,17 +193,16 @@ def start_app(self) -> "Logos":
191
193
return logos
192
194
193
195
def stop_app (self ):
196
+ # FIXME: this didn't close Verbum (well it does after a click)
194
197
self .run (["--stop-installed-app" ])
195
198
# FIXME: wait for close?
196
199
197
200
198
201
# FIXME: test this against Verbum too. It should be the same.
199
202
# If not, make this an abstract class w/overrides.
200
203
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"""
205
206
_ou_dedetai : OuDedetai
206
207
_display_server : "DisplayServer"
207
208
@@ -288,9 +289,39 @@ def is_crashed(self) -> bool:
288
289
return False
289
290
290
291
@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
294
325
295
326
def wait_for_true (
296
327
callable : Callable [[], Optional [bool ]],
@@ -619,16 +650,20 @@ def test_first_run_resource_download(
619
650
time .sleep (20 )
620
651
621
652
# 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 ())
624
657
# Then shift+Tab three times to get to the continue button.
625
658
# We need to use shift tab, as some accounts have three options in the radio
626
659
# (Full/essential/minimal), others only have (full/minimal)
627
660
# so we can't count on how many tabs to go down
628
661
logos .press_keys (
629
- [KeyCodeModified (KeyCodeShift (), KeyCodeTab ())] * 3
630
- + [KeyCodeReturn ()]
662
+ [KeyCodeModified (KeyCodeShift (), KeyCodeTab ())] * 3
631
663
)
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 ())
632
667
# Wait for the UI to settle - we can wait here longer than we need to
633
668
time .sleep (30 )
634
669
# Hit Continue again
@@ -641,14 +676,7 @@ def test_first_run_resource_download(
641
676
# For example when testing this my download got stuck at 66%
642
677
# But stopping and restarting fixed.
643
678
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 )
652
680
653
681
logos .close ()
654
682
@@ -691,6 +719,12 @@ def test_logos_features(ou_dedetai: OuDedetai):
691
719
# Let it settle
692
720
time .sleep (4 )
693
721
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
+
694
728
logos .open_tool ("copy bible verses" )
695
729
696
730
# Now ensure the Logos window is still open
@@ -705,6 +739,13 @@ def test_logos_crash_is_detected_by_test_code(ou_dedetai: OuDedetai):
705
739
706
740
This scenario forces a known-crash - in this case a missing arial font and opening
707
741
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
+
708
749
# Now check to see if our test code properly detects a crash
709
750
logos = ou_dedetai .start_app ()
710
751
@@ -717,6 +758,8 @@ def test_logos_crash_is_detected_by_test_code(ou_dedetai: OuDedetai):
717
758
fake_font_dir = font_dir + "_"
718
759
shutil .move (font_dir , fake_font_dir )
719
760
761
+ # This also causes a crash on Logos, but this tool doesn't appear to be working
762
+ # In the latest Verbum
720
763
logos .open_tool ("copy bible verses" )
721
764
# Let it settle
722
765
time .sleep (2 )
@@ -738,7 +781,7 @@ def test_logos_crash_is_detected_by_test_code(ou_dedetai: OuDedetai):
738
781
739
782
logos .close ()
740
783
741
-
784
+ # Xephyr is very useful for testing this - it is a nested Xorg server
742
785
def main ():
743
786
# FIXME: also test the beta channel of Logos?
744
787
# FIXME: also test verbum
0 commit comments