test_qr.py 1.26 KB
Newer Older
Deb's avatar
Deb committed
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
import unittest
import time


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

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

    def test_extract_first_qr(self):
        from utils import qr as qr_utils

        expected_qr = "23-16"

        pdf_file = "./tests/assets/pdfs/123001_LastnameA.pdf"
        qr = qr_utils.first_qr_from_first_pdf_page(pdf_file=pdf_file)
        self.assertEqual(qr, expected_qr)

    def test_extract_all_qrs(self):
        from utils import qr as qr_utils

        expected_qrs = [
            ['23-01'],
            ['23-02'],
            ['23-03'],
            ['23-04'],
            ['23-05'],
            ['23-06'],
            ['23-07'],
            ['23-08'],
            ['23-09'],
            ['23-10'],
            ['23-11'],
            ['23-12'],
            ['23-13'],
            ['23-14'],
            ['23-15'],
            ['23-16']
        ]

        # Parameters
        dpi = 200
        pdf_file = "./tests/assets/pdfs/123001_LastnameA.pdf"

        # Decode all QRs
        qrs, _ = qr_utils.qrs_from_pdf(pdf_file=pdf_file, dpi=dpi)
        qrs.sort()
        self.assertEqual(qrs, expected_qrs)