-
Notifications
You must be signed in to change notification settings - Fork 92
improve unittests and fix strptime of status datetime for 3.6 #145
Conversation
…he "update_examples" function with a start by the value of global variable "UPDATE_EXAMPLES"
We've dropped py3.6 support since this PR was opened, so the parts related to that shouldn't be merged. |
I won't be able to spend any time on this for a couple of weeks, but I'll check in and see how I can help out at that point. |
overpass/api.py
Outdated
@@ -93,7 +95,7 @@ def get(self, query, responseformat="geojson", verbosity="body", build=True, dat | |||
date = datetime.fromisoformat(date) | |||
except ValueError: | |||
# The 'Z' in a standard overpass date will throw fromisoformat() off | |||
date = datetime.strptime(date, '%Y-%m-%dT%H:%M:%SZ') | |||
date = self._strptime(date) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed since we've dropped 3.6 support
overpass/dependency.py
Outdated
@@ -0,0 +1,9 @@ | |||
import sys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecated by the dropping of 3.6
overpass/api.py
Outdated
def _strptime(date_string): | ||
if dependency.Python.less_3_7(): | ||
dt = datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%SZ') | ||
kwargs = {k: getattr(dt, k) for k in ('year', 'month', 'day', 'hour', 'minute', 'second', 'microsecond')} | ||
kwargs['tzinfo'] = timezone.utc | ||
return datetime(**kwargs) | ||
|
||
return datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%S%z') | ||
|
||
@classmethod | ||
def _api_status(cls) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also deprecated by the dropping of 3.6 support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean we can get rid of the custom _strptime()
function altogether and replace with plain datetime.strptime()
?
overpass/api.py
Outdated
def __deprecation_get(self, *args, **kwargs): | ||
import warnings | ||
warnings.warn('Call to deprecated function "Get", use "get" function instead', DeprecationWarning) | ||
return self.get(*args, **kwargs) | ||
|
||
def __deprecation_search(self, *args, **kwargs): | ||
import warnings | ||
warnings.warn('Call to deprecated function "Search", use "search" function instead', DeprecationWarning) | ||
return self.search(*args, **kwargs) | ||
|
||
# deprecation of upper case functions | ||
Get = get | ||
Search = search | ||
Get = __deprecation_get | ||
Search = __deprecation_search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still relevant with the dropping of 3.6.
overpass/api.py
Outdated
waiting_slots = tuple(cls._strptime(waiting_re.search(line).group()) | ||
for line in lines if waiting_re.search(line)) | ||
|
||
current_idx = next( | ||
i for i, word in enumerate(lines) | ||
if word.startswith('Currently running queries') | ||
) | ||
running_slots = tuple(tuple(line.split()) for line in lines[current_idx + 1:]) | ||
running_slots_datetimes = tuple( | ||
datetime.strptime( | ||
slot[3], "%Y-%m-%dT%H:%M:%S%z" | ||
) | ||
for slot in running_slots | ||
) | ||
running_slots_datetimes = tuple(cls._strptime(slot[3]) for slot in running_slots) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also deprecated by the dropping of 3.6 support
RESOURCE_PATH = os.path.join(os.path.dirname(os.path.abspath(os.path.relpath(__file__))), 'resources') | ||
|
||
|
||
def save_resource(file_name, data): | ||
with open(os.path.join(RESOURCE_PATH, file_name), 'wb') as f: | ||
f.write(data) | ||
|
||
|
||
def load_resource(file_name): | ||
with open(os.path.join(RESOURCE_PATH, file_name), 'rb') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use pathlib instead of os.path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not familiar. What does that give us?
Everything in the files I didn't comment on looks to still be relevant at first glance (and great work there!) but I haven't run any of the tests yet to be sure. |
also migrated some metadata to pyproject.toml
I would be in favor of closing this PR and opening a new one focused just on the tests. |
thanks @dericke , I will close this then and create an issue that we can create a new PR against. |
• mock all requests to real overpass endpoint in unittests
• refactor unittests
• add more unittests
• fix strptime of status datetime for 3.6