Skip to content

TST: Add match=msg to all pytest.raises in pandas/tests/io/json #38705

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

Conversation

moink
Copy link
Member

@moink moink commented Dec 26, 2020

This pull request partially addresses xref #30999 to remove bare pytest.raises by adding match=msg. It doesn't close that issue as I have only addressed test modules in tje pandas/tests/io/json directory.

I also moved a couple of lines out of the pytest.raises context to make clear which pandas method was raising the error. And I deleted a couple of unreachable asserts in tests.

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

json = StringIO('{"articleId":' + str(bigNum) + "}")
msg = r"Value is too small|Value is too big"
with pytest.raises(ValueError, match=msg):
read_json(json)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the line for testing the string '{"0":{"articleId":' + str(bigNum) + "}}" is lost with these changes. The two cases '{"articleId":' + str(bigNum) + "}" and '{"0":{"articleId":' + str(bigNum) + "}}" are different, so I think both should be kept.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks. looks like I misread it to do the same thing twice.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

Comment on lines 830 to 836
"Cannot decode multidimensional arrays with variable length elements to "
"numpy|"
"argument must be a string, a bytes-like object or a number, not|"
"nesting not supported for object or variable length dtypes|"
r"invalid literal for int\(\) with base 10|"
"labels only supported up to 2 dimensions|"
"cannot reshape array of size"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to add such a complex match, I would just do a "match all" here

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, again I didn't want to do a match all, so I added the error message to the test parameters. It added a lot of lines due to the line length limit, but I think it's ok. Let me know what you think.

I wanted to try this, but if you really don't like it I will do it your way.

@jorisvandenbossche jorisvandenbossche changed the title TST: GH30999 Add match=msg to all pytest.raises in pandas/tests/io/json TST: Add match=msg to all pytest.raises in pandas/tests/io/json Dec 27, 2020
@jreback jreback added Error Reporting Incorrect or improved errors from pandas IO JSON read_json, to_json, json_normalize Testing pandas testing functions or related to the test suite labels Dec 27, 2020
@jreback jreback added this to the 1.3 milestone Dec 27, 2020
@jreback jreback merged commit 382e806 into pandas-dev:master Dec 27, 2020
@jreback
Copy link
Contributor

jreback commented Dec 27, 2020

thanks @moink the error messages really do help in reading the test code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas IO JSON read_json, to_json, json_normalize Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants