Skip to content

Commit f9f69d4

Browse files
singh-lokendrasushain97
authored andcommitted
Test installer (#57)
* added: tests for apertium/installer.py * update: wrapper calls load dictionary during instatiation to reduce time * update: build-swig-wrapper apertium_core clone wrapper_optimise branch lttoolbox: build wrapper until package isnt updated * utils.py: moved dictionary_path to if block * tests: use inbuilt methods for assertion * update class name in apertium_core * clone apertium master, branch merged * test: check all the binaries used for subprocess call * test apertium binaries availability in single test * added: comment in install_apertium() test
1 parent 8506f5e commit f9f69d4

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

apertium/utils.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,36 @@ def execute_pipeline(inp: str, commands: List[List[str]]) -> str:
5656
input_file_name, output_file_name = input_file.name, output_file.name
5757

5858
arg = command[1][1] if len(command) >= 3 else ''
59-
path = command[-1]
6059
text = end.decode()
6160
input_file.write(text)
6261
input_file.close()
6362

6463
if 'lt-proc' == command[0]:
64+
dictionary_path = command[-1]
6565
lttoolbox.LtLocale.tryToSetLocale()
66-
fst = lttoolbox.FST()
66+
fst = lttoolbox.FST(dictionary_path)
6767
if not fst.valid():
6868
raise ValueError('FST Invalid')
69-
fst = lttoolbox.FST()
70-
fst.lt_proc(arg, path, input_file_name, output_file_name)
69+
fst.lt_proc(arg, input_file_name, output_file_name)
7170
elif 'lrx-proc' == command[0]:
71+
dictionary_path = command[-1]
7272
lextools.LtLocale.tryToSetLocale()
73-
lrx = lextools.LRX()
74-
lrx.lrx_proc(arg, path, input_file.name, output_file.name)
73+
lrx = lextools.LRXProc(dictionary_path)
74+
lrx.lrx_proc(arg, input_file.name, output_file.name)
7575
elif 'apertium-transfer' == command[0]:
76-
obj = apertium_core.apertium()
77-
obj.transfer_text(arg, command[2], command[3], input_file.name, output_file.name)
76+
obj = apertium_core.ApertiumTransfer(command[2], command[3])
77+
obj.transfer_text(arg, input_file.name, output_file.name)
7878
elif 'apertium-interchunk' == command[0]:
79-
obj = apertium_core.apertium()
80-
obj.interchunk_text(arg, command[1], command[2], input_file.name, output_file.name)
79+
obj = apertium_core.ApertiumInterchunk(command[1], command[2])
80+
obj.interchunk_text(arg, input_file.name, output_file.name)
8181
elif 'apertium-postchunk' == command[0]:
82-
obj = apertium_core.apertium()
83-
obj.postchunk_text(arg, command[1], command[2], input_file.name, output_file.name)
82+
obj = apertium_core.ApertiumPostchunk(command[1], command[2])
83+
obj.postchunk_text(arg, input_file.name, output_file.name)
8484
elif 'apertium-pretransfer' == command[0]:
85-
obj = apertium_core.apertium()
86-
obj.pretransfer(arg, input_file.name, output_file.name)
85+
apertium_core.pretransfer(arg, input_file.name, output_file.name)
8786
elif 'apertium-tagger' == command[0]:
8887
command += [input_file.name, output_file.name]
89-
apertium_core.tagger(len(command), command)
88+
apertium_core.ApertiumTagger(len(command), command)
9089
else:
9190
used_wrapper = False
9291

build-swig-wrapper.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ cd python
1818
make -j2
1919
python3 setup.py install
2020
popd
21+
22+
git clone --depth 1 https://github.com/apertium/lttoolbox.git
23+
pushd lttoolbox
24+
./autogen.sh --enable-python-bindings
25+
cd python
26+
make -j2
27+
python3 setup.py install
28+
popd

tests/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import importlib.util
12
import os
3+
import platform
4+
import shutil
25
import sys
36
import unittest
47

@@ -69,6 +72,32 @@ def test_uninstalled_mode(self):
6972
apertium.generate('spa', 'cat<n><pl>')
7073

7174

75+
class TestInstallation(unittest.TestCase):
76+
def test_apertium_installer(self):
77+
# This test doesn't remove existing apertium binaries.
78+
# So it is possible that apertium.installer.install_apertium() isn't working
79+
apertium.installer.install_apertium()
80+
apertium_processes = ['apertium-destxt', 'apertium-interchunk', 'apertium-postchunk',
81+
'apertium-pretransfer', 'apertium-tagger', 'apertium-transfer',
82+
'lrx-proc', 'lt-proc'
83+
]
84+
for process in apertium_processes:
85+
self.assertIsNotNone(shutil.which(process), 'apertium installer not working. {} not available on system path'.format(process))
86+
break
87+
88+
def test_install_module(self):
89+
language = 'kir'
90+
apertium.installer.install_module(language)
91+
importlib.reload(apertium)
92+
self.assertIn(language, apertium.analyzers, 'apetium.install_module not working')
93+
94+
def test_install_wrapper(self):
95+
apertium.installer.install_wrapper('python3-lttoolbox')
96+
if platform.system() == 'Linux':
97+
sys.path.append('/usr/lib/python3/dist-packages')
98+
self.assertIsNotNone(importlib.util.find_spec('lttoolbox'), 'Wrapper not installed')
99+
100+
72101
class TestTranslate(unittest.TestCase):
73102
def test_translator_en_spa(self):
74103
translator = apertium.Translator('eng', 'spa')

0 commit comments

Comments
 (0)