-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
add test case when to_csv argument is sys.stdout #21572
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
Conversation
Hello @r00ta! Thanks for updating the PR.
Comment last updated on June 22, 2018 at 13:01 Hours UTC |
def test_to_csv_stdout_file(self): | ||
# GH 21561 | ||
str_array = [{'names': ['foo', 'bar']}, {'names': ['baz', 'qux']}] | ||
df = pd.DataFrame(str_array) |
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.
might be simpler to:
DataFrame([['foo', 'bar'], ['baz', 'qux']], columns=['name_1', 'name_2'])
output = out.getvalue() | ||
assert output == expected_ascii | ||
sys.stdout = saved_stdout | ||
assert sys.stdout.closed is False |
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.
I would do below instead:
assert not sys.stdout.closed
Is it possible to parametrize this as a value in an existing test rather than adding a separate test case? |
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.
there appear to be an existing pandas.util.testing.capture_stdout decorator
Codecov Report
@@ Coverage Diff @@
## master #21572 +/- ##
==========================================
+ Coverage 91.9% 91.9% +<.01%
==========================================
Files 153 153
Lines 49557 49549 -8
==========================================
- Hits 45545 45539 -6
+ Misses 4012 4010 -2
Continue to review full report at Codecov.
|
Thanks for the tips! I've updated the PR :D |
@r00ta : You have a couple of linting errors: https://travis-ci.org/pandas-dev/pandas/jobs/395098214#L2876 |
lgtm. merge on green. |
@@ -6,7 +6,7 @@ | |||
import pytest | |||
from pandas import DataFrame | |||
from pandas.util import testing as tm | |||
|
|||
from pandas.util.testing import capture_stdout |
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.
would it be possible to use tm.capture_stdout rather add another import?
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.
good point!
The remaining failure is a linting error: pandas/tests/io/formats/test_to_csv.py:10:1: E302 expected 2 blank lines, found 1 |
thanks @r00ta |
(cherry picked from commit 66fea91)
(cherry picked from commit 66fea91)
git diff upstream/master -u -- "*.py" | flake8 --diff
Add new test case when to_csv argument is sys.stdout