class TestZBarCam(unittest.TestCase): def setUp(self): with mock.patch('kivy.uix.anchorlayout.AnchorLayout.__init__'): self.zbarcam = ZBarCam() def test_detect_qrcode_frame_no_qrcode(self): """ Checks `_detect_qrcode_frame()` returns empty list on no qrcode. """ fixture_path = os.path.join(FIXTURE_DIR, 'no_qr_code.png') texture = Image(fixture_path).texture code_types = self.zbarcam.code_types symbols = self.zbarcam._detect_qrcode_frame(texture, code_types) assert symbols == [] def test_detect_qrcode_frame_one_qrcode(self): """ Checks `_detect_qrcode_frame()` can detect one qrcode. """ fixture_path = os.path.join(FIXTURE_DIR, 'one_qr_code.png') texture = Image(fixture_path).texture code_types = self.zbarcam.code_types symbols = self.zbarcam._detect_qrcode_frame(texture, code_types) assert symbols == [ ZBarCam.Symbol(type='QRCODE', data=b'zbarlight test qr code') ] def test_detect_qrcode_frame_one_qrcode_one_ean(self): """ Checks `_detect_qrcode_frame()` can detect one qrcode and one ean. """ fixture_path = os.path.join(FIXTURE_DIR, 'one_qr_code_and_one_ean.png') texture = Image(fixture_path).texture code_types = self.zbarcam.code_types symbols = self.zbarcam._detect_qrcode_frame(texture, code_types) assert symbols == [ ZBarCam.Symbol(type='QRCODE', data=b'zbarlight test qr code'), ZBarCam.Symbol(type='UPCA', data=b'012345678905') ] def test_detect_qrcode_frame_two_qrcodes(self): """ Checks `_detect_qrcode_frame()` can detect two qrcodes. """ fixture_path = os.path.join(FIXTURE_DIR, 'two_qr_codes.png') texture = Image(fixture_path).texture code_types = self.zbarcam.code_types symbols = self.zbarcam._detect_qrcode_frame(texture, code_types) Symbol = ZBarCam.Symbol assert symbols == [ Symbol(type='QRCODE', data=b'second zbarlight test qr code'), Symbol(type='QRCODE', data=b'zbarlight test qr code'), ]
def test_detect_qrcode_frame_one_qrcode_one_ean(self): """ Checks `_detect_qrcode_frame()` can detect one qrcode and one ean. """ fixture_path = os.path.join(FIXTURE_DIR, 'one_qr_code_and_one_ean.png') texture = Image(fixture_path).texture code_types = self.zbarcam.code_types symbols = self.zbarcam._detect_qrcode_frame(texture, code_types) self.assertEqual(symbols, [ ZBarCam.Symbol(type='QRCODE', data=b'zbarlight test qr code'), ZBarCam.Symbol(type='UPCA', data=b'012345678905') ])
def gotoZbarcam(self, *a): from kivy_garden.zbarcam import ZBarCam self.zbarcam = zbc = ZBarCam() lo = self.zparpagelayout lo.clear_widgets() lo.add_widget(zbc) lo.add_widget(self.makeBackButton()) self.backup_screenmanager = self.screenManager.current self.screenManager.current = 'zbarcam'
def test_detect_qrcode_frame_one_qrcode(self): """ Checks `_detect_qrcode_frame()` can detect one qrcode. """ fixture_path = os.path.join(FIXTURE_DIR, 'one_qr_code.png') texture = Image(fixture_path).texture code_types = self.zbarcam.code_types symbols = self.zbarcam._detect_qrcode_frame(texture, code_types) assert symbols == [ ZBarCam.Symbol(type='QRCODE', data=b'zbarlight test qr code') ]
def __init__(self, app, **kwargs): super(QRreader, self).__init__(**kwargs) self.app = app QR_layout = FloatLayout() label = Label(text="Take photo of QR code or enter data", halign='center', font_size='20sp', size_hint=(.6, .1), pos_hint={ 'x': .2, 'y': 0.9 }) QR_layout.add_widget(label) self.zbarcam = ZBarCam(size_hint=(.6, .4), pos_hint={ 'x': .2, 'y': 0.5 }) QR_layout.add_widget(self.zbarcam) self.read_text = TextInput(text="Make photo", multiline=False, readonly=False, halign="left", font_size=100, size_hint=(.8, .1), pos_hint={ 'x': .1, 'y': 0.4 }) QR_layout.add_widget(self.read_text) make_photo = Button(text="Make photo", halign='center', size_hint=(.5, .1), pos_hint={ 'x': .25, 'y': .25 }) make_photo.bind(on_press=self.make_photo) QR_layout.add_widget(make_photo) confirm = Button(text="Confirm", halign='center', size_hint=(.5, .1), pos_hint={ 'x': .25, 'y': .1 }) confirm.bind(on_press=self.confirm) QR_layout.add_widget(confirm) self.add_widget(QR_layout)
def setUp(self): with mock.patch('kivy.uix.anchorlayout.AnchorLayout.__init__'): self.zbarcam = ZBarCam()