Spaces:
Runtime error
Runtime error
File size: 2,933 Bytes
e4f9cbe |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
"""Tests for concept."""
from ..schema import SignalInputType
from .concept import DRAFT_MAIN, Concept, Example, draft_examples
def test_draft_examples_main() -> None:
concept = Concept(
namespace='test_namespace',
concept_name='test_name',
type=SignalInputType.TEXT,
data={
'0': Example(id='0', label=True, text='hello'),
'1': Example(id='1', label=False, text='world'),
},
version=0)
assert draft_examples(concept, DRAFT_MAIN) == {
'0': Example(id='0', label=True, text='hello'),
'1': Example(id='1', label=False, text='world'),
}
def test_draft_examples_simple_draft() -> None:
concept = Concept(
namespace='test_namespace',
concept_name='test_name',
type=SignalInputType.TEXT,
data={
'0': Example(id='0', label=True, text='hello'),
'1': Example(id='1', label=False, text='world'),
'2': Example(id='2', label=True, text='hello draft 1', draft='draft1'),
'3': Example(id='3', label=False, text='world draft 1', draft='draft1'),
'4': Example(id='4', label=True, text='hello draft 2', draft='draft2'),
'5': Example(id='5', label=False, text='world draft 2', draft='draft2'),
},
version=0)
assert draft_examples(concept, DRAFT_MAIN) == {
'0': Example(id='0', label=True, text='hello'),
'1': Example(id='1', label=False, text='world'),
}
assert draft_examples(concept, 'draft1') == {
'0': Example(id='0', label=True, text='hello'),
'1': Example(id='1', label=False, text='world'),
'2': Example(id='2', label=True, text='hello draft 1', draft='draft1'),
'3': Example(id='3', label=False, text='world draft 1', draft='draft1'),
}
assert draft_examples(concept, 'draft2') == {
'0': Example(id='0', label=True, text='hello'),
'1': Example(id='1', label=False, text='world'),
'4': Example(id='4', label=True, text='hello draft 2', draft='draft2'),
'5': Example(id='5', label=False, text='world draft 2', draft='draft2'),
}
def test_draft_examples_draft_dedupe() -> None:
concept = Concept(
namespace='test_namespace',
concept_name='test_name',
type=SignalInputType.TEXT,
data={
'0': Example(id='0', label=True, text='hello'),
'1': Example(id='1', label=False, text='world'),
# Duplicate text.
'2': Example(id='2', label=False, text='hello', draft='draft'),
'3': Example(id='3', label=False, text='world draft', draft='draft'),
},
version=0)
assert draft_examples(concept, DRAFT_MAIN) == {
'0': Example(id='0', label=True, text='hello'),
'1': Example(id='1', label=False, text='world'),
}
assert draft_examples(concept, 'draft') == {
# 0 is deduplicated with 2.
'1': Example(id='1', label=False, text='world'),
# 2 overrides 0's label.
'2': Example(id='2', label=False, text='hello', draft='draft'),
'3': Example(id='3', label=False, text='world draft', draft='draft'),
}
|