Skip to content

Problem with tests test_get_ipython_dir_* when using pathlib #12651

Closed as not planned

Description

@davbrito

I am having problem passing this test:

def test_get_ipython_dir_2():
"""test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions."""
with patch_get_home_dir('someplace'), \
patch.object(paths, 'get_xdg_dir', return_value=None), \
patch.object(paths, '_writable_dir', return_value=True), \
patch('os.name', "posix"), \
modified_env({'IPYTHON_DIR': None,
'IPYTHONDIR': None,
'XDG_CONFIG_HOME': None
}):
ipdir = paths.get_ipython_dir()
nt.assert_equal(ipdir, os.path.join("someplace", ".ipython"))

And others similar.

The problem is this line: patch('os.name', "posix"). Because pathlib thinks it is running into a unix system then tries to use PosixPath.
Therefore it gets this error:

======================================================================
ERROR: test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\David\Envs\ipy\lib\site-packages\nose\case.py", line 198, in runTest
    self.test(*self.arg)
  File "c:\users\david\proyectos\ipython\IPython\core\tests\test_paths.py", line 67, in test_get_ipython_dir_2
    ipdir = paths.get_ipython_dir()
  File "c:\users\david\proyectos\ipython\IPython\paths.py", line 45, in get_ipython_dir
    ipdir = Path(home_dir, ipdir_def)
  File "c:\python\python38\lib\pathlib.py", line 1035, in __new__
    raise NotImplementedError("cannot instantiate %r on your system"
NotImplementedError: cannot instantiate 'PosixPath' on your system

@Carreau what should I do?

Originally posted by @davbrito in #12650 (comment)

Activity

  1. changed the title [-]I am having problem passing [this test](https://github.com/ipython/ipython/blob/3c2c1857268fba1833b324d8b4e4ce53b0220b83/IPython/core/tests/test_paths.py#L57), and others similar.[/-] [+]Problem with tests test_get_ipython_dir_* when using pathlib[/+] on Oct 19, 2020
  2. davbrito commented on Oct 19, 2020

    @davbrito
    Author

    @meeseeksdev tag help wanted

  3. davbrito commented on Oct 19, 2020

    @davbrito
    Author

    @meeseeksdev tag testing

  4. lumberbot-app commented on Oct 19, 2020

    @lumberbot-app
    Contributor

    Aww davbrito, I was not able to apply the following label(s): testing. Either because they are not existing labels on this repository or because you do not have the permission to apply these.I tried my best to guess by looking at the casing, but was unable to find matching labels.

  5. MrMino commented on Oct 20, 2020

    @MrMino
    Member

    Patching os.name into posix is not a good idea IMO, especially since builtins depend on its value.

  6. davbrito commented on Oct 20, 2020

    @davbrito
    Author

    Patching os.name into posix is not a good idea IMO, especially since builtins depend on its value.

    Why do they do it in those tests? Is there any justification for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions