1919from tests import wl_test_init
2020from wordless import wl_concordancer_parallel
2121from wordless .wl_dialogs import wl_dialogs_misc
22+ from wordless .wl_nlp import wl_texts
23+
24+ main_global = None
2225
2326def test_concordancer_parallel ():
2427 main = wl_test_init .Wl_Test_Main (switch_lang_utils = 'fast' )
2528
2629 settings = main .settings_custom ['concordancer_parallel' ]
2730
28- settings ['search_settings' ]['multi_search_mode' ] = True
29- settings ['search_settings' ]['search_terms' ] = wl_test_init .SEARCH_TERMS
30-
3131 for i in range (2 ):
3232 match i :
3333 case 0 :
34+ settings ['search_settings' ]['multi_search_mode' ] = True
35+ settings ['search_settings' ]['search_terms' ] = wl_test_init .SEARCH_TERMS
36+
3437 wl_test_init .select_test_files (main , no_files = (0 , 1 , 2 ))
3538 case 1 :
36- wl_test_init .select_test_files (main , no_files = (1 , 2 , 5 ))
39+ settings ['search_settings' ]['multi_search_mode' ] = False
40+ settings ['search_settings' ]['search_term' ] = ''
41+
42+ wl_test_init .select_test_files (main , no_files = (8 , 9 , 10 ))
43+
44+ global main_global
45+ main_global = main
3746
3847 print (f"Files: { ' | ' .join (wl_test_init .get_test_file_names (main ))} " )
3948
@@ -45,23 +54,41 @@ def test_concordancer_parallel():
4554 worker_concordancer_parallel .finished .connect (update_gui )
4655 worker_concordancer_parallel .run ()
4756
48- def update_gui (err_msg , concordance_lines ):
57+ def update_gui (err_msg , parallel_units , num_paras_max ):
4958 print (err_msg )
5059 assert not err_msg
51- assert concordance_lines
52-
53- for concordance_line in concordance_lines :
54- assert len (concordance_line ) == 2
60+ assert parallel_units
5561
56- parallel_unit_no , len_parallel_units = concordance_line [ 0 ]
62+ files_selected = list ( main_global . wl_file_area . get_selected_files ())
5763
58- # Parallel Unit No.
59- assert parallel_unit_no >= 1
60- assert len_parallel_units >= 1
64+ # Test whether empty parallel units are removed
65+ if files_selected [0 ]['name' ] == '[eng_us] Empty search term - src' :
66+ assert parallel_units == [
67+ (4 , [
68+ [
69+ ['Omitted' , 'source' , 'text. (' , 'without' , 'corresponding' , 'translation).' ],
70+ wl_texts .to_tokens (['Omitted' , 'source' , 'text.' , ' (' , 'without' , 'corresponding' , 'translation' , ').' ])
71+ ],
72+ [[], []],
73+ [[], []]
74+ ]),
75+ (5 , [
76+ [[], []],
77+ [
78+ ['Added' , 'target' , 'text (' , 'without' , 'corresponding' , 'originals).' ],
79+ wl_texts .to_tokens (['Added' , 'target' , 'text' , ' (' , 'without' , 'corresponding' , 'originals' , ').' ])
80+ ],
81+ [[], []]
82+ ])
83+ ]
84+ else :
85+ for parallel_unit_no , parallel_units_files in parallel_units :
86+ # Parallel Unit No.
87+ assert 1 <= parallel_unit_no <= num_paras_max
6188
62- # Parallel Units
63- for parallel_unit in concordance_line [ 1 ] :
64- assert len (parallel_unit ) == 2
89+ # Parallel Units
90+ for parallel_unit in parallel_units_files :
91+ assert len (parallel_unit ) == 2
6592
6693if __name__ == '__main__' :
6794 test_concordancer_parallel ()
0 commit comments