test_renamescans.py 1.42 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
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_qr_exception(self):
        import renamescans

        # Prepare parameter
Christian Rohlfing's avatar
Christian Rohlfing committed
22
23
        in_dir = './tests/assets/pdfs_scan'
        sheet_csv = "./tests/assets/Grades.csv"
Christian Rohlfing's avatar
Christian Rohlfing committed
24
25
26
27
28
29
30

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

        # Call function
        try:
            renamescans.main([
31
                in_dir, sheet_csv, out_dir,
Christian Rohlfing's avatar
Christian Rohlfing committed
32
33
34
35
                "--dry", "--checkqr"])
        except Exception:
            pass

Christian Rohlfing's avatar
Christian Rohlfing committed
36
    def test_rename_by_csv(self):
Christian Rohlfing's avatar
Christian Rohlfing committed
37
38
39
        import renamescans

        expected_files = [
Christian Rohlfing's avatar
Christian Rohlfing committed
40
41
42
43
44
            '123001_L.pdf',
            '123002_L.pdf',
            '123010_L.pdf',
            '123011_L.pdf',
            '123012_d.pdf']
Christian Rohlfing's avatar
Christian Rohlfing committed
45
46

        # Prepare parameter
Christian Rohlfing's avatar
Christian Rohlfing committed
47
48
        in_dir = './tests/assets/pdfs_scan'
        sheet_csv = "./tests/assets/Grades.csv"
Christian Rohlfing's avatar
Christian Rohlfing committed
49
50
51
52
53

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

        # Call function
54
        renamescans.main([in_dir, sheet_csv, out_dir])
Christian Rohlfing's avatar
Christian Rohlfing committed
55
56
57
58
59

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