##// END OF EJS Templates
Remove unneeded workaround...
Remove unneeded workaround The globals update stuff is done in the plugin.

File last commit:

r26921:691cde99
r27156:3494468c
Show More
test_module_paths.py
109 lines | 3.2 KiB | text/x-python | PythonLexer
/ IPython / utils / tests / test_module_paths.py
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 # encoding: utf-8
Thomas Kluyver
Remove unused imports in IPython.utils
r11127 """Tests for IPython.utils.module_paths.py"""
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2008-2011 The IPython Development Team
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import shutil
import sys
import tempfile
dswij
pathlib on test_module_paths.py
r26140 from pathlib import Path
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
from IPython.testing.tools import make_tempfile
import IPython.utils.module_paths as mp
dswij
pathlib on test_module_paths.py
r26140 TEST_FILE_PATH = Path(__file__).resolve().parent
Matthias Bussonnier
test with dot
r24838
dswij
pathlib on test_module_paths.py
r26140 TMP_TEST_DIR = Path(tempfile.mkdtemp(suffix="with.dot"))
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 #
# Setup/teardown functions/decorators
#
old_syspath = sys.path
def make_empty_file(fname):
Mickaël Schoentgen
Fix ResourceWarning: unclosed file...
r24897 open(fname, 'w').close()
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
Matthias Bussonnier
Use module level setup and teardown compatible both nose and pytest....
r25082 def setup_module():
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 """Setup testenvironment for the module:
"""
# Do not mask exceptions here. In particular, catching WindowsError is a
# problem because that exception is only defined on Windows...
dswij
pathlib on test_module_paths.py
r26140 Path(TMP_TEST_DIR / "xmod").mkdir(parents=True)
Path(TMP_TEST_DIR / "nomod").mkdir(parents=True)
make_empty_file(TMP_TEST_DIR / "xmod/__init__.py")
make_empty_file(TMP_TEST_DIR / "xmod/sub.py")
make_empty_file(TMP_TEST_DIR / "pack.py")
make_empty_file(TMP_TEST_DIR / "packpyc.pyc")
sys.path = [str(TMP_TEST_DIR)]
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
Matthias Bussonnier
Use module level setup and teardown compatible both nose and pytest....
r25082 def teardown_module():
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 """Teardown testenvironment for the module:
Matthias Bussonnier
reformat docstring in IPython utils
r26419 - Remove tempdir
- restore sys.path
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 """
# Note: we remove the parent test dir, which is the root of all test
# subdirs we may have created. Use shutil instead of os.removedirs, so
# that non-empty directories are all recursively removed.
shutil.rmtree(TMP_TEST_DIR)
Thomas Kluyver
teardown changes to sys.path
r7017 sys.path = old_syspath
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
Matthias Bussonnier
test with dot
r24838 def test_tempdir():
"""
Ensure the test are done with a temporary file that have a dot somewhere.
"""
Samuel Gaist
[utils][tests][module_paths] Remove nose
r26921 assert "." in str(TMP_TEST_DIR)
Matthias Bussonnier
test with dot
r24838
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 def test_find_mod_1():
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 """
Search for a directory's file path.
Expected output: a path to that directory's __init__.py file.
"""
dswij
pathlib on test_module_paths.py
r26140 modpath = TMP_TEST_DIR / "xmod" / "__init__.py"
Samuel Gaist
[utils][tests][module_paths] Remove nose
r26921 assert Path(mp.find_mod("xmod")) == modpath
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_mod_2():
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 """
Search for a directory's file path.
Expected output: a path to that directory's __init__.py file.
TODO: Confirm why this is a duplicate test.
"""
dswij
pathlib on test_module_paths.py
r26140 modpath = TMP_TEST_DIR / "xmod" / "__init__.py"
Samuel Gaist
[utils][tests][module_paths] Remove nose
r26921 assert Path(mp.find_mod("xmod")) == modpath
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_mod_3():
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 """
Search for a directory + a filename without its .py extension
Expected output: full path with .py extension.
"""
dswij
pathlib on test_module_paths.py
r26140 modpath = TMP_TEST_DIR / "xmod" / "sub.py"
Samuel Gaist
[utils][tests][module_paths] Remove nose
r26921 assert Path(mp.find_mod("xmod.sub")) == modpath
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_mod_4():
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 """
Search for a filename without its .py extension
Expected output: full path with .py extension
"""
dswij
pathlib on test_module_paths.py
r26140 modpath = TMP_TEST_DIR / "pack.py"
Samuel Gaist
[utils][tests][module_paths] Remove nose
r26921 assert Path(mp.find_mod("pack")) == modpath
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_mod_5():
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 """
Search for a filename with a .pyc extension
Expected output: TODO: do we exclude or include .pyc files?
"""
Samuel Gaist
[utils][tests][module_paths] Remove nose
r26921 assert mp.find_mod("packpyc") == None