Commit 5965f143 authored by Cecilia Nievas's avatar Cecilia Nievas
Browse files

Expanded test for write_data_unit_tiles_to_database

parent 61c995fc
Pipeline #29114 passed with stage
in 2 minutes and 5 seconds
......@@ -498,3 +498,39 @@ def test_write_data_unit_tiles_to_database(test_db):
assert exec_result[0][0] == 1
db_test.close_connection()
# Test case in which fraction_data_unit_built_up_area is NaN
aggregated_source_id = 2
occupancy_case = "residential"
example_data_unit.data_unit_tiles["quadkey"].values[-1] = "332233223322332233"
example_data_unit.data_unit_tiles["fraction_data_unit_built_up_area"].values[-1] = numpy.nan
DataUnitTilesHelper.write_data_unit_tiles_to_database(
config.database_gde_tiles,
"data_unit_tiles",
aggregated_source_id,
occupancy_case,
exposure_entity_code,
example_data_unit,
)
# Query the database to verify that the data-unit tile has been written to the table as NaN
db_test = Database(**config.database_gde_tiles)
db_test.create_connection_and_cursor()
sql_command = "SELECT fraction_data_unit_built_up_area FROM data_unit_tiles"
sql_command += " WHERE (quadkey='%s' AND aggregated_source_id='%s'"
sql_command += " AND occupancy_case='%s' AND data_unit_id='%s');"
db_test.cursor.execute(
sql_command
% (
example_data_unit.data_unit_tiles["quadkey"].values[-1],
str(aggregated_source_id),
occupancy_case,
"%s_%s" % (exposure_entity_code, example_data_unit.id),
)
)
exec_result = db_test.cursor.fetchall()
assert numpy.isnan(exec_result[0][0])
db_test.close_connection()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment