Skip to content

Commit

Permalink
Test installer (#57)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
singh-lokendra authored and sushain97 committed Aug 3, 2019
1 parent 8506f5e commit f9f69d4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
29 changes: 14 additions & 15 deletions apertium/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,36 @@ def execute_pipeline(inp: str, commands: List[List[str]]) -> str:
input_file_name, output_file_name = input_file.name, output_file.name

arg = command[1][1] if len(command) >= 3 else ''
path = command[-1]
text = end.decode()
input_file.write(text)
input_file.close()

if 'lt-proc' == command[0]:
dictionary_path = command[-1]
lttoolbox.LtLocale.tryToSetLocale()
fst = lttoolbox.FST()
fst = lttoolbox.FST(dictionary_path)
if not fst.valid():
raise ValueError('FST Invalid')
fst = lttoolbox.FST()
fst.lt_proc(arg, path, input_file_name, output_file_name)
fst.lt_proc(arg, input_file_name, output_file_name)
elif 'lrx-proc' == command[0]:
dictionary_path = command[-1]
lextools.LtLocale.tryToSetLocale()
lrx = lextools.LRX()
lrx.lrx_proc(arg, path, input_file.name, output_file.name)
lrx = lextools.LRXProc(dictionary_path)
lrx.lrx_proc(arg, input_file.name, output_file.name)
elif 'apertium-transfer' == command[0]:
obj = apertium_core.apertium()
obj.transfer_text(arg, command[2], command[3], input_file.name, output_file.name)
obj = apertium_core.ApertiumTransfer(command[2], command[3])
obj.transfer_text(arg, input_file.name, output_file.name)
elif 'apertium-interchunk' == command[0]:
obj = apertium_core.apertium()
obj.interchunk_text(arg, command[1], command[2], input_file.name, output_file.name)
obj = apertium_core.ApertiumInterchunk(command[1], command[2])
obj.interchunk_text(arg, input_file.name, output_file.name)
elif 'apertium-postchunk' == command[0]:
obj = apertium_core.apertium()
obj.postchunk_text(arg, command[1], command[2], input_file.name, output_file.name)
obj = apertium_core.ApertiumPostchunk(command[1], command[2])
obj.postchunk_text(arg, input_file.name, output_file.name)
elif 'apertium-pretransfer' == command[0]:
obj = apertium_core.apertium()
obj.pretransfer(arg, input_file.name, output_file.name)
apertium_core.pretransfer(arg, input_file.name, output_file.name)
elif 'apertium-tagger' == command[0]:
command += [input_file.name, output_file.name]
apertium_core.tagger(len(command), command)
apertium_core.ApertiumTagger(len(command), command)
else:
used_wrapper = False

Expand Down
8 changes: 8 additions & 0 deletions build-swig-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ cd python
make -j2
python3 setup.py install
popd

git clone --depth 1 https://github.com/apertium/lttoolbox.git
pushd lttoolbox
./autogen.sh --enable-python-bindings
cd python
make -j2
python3 setup.py install
popd
29 changes: 29 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import importlib.util
import os
import platform
import shutil
import sys
import unittest

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


class TestInstallation(unittest.TestCase):
def test_apertium_installer(self):
# This test doesn't remove existing apertium binaries.
# So it is possible that apertium.installer.install_apertium() isn't working
apertium.installer.install_apertium()
apertium_processes = ['apertium-destxt', 'apertium-interchunk', 'apertium-postchunk',
'apertium-pretransfer', 'apertium-tagger', 'apertium-transfer',
'lrx-proc', 'lt-proc'
]
for process in apertium_processes:
self.assertIsNotNone(shutil.which(process), 'apertium installer not working. {} not available on system path'.format(process))
break

def test_install_module(self):
language = 'kir'
apertium.installer.install_module(language)
importlib.reload(apertium)
self.assertIn(language, apertium.analyzers, 'apetium.install_module not working')

def test_install_wrapper(self):
apertium.installer.install_wrapper('python3-lttoolbox')
if platform.system() == 'Linux':
sys.path.append('/usr/lib/python3/dist-packages')
self.assertIsNotNone(importlib.util.find_spec('lttoolbox'), 'Wrapper not installed')


class TestTranslate(unittest.TestCase):
def test_translator_en_spa(self):
translator = apertium.Translator('eng', 'spa')
Expand Down

0 comments on commit f9f69d4

Please sign in to comment.