๐Ÿ“ฆ siedentop / pyqrnative

๐Ÿ“„ test.py ยท 48 lines
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##!/usr/bin/python

#Copyright: 2011 Christoph Siedentop
#License: This code is licensed under the GPLv3. For more see LICENSE

import zbar #Zbar can be installed in Debian/Ubuntu by installing python-zbar
import Image
import unittest
import PyQRNative

class TestQRCode(unittest.TestCase):

    def setUp(self):
        self.data = "Test string"
        
        # Create image
        qr = PyQRNative.QRCode(4, PyQRNative.QRErrorCorrectLevel.L)
        qr.addData(self.data)
        qr.make()
        self.image = qr.makeImage()

        # Set up scanner
        self.scanner = zbar.ImageScanner()
        self.scanner.parse_config('enable')

    def test_result(self):
        ''' Assert that the image contains the requested data'''
        self.image = self.image.convert('L')
        width, height = self.image.size
        raw = self.image.tostring()
        
        zimage = zbar.Image(width, height, 'Y800', raw)
        
        self.scanner.scan(zimage)

        for symbol in zimage:
            t =  symbol.type
            data = symbol.data
        self.assertEqual(data, self.data)
        self.assertEqual(t, zbar.EnumItem(64, 'QRCODE'))
    
    def tearDown(self):
        del(self.image)


if __name__ == '__main__':
    unittest.main()