test_supplements.py 3.63 KB
Newer Older
Christian Rohlfing's avatar
Christian Rohlfing committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import unittest
import time
import os
import tempfile


class MainTest(unittest.TestCase):
    def setUp(self):
        self.tic = time.time()  # todo this is sooo ugly

        self.test_dir = tempfile.mkdtemp()

    def tearDown(self):
        self.toc = time.time()
        t = self.toc - self.tic
        print('Time: %.3f' % (t))

18
19
20
    def test_supplements_from_pdf_folder(self):
        import supplements

Christian Rohlfing's avatar
Christian Rohlfing committed
21
22
23
24
25
26
27
28
29
        expected_files = [
            '123001_LastnameA_GDET3_20H.pdf',
            '123001_LastnameA_GDET3_20H_loes.pdf',
            '123002_LastnameB_GDET3_20H.pdf',
            '123002_LastnameB_GDET3_20H_loes.pdf',
            '123010_LastnameJ_GDET3_20H.pdf',
            '123010_LastnameJ_GDET3_20H_loes.pdf',
            '123011_LastnameK_GDET3_20H.pdf',
            '123011_LastnameK_GDET3_20H_loes.pdf']
30
31

        # Prepare parameter
Christian Rohlfing's avatar
Christian Rohlfing committed
32
33
        supp_dir = './tests/assets/supplements'
        pdf_dir = './tests/assets/pdfs'
34
35
36
37
38
39
40
41

        supp_out_dir = os.path.join(self.test_dir, 'supplements_out')
        os.mkdir(supp_out_dir)

        tmp_dir = os.path.join(self.test_dir, 'tmp')
        os.mkdir(tmp_dir)

        # Copy supplements file
42
        supplements.main([supp_dir, pdf_dir, supp_out_dir])
43
44
45
46
47
48
49
50
51

        # Assert output
        created_files = os.listdir(supp_out_dir)
        created_files.sort()
        self.assertEqual(expected_files, created_files)

    def test_supplements_from_csv(self):
        import supplements

Christian Rohlfing's avatar
Christian Rohlfing committed
52
53
54
55
56
57
58
59
60
61
62
        expected_files = [
            '123001_L_GDET3_20H.pdf',
            '123001_L_GDET3_20H_loes.pdf',
            '123002_L_GDET3_20H.pdf',
            '123002_L_GDET3_20H_loes.pdf',
            '123010_L_GDET3_20H.pdf',
            '123010_L_GDET3_20H_loes.pdf',
            '123011_L_GDET3_20H.pdf',
            '123011_L_GDET3_20H_loes.pdf',
            '123012_d_GDET3_20H.pdf',
            '123012_d_GDET3_20H_loes.pdf']
63
64

        # Prepare parameter
Christian Rohlfing's avatar
Christian Rohlfing committed
65
66
        supp_dir = './tests/assets/supplements'
        csv = './tests/assets/Grades.csv'
67
68
69
70
71
72
73
74

        supp_out_dir = os.path.join(self.test_dir, 'supplements_out')
        os.mkdir(supp_out_dir)

        tmp_dir = os.path.join(self.test_dir, 'tmp')
        os.mkdir(tmp_dir)

        # Copy supplements file
75
        supplements.main([supp_dir, csv, supp_out_dir])
76
77
78
79
80
81

        # Assert output
        created_files = os.listdir(supp_out_dir)
        created_files.sort()
        self.assertEqual(expected_files, created_files)

Christian Rohlfing's avatar
Christian Rohlfing committed
82
83
84
85
    def test_supplements_watermark(self):
        import supplements
        import watermark

Christian Rohlfing's avatar
Christian Rohlfing committed
86
87
88
89
90
91
92
93
94
        expected_files = [
            '123001_LastnameA_GDET3_20H_loes_w.pdf',
            '123001_LastnameA_GDET3_20H_w.pdf',
            '123002_LastnameB_GDET3_20H_loes_w.pdf',
            '123002_LastnameB_GDET3_20H_w.pdf',
            '123010_LastnameJ_GDET3_20H_loes_w.pdf',
            '123010_LastnameJ_GDET3_20H_w.pdf',
            '123011_LastnameK_GDET3_20H_loes_w.pdf',
            '123011_LastnameK_GDET3_20H_w.pdf']
Christian Rohlfing's avatar
Christian Rohlfing committed
95
96

        # Prepare parameter
Christian Rohlfing's avatar
Christian Rohlfing committed
97
98
        supp_dir = './tests/assets/supplements'
        pdf_dir = './tests/assets/pdfs'
99
        dpi = 100
Christian Rohlfing's avatar
Christian Rohlfing committed
100
101
102
103
104
105
106
107
108
109
110

        supp_out_dir = os.path.join(self.test_dir, 'supplements_out')
        os.mkdir(supp_out_dir)

        tmp_dir = os.path.join(self.test_dir, 'tmp')
        os.mkdir(tmp_dir)

        out_dir = os.path.join(self.test_dir, 'out')
        os.mkdir(out_dir)

        # Copy supplements file
111
        supplements.main([supp_dir, pdf_dir, supp_out_dir])
Christian Rohlfing's avatar
Christian Rohlfing committed
112
113

        # Watermark files
Christian Rohlfing's avatar
Christian Rohlfing committed
114
115
        watermark.main(
            [supp_out_dir, out_dir, "-t", tmp_dir, "--dpi", str(dpi)])
Christian Rohlfing's avatar
Christian Rohlfing committed
116
117
118
119
120

        # Assert output
        created_files = os.listdir(out_dir)
        created_files.sort()
        self.assertEqual(expected_files, created_files)