Add portable corpus, annotation provenance, admission, review and bounded agent-cycle contracts. Preserve dataset ownership and explicit research acceptance limits.
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
|
|
import numpy as np
|
|
import pytest
|
|
|
|
p = Path(__file__).resolve().parents[1]/"simulation/semantic-learning/label_extension.py"
|
|
s = importlib.util.spec_from_file_location("label_extension", p)
|
|
m = importlib.util.module_from_spec(s)
|
|
s.loader.exec_module(m)
|
|
|
|
|
|
def test_expanding_background_keeps_old_uncertain_band_and_known_labels():
|
|
base = np.full((5, 8), 255, np.uint8)
|
|
base[2, 3:5] = 1
|
|
base[1, 3:5] = 0
|
|
base[4, 7] = 1
|
|
lock = np.zeros(base.shape, bool)
|
|
lock[1:4, 2:6] = True
|
|
proposal = np.zeros(base.shape, np.uint8)
|
|
proposal[0, 0] = 1
|
|
got = m.extend_reviewed_target(base, proposal, lock)
|
|
np.testing.assert_array_equal(got[lock], base[lock])
|
|
np.testing.assert_array_equal(got[base != 255], base[base != 255])
|
|
assert got[0, 0] == got[4, 7] == 1 and got[0, 1] == 0
|
|
assert got[2, 2] == 255 and proposal[4, 7] == 0
|
|
|
|
|
|
def test_omitted_or_misaligned_protection_rejected():
|
|
base = np.full((2, 3), 255, np.uint8)
|
|
for lock in [None, np.zeros((3, 2), bool), np.zeros((2, 3), np.uint8)]:
|
|
with pytest.raises(ValueError):
|
|
m.extend_reviewed_target(base, base, lock)
|
|
|
|
|
|
def test_out_of_vocabulary_labels_rejected():
|
|
base = np.full((2, 3), 255, np.uint8)
|
|
proposal = base.copy()
|
|
proposal[0, 0] = 2
|
|
with pytest.raises(ValueError):
|
|
m.extend_reviewed_target(base, proposal, np.zeros(base.shape, bool))
|