test_preparepdf.py 1.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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))

    def test_copy_from_zip(self):
        import preparepdf

        expected_files = [
22
23
24
25
            '123001_L.pdf',
            '123002_L.pdf',
            '123010_L.pdf',
            '123011_L.pdf']
26
27

        # Prepare parameter
Christian Rohlfing's avatar
Christian Rohlfing committed
28
29
        in_zip = './tests/assets/submissions.zip'
        sheet_csv = "./tests/assets/Grades.csv"
30
31
32
33
34
35
36
37

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

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

        # Call function
Christian Rohlfing's avatar
Christian Rohlfing committed
38
        preparepdf.main([
39
            in_zip, sheet_csv, out_dir, "-t", tmp_dir])
40
41
42
43
44

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