Skip to content

STY: use pytest.raises context syntax #24676

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

Merged
merged 4 commits into from
Jan 9, 2019

Conversation

simonjayhawkins
Copy link
Member

xref #24332

@gfyoung gfyoung added Refactor Internal refactoring of code Testing pandas testing functions or related to the test suite labels Jan 9, 2019
pytest.raises(ValueError, Unpacker, read_size=5, max_buffer_size=3)
msg = "read_size should be less or equal to max_buffer_size"
with pytest.raises(ValueError, match=msg):
Unpacker(read_size=5, max_buffer_size=3)
Copy link
Member

@gfyoung gfyoung Jan 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see at least two distinct tests in this one. In the interest of smaller, more modular, testing, let's at least break it up here where I've commented.

@gfyoung gfyoung added the IO Data IO issues that don't fit into a more specific label label Jan 9, 2019
@gfyoung
Copy link
Member

gfyoung commented Jan 9, 2019

@simonjayhawkins : Even though it's just a handful of files, I have to commend the acrobatics you had to do to make this all work. 👍

@@ -326,7 +346,8 @@ def test_next(self, mmap_file):
next_line = next(wrapper)
assert next_line.strip() == line.strip()

pytest.raises(StopIteration, next, wrapper)
with pytest.raises(StopIteration, match=r'$^'):
next(wrapper)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised r'$^' works, but it seems it does. In any case, it's a bit confusing to read, because normally the caret (^) checks for the beginning of a line and the dollar for the end. I'd switch those characters around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h-vetinari well spotted. thanks. i'll get that sorted.

@simonjayhawkins
Copy link
Member Author

@gfyoung

@simonjayhawkins : Even though it's just a handful of files, I have to commend the acrobatics you had to do to make this all work

Thanks!

this could be because either the error messages should be more consistent, or maybe it would have been better to put the expected error messages in the parametrization. The 'acrobatics' would then be scoped to just the variations due to platform/interpreter/compiler.

@jreback jreback added this to the 0.24.0 milestone Jan 9, 2019
@jreback jreback merged commit 9744a4d into pandas-dev:master Jan 9, 2019
@jreback
Copy link
Contributor

jreback commented Jan 9, 2019

thanks @simonjayhawkins

@simonjayhawkins simonjayhawkins deleted the tests-io branch January 9, 2019 13:23
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO Data IO issues that don't fit into a more specific label Refactor Internal refactoring of code Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants