-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.py
58 lines (48 loc) · 2.04 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
# -*- coding: utf-8 -*-
import glob
import shutil
import os
import subprocess
from unittest import TestCase
# legacy tests
# don't blame me :P
class BuildTest(TestCase):
TESTS_DIR = 'tests_data'
EXAMPLES = {
'ejemplo': [['--YEAR=2016']],
'ejemplo_no_config': [['--YEAR=2016']],
'ejemplo_2': [['--YEAR=2016']],
'ejemplo_single': [['--YEAR=2016'], ['--YEAR=2016', '--exclude_index', '--BASE_FILENAME=index_excluded']]
}
@classmethod
def tearDownClass(cls):
for ex in cls.EXAMPLES.keys():
dir = os.path.join(cls.TESTS_DIR, ex)
if os.path.isdir(dir):
shutil.rmtree(dir)
@staticmethod
def run_and_assert(cmd, returncode):
print("Running: {}".format(cmd))
proc = subprocess.run(cmd, stdout=subprocess.PIPE)
#output = proc.communicate()[0]
if proc.returncode != returncode:
print (proc.output)
return proc.returncode
def test_build(self):
for ex in self.EXAMPLES.keys():
new_dir = os.path.join(self.TESTS_DIR, ex)
os.mkdir(new_dir)
for f in glob.glob(os.path.join(ex, '*.txt')) + [os.path.join(ex, 'config.py')]:
if os.path.isfile(f):
shutil.copy(f, new_dir)
for params in self.EXAMPLES[ex]:
cmd = ['python', 'automagica.py', '--only_tex'] + params + [os.path.join(self.TESTS_DIR, ex)]
self.run_and_assert(cmd, 0)
cmd = ['diff', 'tests_data/ejemplo/jungla.tex', 'tests_data/jungla.tex']
self.assertEqual(self.run_and_assert(cmd, 0), 0)
cmd = ['diff', 'tests_data/ejemplo_2/sueltos.tex', 'tests_data/sueltos.tex']
self.assertEqual(self.run_and_assert(cmd, 0), 0)
cmd = ['diff', 'tests_data/ejemplo_single/default.tex', 'tests_data/default.tex']
self.assertEqual(self.run_and_assert(cmd, 0), 0)
cmd = ['diff', 'tests_data/ejemplo_single/index_excluded.tex', 'tests_data/index_excluded.tex']
self.assertEqual(self.run_and_assert(cmd, 0), 0)