def test_step_cell_format(): source = Resource(path="data/transform.csv") source.infer() source.schema.get_field("id").type = "string" source.schema.get_field("population").type = "string" target = transform( source, steps=[ steps.cell_format(template="Prefix: {0}"), ], ) assert target.schema == source.schema assert target.read_rows() == [ { "id": "Prefix: 1", "name": "Prefix: germany", "population": "Prefix: 83" }, { "id": "Prefix: 2", "name": "Prefix: france", "population": "Prefix: 66" }, { "id": "Prefix: 3", "name": "Prefix: spain", "population": "Prefix: 47" }, ]
def test_step_cell_format_with_name(): source = Resource(path="data/transform.csv") source.infer() target = transform( source, steps=[ steps.cell_format(template="Prefix: {0}", field_name="name"), ], ) assert target.schema == source.schema assert target.read_rows() == [ { "id": 1, "name": "Prefix: germany", "population": 83 }, { "id": 2, "name": "Prefix: france", "population": 66 }, { "id": 3, "name": "Prefix: spain", "population": 47 }, ]
def test_step_cell_format(): source = Resource(path="data/transform.csv") target = transform( source, steps=[ steps.field_update(name="id", type="string"), steps.field_update(name="population", type="string"), steps.cell_format(template="Prefix: {0}"), ], ) assert target.schema == { "fields": [ { "name": "id", "type": "string" }, { "name": "name", "type": "string" }, { "name": "population", "type": "string" }, ] } assert target.read_rows() == [ { "id": "Prefix: 1", "name": "Prefix: germany", "population": "Prefix: 83" }, { "id": "Prefix: 2", "name": "Prefix: france", "population": "Prefix: 66" }, { "id": "Prefix: 3", "name": "Prefix: spain", "population": "Prefix: 47" }, ]