-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix handling undefined length in CdxRecord #83
Fix handling undefined length in CdxRecord #83
Conversation
Wow, I’m surprised I haven’t run into this before! Could you please add a test? After that, I’ll get this merged and released ASAP. Since this is covering a pretty narrow scenario, it’s probably better to use a mock (most of the tests use VCR). This one is a decent example: wayback/wayback/tests/test_client.py Lines 166 to 190 in 024a80e
But since this is such a simple case, you probably don’t need the response content in a separate file. You could just have a string right in the source code for the test. |
@Mr0grog thanks for the feedback, added a test case |
@@ -79,10 +79,10 @@ Ready to contribute? Here's how to set up `wayback` for local development. | |||
5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:: | |||
|
|||
$ flake8 wayback tests | |||
$ python setup.py test | |||
$ pytest |
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.
Oh, thanks for catching this!
wayback/tests/test_client.py
Outdated
matchType="domain", | ||
filter_field="statuscode:200") | ||
|
||
assert 5 == len(list(records)) |
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 should probably also be asserting that the .length
property on the last one is None
while the others are ints, e.g:
assert 5 == len(list(records)) | |
items = list(records) | |
assert 5 == len(items) | |
assert isinstance(items[0].length, int) | |
assert items[4] is None |
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.
Thanks, I will make this change
wayback/_client.py
Outdated
@@ -539,7 +539,7 @@ def search(self, url, *, matchType=None, limit=None, offset=None, | |||
status_code = None | |||
else: | |||
status_code = int(data.status_code) | |||
length = int(data.length) | |||
length = None if data.length == "-" else int(data.length) |
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.
Oh, please use single quotes for non-multiline strings, too. Sorry I missed this last night.
length = None if data.length == "-" else int(data.length) | |
length = None if data.length == '-' else int(data.length) |
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.
Will do
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 looks great! Would you like to be listed as a contributor?
@Mr0grog That sounds great thanks! |
e24b0c3
to
d5d052f
Compare
You can now grab this from PyPI as version 0.3.1! 🚀 |
The exception occurs on line 542 of
_client.py
. The problem is the service returns "-" where length should be, probably indicating that for some reason this data is missing, however the wayback client attempts to parse it to an int. In this case, use None instead.