Ejemplo n.º 1
0
def test_field_read_cell():
    field = Field(DESCRIPTOR)
    assert field.read_cell("1") == (1, None)
    assert field.read_cell("string") == (
        None,
        {"type": 'type is "integer/default"'},
    )
    assert field.read_cell("-") == (None, {"required": 'constraint "required" is "True"'})
Ejemplo n.º 2
0
def test_field_read_cell_number_missingValues():
    field = Field({
        "name": "name",
        "type": "number",
        "missingValues": ["", "NA", "N/A"]
    })
    assert field.read_cell("") == (None, None)
    assert field.read_cell("NA") == (None, None)
    assert field.read_cell("N/A") == (None, None)
Ejemplo n.º 3
0
def test_datetime_read_cell(format, source, target):
    with pytest.warns(None) as recorded:
        field = Field({"name": "name", "type": "datetime", "format": format})
        cell, notes = field.read_cell(source)
        assert cell == target
    if not format.startswith("fmt:"):
        assert recorded.list == []
Ejemplo n.º 4
0
def test_array_read_cell_array_item_with_constraint():
    field = Field(type="array",
                  array_item={"constraints": {
                      "enum": ["val1", "val2"]
                  }})
    cell, notes = field.read_cell('["val1", "val2"]')
    assert cell == ["val1", "val2"]
    assert notes is None
Ejemplo n.º 5
0
def test_array_read_cell_array_item_with_constraint_error():
    field = Field(type="array", array_item={"constraints": {"enum": ["val1"]}})
    cell, notes = field.read_cell('["val1", "val2"]')
    assert cell == ["val1", "val2"]
    assert notes == {"enum": 'array item constraint "enum" is "[\'val1\']"'}
Ejemplo n.º 6
0
def test_array_read_cell_array_item_type_error():
    field = Field(type="array", array_item={"type": "integer"})
    cell, notes = field.read_cell('["1", "2", "bad"]')
    assert cell == [1, 2, None]
    assert notes == {"type": 'array item type is "integer/default"'}
Ejemplo n.º 7
0
def test_array_read_cell_array_item():
    field = Field(type="array", array_item={"type": "integer"})
    cell, notes = field.read_cell('["1", "2", "3"]')
    assert cell == [1, 2, 3]
    assert notes is None
Ejemplo n.º 8
0
def test_array_read_cell(format, source, target, options):
    field = Field(name="name", type="array", format=format)
    field.update(options)
    cell, notes = field.read_cell(source)
    assert cell == target
Ejemplo n.º 9
0
def test_integer_read_cell(format, source, target, options):
    descriptor = {"name": "name", "type": "integer", "format": format}
    descriptor.update(options)
    field = Field(descriptor)
    cell, notes = field.read_cell(source)
    assert cell == target
Ejemplo n.º 10
0
def test_duration_read_cell(format, source, target):
    field = Field({"name": "name", "type": "duration", "format": format})
    cell, notes = field.read_cell(source)
    assert cell == target
Ejemplo n.º 11
0
def test_yearmonth_read_cell(format, source, target):
    field = Field({"name": "name", "type": "yearmonth", "format": format})
    cell, notes = field.read_cell(source)
    assert cell == target
Ejemplo n.º 12
0
def test_time_read_cell(format, source, target, recwarn):
    field = Field({"name": "name", "type": "time", "format": format})
    cell, notes = field.read_cell(source)
    assert cell == target
    if not format.startswith("fmt:"):
        assert recwarn.list == []
Ejemplo n.º 13
0
def test_object_read_cell(format, source, target):
    field = Field({"name": "name", "type": "object", "format": format})
    cell, notes = field.read_cell(source)
    assert cell == target