Newer
Older
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
import pytest
from PIL import Image
import os
from pylibdmtx.pylibdmtx import decode
from zesje.helpers.scan_helper import decode_barcode, ExamMetadata, ExtractedBarcode
from zesje.helpers import image_helper
# Returns the original image instead of retrieving a box from it
@pytest.fixture
def mock_get_box_return_original(monkeypatch, datadir):
def mock_return(image, widget, padding):
return image
monkeypatch.setattr(image_helper, 'get_box',
mock_return)
# Tests whether the output of calc angle is correct
@pytest.mark.parametrize('image_filename, token, expected', [
('COOLTOKEN_0005_01.png', 'COOLTOKEN', ExtractedBarcode('COOLTOKEN', 5, 1)),
('COOLTOKEN_0050_10.png', 'COOLTOKEN', ExtractedBarcode('COOLTOKEN', 50, 10)),
('TOKENCOOL_9999_99.png', 'TOKENCOOL', ExtractedBarcode('TOKENCOOL', 9999, 99))],
ids=['Simple test 1', 'Simple test 2', 'High numbers'])
def test_decode_barcode(datadir, image_filename, token, expected, mock_get_box_return_original):
image_path = os.path.join(datadir, 'datamatrices', image_filename)
exam_config = ExamMetadata(
token=token,
barcode_area=[0],
student_id_widget_area=None,
problem_ids=None
)
image = Image.open(image_path)
result = decode_barcode(image, exam_config)
assert result == expected
# Untested:
# - def process_pdf()
# - def extract_images()
# - def write_pdf_status()
# - def process_page()
# - def guess_dpi()
# - def rotate_image()
# - def shift_image()
# - get_student_number()
# Not tested in this file. See: test_get_studentnumber_precision.py