Skip to content
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

PR: Fix error when setting a path with a single quote #6543

Merged
merged 7 commits into from
Mar 7, 2018

Conversation

csabella
Copy link
Contributor

@csabella csabella commented Feb 27, 2018

Fixes #6451.

@ccordoba12 ccordoba12 added this to the v3.2.8 milestone Feb 27, 2018
@ccordoba12
Copy link
Member

@csabella, please add a test for this.

@csabella
Copy link
Contributor Author

@ccordoba12 I wasn't sure how to add a test. I put some code on the issue showing that it was working with a manual test. Is there an existing test that I can look at for creating a new directory or for working with these ipython command calls?

@ccordoba12
Copy link
Member

ccordoba12 commented Feb 28, 2018

Take a look at test_conf_env_vars:

https://github.com/spyder-ide/spyder/blob/3.x/spyder/plugins/tests/test_ipythonconsole.py#L196

That does pretty much what you need to do here.

@pep8speaks
Copy link

pep8speaks commented Feb 28, 2018

Hello @csabella! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on March 07, 2018 at 10:50 Hours UTC

@csabella
Copy link
Contributor Author

@ccordoba12 Thanks for the suggestion! In that test file, test_get_env called get_env which had the same type of goal as get_cwd and set_cwd. Very helpful.

I'm getting PEP8 warnings, but I copied that code from the other tests. Is the longer line allowed here?

@@ -323,6 +323,60 @@ def test_console_coloring(ipyconsole, qtbot):
assert console_font_color.strip() == editor_font_color.strip()


@pytest.mark.slow
@flaky(max_runs=3)
@pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows")
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove this skipif condition to test this on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


# Issue 6451.
savetemp = shell._cwd
tempdir = tempfile.mkdtemp(suffix="queen's")
Copy link
Member

Choose a reason for hiding this comment

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

Please use the tmpdir fixture instead of tempfile. There's an example of it here:

https://github.com/spyder-ide/spyder/blob/3.x/spyder/app/tests/test_mainwindow.py#L213

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I've made the change.


@pytest.mark.slow
@flaky(max_runs=3)
@pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows")
Copy link
Member

Choose a reason for hiding this comment

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

Remove skipif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


# Issue 6451.
savetemp = shell._cwd
tempdir = tempfile.mkdtemp(suffix="queen's")
Copy link
Member

Choose a reason for hiding this comment

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

Please use the tmpdir fixture.

@ccordoba12
Copy link
Member

@csabella, this looks pretty good. I just left a couple of comments in your tests to improve them a bit.

And please don't worry about pep8 issues in test files. Unfortunately, we can't make pep8speaks to ignore them.


# Assert we get the assigned value correctly
assert shell.get_value('cwd') == tempdir
os.rmdir(tempdir)
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this so that this test can pass on Windows.

@csabella
Copy link
Contributor Author

csabella commented Mar 4, 2018

It looks like windows isn't applying the os.chdir before the assert. :-( Trying to figure it out.

# Ask for directory.
with qtbot.waitSignal(shell.sig_change_cwd):
shell.get_cwd()
assert shell._cwd == tempdir
Copy link
Member

Choose a reason for hiding this comment

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

What if you introduce a qtbot.wait(1000) before this line to see if the test pass?

@csabella
Copy link
Contributor Author

csabella commented Mar 6, 2018

Ignore this. I didn't see the changes you did on the tests before I wrote my comment.

I've added a qtbot.wait(). However, all the existing tests near this one just skip windows (@pytest.mark.skipif(os.name == 'nt' or PYQT4, reason="It doesn't work on Windows and segfaults in PyQt4")). I can enter the commands run by those other tests manually into the IPython console on a windows machine (such as "import os; os.environ['FOO'] = 'bar'"), but yet the automated testing is skipped. I believe the chdir in this new test is running into the same issues as those other tests.

@ccordoba12
Copy link
Member

@csabella, I don't want to put an additional burden on you, so if you want to skip this test on Windows, please do it.

However, all the existing tests near this one just skip windows

Well, I just removed a lot of those skipif's because I noticed the corresponding tests were hanging on Windows due to us opening a QDialog and trying to close it with a QTimer. I removed that and used a lower level API instead.

@csabella
Copy link
Contributor Author

csabella commented Mar 6, 2018

@ccordoba12 It's not a burden. I just don't know what to change to get it to work. My dev box is Linux and it works there. I can run the Spyder installation on Windows, but I can't download the git repo and test it from there. So, I'm kind of in the dark trying to fix this in the tests. :-(

@ccordoba12
Copy link
Member

@csabella, no worries then. If you tested your PR on a Windows box and it works, then please skip the test. You can come back later to remove the skip if you find how to do it (I've done that a lot of times :-).

@csabella
Copy link
Contributor Author

csabella commented Mar 6, 2018

@ccordoba12 No, I haven't tested it on Windows. I can't install the git repo on the Windows box that I can access, so I can't test my changes there.

@ccordoba12
Copy link
Member

@dalthviz, please test @csabella work on Windows and let us know if it works for you or not.

@ccordoba12 ccordoba12 requested a review from dalthviz March 6, 2018 18:36
@jnsebgosselin
Copy link
Member

jnsebgosselin commented Mar 6, 2018

The patch is working, but the test_get_cwd is failing locally on my setup (Windows 7 64 bits). I'll take a look a it now in case I can find out why.

This is from the window that spawn during the test :
image

@jnsebgosselin
Copy link
Member

jnsebgosselin commented Mar 6, 2018

The test is failing because of the \ in the path when running shell.execute("import os; os.chdir('''{}''')".format(tempdir))

Running this instead with a raw string works:
shell.execute("import os; os.chdir(r'''{}''')".format(tempdir))

So, following what is done in shell.py, something like this maybe? It's not pretty, but it works lol

    if os.name == 'nt':
        tempdir = tempdir.replace(u"\\", u"\\\\")

    # Change directory in the console.
    with qtbot.waitSignal(shell.executed):
        shell.execute(u"import os; os.chdir(u'''{}''')".format(tempdir))

    if os.name == 'nt':
        tempdir = tempdir.replace(u"\\\\", u"\\")

@csabella
Copy link
Contributor Author

csabella commented Mar 6, 2018

Thank you, @jnsebgosselin! I really appreciate you looking into this. Without being able to test on Windows, I would have never figured that out.

@jnsebgosselin
Copy link
Member

I'm glad I could help! Is it me or the tests are failing for a reason that is unrelated to this PR? The test test_get_help is failing everywhere.

@ccordoba12
Copy link
Member

Cheryl, the failures are unrelated to your tests. I'm fixing them in #6626.

@csabella
Copy link
Contributor Author

csabella commented Mar 7, 2018

@ccordoba12 Thank you for letting me know. I was just going to start looking into them.

@ccordoba12
Copy link
Member

@csabella, please rebase to get my fix. Then this should be ready.

@csabella
Copy link
Contributor Author

csabella commented Mar 7, 2018

Thanks again @ccordoba12 and @jnsebgosselin for helping me get the test to pass. :-)

@ccordoba12 ccordoba12 changed the title PR: Error when setting a path with a single quote PR: Fix error when setting a path with a single quote Mar 7, 2018
@ccordoba12 ccordoba12 merged commit 53ae83e into spyder-ide:3.x Mar 7, 2018
ccordoba12 added a commit that referenced this pull request Mar 7, 2018
@csabella csabella deleted the issue6451 branch March 7, 2018 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants