##// END OF EJS Templates
fix oinspect module
fix oinspect module

File last commit:

r21354:571e85ef
r22961:64f6d323
Show More
test_module_paths.py
128 lines | 3.8 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
#-----------------------------------------------------------------------------
from __future__ import with_statement
import os
import shutil
import sys
import tempfile
from os.path import join, abspath, split
from IPython.testing.tools import make_tempfile
import IPython.utils.module_paths as mp
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 import nose.tools as nt
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 env = os.environ
TEST_FILE_PATH = split(abspath(__file__))[0]
TMP_TEST_DIR = tempfile.mkdtemp()
#
# Setup/teardown functions/decorators
#
old_syspath = sys.path
def make_empty_file(fname):
f = open(fname, 'w')
f.close()
def setup():
"""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...
os.makedirs(join(TMP_TEST_DIR, "xmod"))
os.makedirs(join(TMP_TEST_DIR, "nomod"))
make_empty_file(join(TMP_TEST_DIR, "xmod/__init__.py"))
make_empty_file(join(TMP_TEST_DIR, "xmod/sub.py"))
make_empty_file(join(TMP_TEST_DIR, "pack.py"))
make_empty_file(join(TMP_TEST_DIR, "packpyc.pyc"))
Thomas Kluyver
teardown changes to sys.path
r7017 sys.path = [TMP_TEST_DIR]
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def teardown():
"""Teardown testenvironment for the module:
- Remove tempdir
Thomas Kluyver
teardown changes to sys.path
r7017 - 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
def test_get_init_1():
"""See if get_init can find __init__.py in this testdir"""
with make_tempfile(join(TMP_TEST_DIR, "__init__.py")):
assert mp.get_init(TMP_TEST_DIR)
def test_get_init_2():
"""See if get_init can find __init__.pyw in this testdir"""
with make_tempfile(join(TMP_TEST_DIR, "__init__.pyw")):
assert mp.get_init(TMP_TEST_DIR)
def test_get_init_3():
"""get_init can't find __init__.pyc in this testdir"""
with make_tempfile(join(TMP_TEST_DIR, "__init__.pyc")):
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 nt.assert_is_none(mp.get_init(TMP_TEST_DIR))
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
Thomas Kluyver
Remove unused imports in IPython.utils
r11127 def test_get_init_4():
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 """get_init can't find __init__ in empty testdir"""
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 nt.assert_is_none(mp.get_init(TMP_TEST_DIR))
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_mod_1():
modpath = join(TMP_TEST_DIR, "xmod", "__init__.py")
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 nt.assert_equal(mp.find_mod("xmod"), modpath)
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_mod_2():
modpath = join(TMP_TEST_DIR, "xmod", "__init__.py")
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 nt.assert_equal(mp.find_mod("xmod"), modpath)
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_mod_3():
modpath = join(TMP_TEST_DIR, "xmod", "sub.py")
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 nt.assert_equal(mp.find_mod("xmod.sub"), modpath)
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_mod_4():
modpath = join(TMP_TEST_DIR, "pack.py")
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 nt.assert_equal(mp.find_mod("pack"), modpath)
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_mod_5():
Matthias Bussonnier
fix test for pyc file modules
r21354 modpath = join(TMP_TEST_DIR, "packpyc.pyc")
nt.assert_equal(mp.find_mod("packpyc"), modpath)
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_module_1():
modpath = join(TMP_TEST_DIR, "xmod")
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 nt.assert_equal(mp.find_module("xmod"), modpath)
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_module_2():
"""Testing sys.path that is empty"""
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 nt.assert_is_none(mp.find_module("xmod", []))
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_module_3():
"""Testing sys.path that is empty"""
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 nt.assert_is_none(mp.find_module(None, None))
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_module_4():
"""Testing sys.path that is empty"""
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 nt.assert_is_none(mp.find_module(None))
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
def test_find_module_5():
Matthias Bussonnier
Use nt.assert_* for better error messages
r21352 nt.assert_is_none(mp.find_module("xmod.nopack"))