コード例 #1
0
def test_parse_mapping():
    defn = SchemaDefinition({
        "name": "test",
        "mapping": {
            "a": "z"
        },
        "prev_mapping": {
            "ba": "z"
        },
        "next_mapping": {
            "ab": "z"
        },
        "ending_mapping": {
            "aa": "zz"
        },
        "samples": [["aaa", "zzz"], ["baa", "bzz"]],
    })
    defn.parse()
    assert defn.name == "test"
    assert defn.mapping == {"a": "z"}
    assert defn.prev_mapping == {"ba": "z"}
    assert defn.next_mapping == {"ab": "z"}
    assert defn.ending_mapping == {"aa": "zz"}
    assert len(defn.samples) == 2
    assert defn.samples[0] == ["aaa", "zzz"]
    assert defn.samples[1] == ["baa", "bzz"]
コード例 #2
0
def test_empty_prev_mapping():
    defn = SchemaDefinition({
        "name": "test",
        "mapping": {},
        "prev_mapping": {}
    })
    defn.parse()
    assert defn.prev_mapping == {}
コード例 #3
0
def test_invalid_next_mapping():
    with pytest.raises(ValueError) as exc:
        defn = SchemaDefinition({
            "name": "test",
            "mapping": {},
            "next_mapping": "42"
        })
        defn.parse()
    assert str(exc.value) == "test: Invalid schema next_mapping: 42"
コード例 #4
0
def test_invalid_sample_type():
    with pytest.raises(ValueError) as exc:
        defn = SchemaDefinition({
            "name": "test",
            "mapping": {},
            "samples": [["aa", {}]]
        })
        defn.parse()
    assert str(exc.value) == "test: Invalid schema sample: ['aa', {}]"
コード例 #5
0
def test_invalid_sample_not_list():
    with pytest.raises(ValueError) as exc:
        defn = SchemaDefinition({
            "name": "test",
            "mapping": {},
            "samples": ["42"]
        })
        defn.parse()
    assert str(exc.value) == "test: Invalid schema sample: 42"
コード例 #6
0
def test_missing_prev_mapping():
    defn = SchemaDefinition({"name": "test", "mapping": {}})
    defn.parse()
    assert defn.prev_mapping is None
コード例 #7
0
def test_invalid_mapping():
    with pytest.raises(ValueError) as exc:
        defn = SchemaDefinition({"name": "test"})
        defn.parse()
    assert str(exc.value) == "test: Missing schema mapping"
コード例 #8
0
def test_empty_name():
    with pytest.raises(ValueError) as exc:
        defn = SchemaDefinition({"name": ""})
        defn.parse()
    assert str(exc.value) == ": Schema name should not be empty"
コード例 #9
0
def test_invalid_name():
    with pytest.raises(ValueError) as exc:
        defn = SchemaDefinition({})
        defn.parse()
    assert str(exc.value) == ": Missing schema name"
コード例 #10
0
def test_empty_samples():
    defn = SchemaDefinition({"name": "test", "mapping": {}, "samples": []})
    defn.parse()
    assert defn.samples == []
コード例 #11
0
def test_missing_samples():
    defn = SchemaDefinition({"name": "test", "mapping": {}})
    defn.parse()
    assert defn.samples is None