test_get_student_number.py 1.11 KB
Newer Older
Nick Cleintuar's avatar
Nick Cleintuar committed
1
import os
Jamy Mahabier's avatar
Jamy Mahabier committed
2 3 4

import pytest

Jamy Mahabier's avatar
Jamy Mahabier committed
5
from zesje import scans
Nick Cleintuar's avatar
Nick Cleintuar committed
6 7 8 9 10 11 12 13 14

# Mocks


# 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
Jamy Mahabier's avatar
Jamy Mahabier committed
15
    monkeypatch.setattr(scans, 'get_box', mock_return)
Nick Cleintuar's avatar
Nick Cleintuar committed
16 17 18 19 20 21 22 23 24


# Tests


# Tests the accuracy and precision of the system for a number of test data.
# More test data should be added. If done, maybe also consider increasing
# the threshold in the assert.
def test_get_studentnumber_precision(datadir, mock_get_box_return_original):
25 26 27 28 29 30 31
    class MockExamConfig:
        student_id_widget_area = [
            0,
            0,
            0,
            0,
        ]
Nick Cleintuar's avatar
Nick Cleintuar committed
32 33 34 35 36 37

    im_names = os.listdir(os.path.join(datadir, 'studentnumbers'))
    for filename_full in im_names:
        im_path = os.path.join(datadir, 'studentnumbers', f'{filename_full}')
        filename_short, _ = os.path.splitext(filename_full)
        expected_number = int(filename_short)
Jamy Mahabier's avatar
Jamy Mahabier committed
38
        detected_number = scans.get_student_number(im_path, MockExamConfig)
39
        assert(expected_number == detected_number)