Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

improve unittests and fix strptime of status datetime for 3.6 #145

Closed
wants to merge 15 commits into from

Conversation

Vitalts
Copy link

@Vitalts Vitalts commented Oct 12, 2021

• mock all requests to real overpass endpoint in unittests
• refactor unittests
• add more unittests
• fix strptime of status datetime for 3.6

@mvexel
Copy link
Owner

mvexel commented Nov 18, 2021

Hi @Vitalts - after merging @dericke 's PR #141 there are some minor merge conflicts, could you resolve and then I can merge, please?

@dericke
Copy link
Contributor

dericke commented Nov 19, 2021

We've dropped py3.6 support since this PR was opened, so the parts related to that shouldn't be merged.

@mvexel
Copy link
Owner

mvexel commented Mar 22, 2022

@Vitalts Are you still interested in getting this merged? See also @dericke's comment. Sorry for the slow turnaround.. Let me know if I can help in any way.

@mvexel
Copy link
Owner

mvexel commented Jan 8, 2024

@dericke @Vitalts how would you like to proceed with this, in light of the significant changes in test_api.py in #140 ?

@dericke
Copy link
Contributor

dericke commented Jan 8, 2024

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)
Copy link
Contributor

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

@@ -0,0 +1,9 @@
import sys
Copy link
Contributor

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
Comment on lines 142 to 152
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:
Copy link
Contributor

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

Copy link
Owner

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
Comment on lines 210 to 222
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
Copy link
Contributor

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
Comment on lines 169 to 177
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)
Copy link
Contributor

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

Comment on lines +6 to +15
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:
Copy link
Contributor

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?

Copy link
Owner

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?

@dericke
Copy link
Contributor

dericke commented Jan 23, 2024

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.

@mvexel
Copy link
Owner

mvexel commented Jan 29, 2024

@Vitalts are you still interested in getting this over the finish line? I'm sorry it all took so long.. With @dericke 's comments we are one step closer.

also migrated some metadata to pyproject.toml
@mvexel
Copy link
Owner

mvexel commented Feb 12, 2024

so @dericke @Vitalts This branch has diverged from main enough that merging will be a bit of a mess. I could use some help especially with api.py

Anyone has some time to spend on this? Or should we abandon this PR and start a new one focused on fixing the tests and deprecating 3.6?

@dericke
Copy link
Contributor

dericke commented Feb 19, 2024

I would be in favor of closing this PR and opening a new one focused just on the tests.

@mvexel
Copy link
Owner

mvexel commented Feb 21, 2024

thanks @dericke , I will close this then and create an issue that we can create a new PR against.

@mvexel mvexel closed this Feb 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants