test_batch.py 1.95 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
import shutil


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_batch(self):
        import batch

Christian Rohlfing's avatar
Christian Rohlfing committed
22
23
24
25
26
27
28
29
30
31
32
        expected_files = [
            'moodle_feedbacks.zip',
            'passwords.csv']
        expected_folders = [
            'LastnameA, FirstnameA_1519321_assignsubmission_file_',
            'LastnameB, FirstnameB_1519322_assignsubmission_file_',
            'LastnameJ, FirstnameJ_1519330_assignsubmission_file_',
            'LastnameK, FirstnameK_1519331_assignsubmission_file_'
        ]
        expected_pdfs = [
            '123001_LastnameA_w_aes.pdf']
33
34

        # Prepare parameter
Christian Rohlfing's avatar
Christian Rohlfing committed
35
36
37
38
        in_dir = './tests/assets/pdfs'
        csv = './tests/assets/Grades.csv'
        dpi = 50

39
40
41
42
43
44
45
46
47
48
        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)

        zipout_dir = os.path.join(self.test_dir, 'zipout')
        os.mkdir(zipout_dir)

        # Copy supplements file
49
50
51
        batch.main([
            in_dir, csv, out_dir,
            "-t", tmp_dir, "--cores", "1", "--dpi", str(dpi)])
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

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

        # Unpack zip
        zipfullfile = os.path.join(out_dir, 'moodle_feedbacks.zip')
        shutil.unpack_archive(zipfullfile, zipout_dir)

        # Assert zip output
        created_folders = os.listdir(zipout_dir)
        created_folders.sort()
        self.assertEqual(expected_folders, created_folders)

        created_pdfs = os.listdir(os.path.join(zipout_dir, created_folders[0]))
        self.assertEqual(created_pdfs, expected_pdfs)