]> git.openstreetmap.org Git - nominatim.git/commitdiff
replace usages of fromisoformat() with strptime()
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 23 Apr 2021 18:53:00 +0000 (20:53 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sat, 24 Apr 2021 13:12:57 +0000 (15:12 +0200)
fromisoformat was only introduced with Python 3.7 while we
still support Python 3.5.

Fixes #2292.

nominatim/db/status.py
test/python/test_db_status.py
test/python/test_tools_replication.py

index 225638f4bef3979f4f0b1fec501b90c120b57bfe..c543c746e22a1e1bf2c00d31c8998fa1186b5d14 100644 (file)
@@ -9,6 +9,7 @@ from ..tools.exec_utils import get_url
 from ..errors import UsageError
 
 LOG = logging.getLogger()
+ISODATE_FORMAT = '%Y-%m-%dT%H:%M:%S'
 
 def compute_database_date(conn):
     """ Determine the date of the database from the newest object in the
@@ -36,7 +37,7 @@ def compute_database_date(conn):
 
     LOG.debug("Found timestamp %s", match[1])
 
-    return dt.datetime.fromisoformat(match[1]).replace(tzinfo=dt.timezone.utc)
+    return dt.datetime.strptime(match[1], ISODATE_FORMAT).replace(tzinfo=dt.timezone.utc)
 
 
 def set_status(conn, date, seq=None, indexed=True):
index c659147148d4b2d970a5008e984e8fce02cc7242..9f0327637d561314e05819198f6473eef4c54cb1 100644 (file)
@@ -19,6 +19,11 @@ OSM_NODE_DATA = """\
 </osm>
 """
 
+def iso_date(date):
+    return dt.datetime.strptime(date, nominatim.db.status.ISODATE_FORMAT)\
+               .replace(tzinfo=dt.timezone.utc)
+
+
 def test_compute_database_date_valid(monkeypatch, status_table, place_row, temp_db_conn):
     place_row(osm_type='N', osm_id=45673)
 
@@ -32,7 +37,7 @@ def test_compute_database_date_valid(monkeypatch, status_table, place_row, temp_
     date = nominatim.db.status.compute_database_date(temp_db_conn)
 
     assert requested_url == ['https://www.openstreetmap.org/api/0.6/node/45673/1']
-    assert date == dt.datetime.fromisoformat('2006-01-27T22:09:10').replace(tzinfo=dt.timezone.utc)
+    assert date == iso_date('2006-01-27T22:09:10')
 
 
 def test_compute_database_broken_api(monkeypatch, status_table, place_row, temp_db_conn):
index 156385ad8bb337e1403b1a55e737c7ef766d90ef..affe13174a6256dbb8c960758c636b9bfd7d397e 100644 (file)
@@ -41,7 +41,8 @@ def test_init_replication_success(monkeypatch, status_table, place_row, temp_db_
 
     temp_db_cursor.execute("SELECT * FROM import_status")
 
-    expected_date = dt.datetime.fromisoformat('2006-01-27T19:09:10').replace(tzinfo=dt.timezone.utc)
+    expected_date = dt.datetime.strptime('2006-01-27T19:09:10', status.ISODATE_FORMAT)\
+                        .replace(tzinfo=dt.timezone.utc)
     assert temp_db_cursor.rowcount == 1
     assert temp_db_cursor.fetchone() == [expected_date, 234, True]