forked from apertium/apertium-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·93 lines (65 loc) · 2.22 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
import importlib
import os
import shutil
import subprocess
import unittest
apertium_init = importlib.import_module('apertium-init')
def make_path(name, prefix=apertium_init.default_prefix):
return '{}-{}'.format(prefix, name)
def build(path, autogen_args=[]):
try:
subprocess.check_output(['./autogen.sh'] + autogen_args, cwd=path, stderr=subprocess.STDOUT, universal_newlines=True)
except subprocess.CalledProcessError as error:
print(error.output)
raise
try:
subprocess.check_output('make', cwd=path, stderr=subprocess.STDOUT, universal_newlines=True)
except subprocess.CalledProcessError as error:
print(error.output)
raise
class TestModule:
name = 'eng'
path = make_path(name)
@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.path)
def test_created(self):
os.path.exists('eng')
def test_builds(self):
build(self.path)
class TestInvalidModule(unittest.TestCase):
name = 'eng-cat-spa'
def test_init(self):
with self.assertRaises(SystemExit):
apertium_init.main([self.name])
class TestLttoolboxModule(TestModule, unittest.TestCase):
@classmethod
def setUpClass(cls):
apertium_init.main([cls.name])
class TestHfstModule(TestModule, unittest.TestCase):
@classmethod
def setUpClass(cls):
apertium_init.main([cls.name, '--analyser=hfst'])
class TestLttoolboxPair(TestModule, unittest.TestCase):
name = 'eng-cat'
path = make_path(name)
name1 = 'eng'
path1 = make_path(name1)
name2 = 'cat'
path2 = make_path(name2)
@classmethod
def setUpClass(cls):
for name, path in [(cls.name1, cls.path1), (cls.name2, cls.path2)]:
apertium_init.main([name])
build(path)
apertium_init.main([cls.name])
@classmethod
def tearDownClass(cls):
for path in [cls.path, cls.path1, cls.path2]:
shutil.rmtree(path)
def test_builds(self):
autogen_args = ['--with-lang1=../{}'.format(self.path1), '--with-lang2=../{}'.format(self.path2)]
build(self.path, autogen_args=autogen_args)
if __name__ == '__main__':
unittest.main(buffer=True, verbosity=2)