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"'})
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)
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 == []
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
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\']"'}
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"'}
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
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
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
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
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
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 == []
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