##// END OF EJS Templates
test with dot
Matthias Bussonnier -
Show More
@@ -1,107 +1,115 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """Tests for IPython.utils.module_paths.py"""
2 """Tests for IPython.utils.module_paths.py"""
3
3
4 #-----------------------------------------------------------------------------
4 #-----------------------------------------------------------------------------
5 # Copyright (C) 2008-2011 The IPython Development Team
5 # Copyright (C) 2008-2011 The IPython Development Team
6 #
6 #
7 # Distributed under the terms of the BSD License. The full license is in
7 # Distributed under the terms of the BSD License. The full license is in
8 # the file COPYING, distributed as part of this software.
8 # the file COPYING, distributed as part of this software.
9 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
10
10
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15
15
16 import os
16 import os
17 import shutil
17 import shutil
18 import sys
18 import sys
19 import tempfile
19 import tempfile
20
20
21 from os.path import join, abspath, split
21 from os.path import join, abspath, split
22
22
23 from IPython.testing.tools import make_tempfile
23 from IPython.testing.tools import make_tempfile
24
24
25 import IPython.utils.module_paths as mp
25 import IPython.utils.module_paths as mp
26
26
27 import nose.tools as nt
27 import nose.tools as nt
28
28
29 env = os.environ
29 env = os.environ
30 TEST_FILE_PATH = split(abspath(__file__))[0]
30 TEST_FILE_PATH = split(abspath(__file__))[0]
31 TMP_TEST_DIR = tempfile.mkdtemp()
31
32 TMP_TEST_DIR = tempfile.mkdtemp(suffix='with.dot')
32 #
33 #
33 # Setup/teardown functions/decorators
34 # Setup/teardown functions/decorators
34 #
35 #
35
36
36 old_syspath = sys.path
37 old_syspath = sys.path
37
38
38 def make_empty_file(fname):
39 def make_empty_file(fname):
39 f = open(fname, 'w')
40 f = open(fname, 'w')
40 f.close()
41 f.close()
41
42
42
43
43 def setup():
44 def setup():
44 """Setup testenvironment for the module:
45 """Setup testenvironment for the module:
45
46
46 """
47 """
47 # Do not mask exceptions here. In particular, catching WindowsError is a
48 # Do not mask exceptions here. In particular, catching WindowsError is a
48 # problem because that exception is only defined on Windows...
49 # problem because that exception is only defined on Windows...
49 os.makedirs(join(TMP_TEST_DIR, "xmod"))
50 os.makedirs(join(TMP_TEST_DIR, "xmod"))
50 os.makedirs(join(TMP_TEST_DIR, "nomod"))
51 os.makedirs(join(TMP_TEST_DIR, "nomod"))
51 make_empty_file(join(TMP_TEST_DIR, "xmod/__init__.py"))
52 make_empty_file(join(TMP_TEST_DIR, "xmod/__init__.py"))
52 make_empty_file(join(TMP_TEST_DIR, "xmod/sub.py"))
53 make_empty_file(join(TMP_TEST_DIR, "xmod/sub.py"))
53 make_empty_file(join(TMP_TEST_DIR, "pack.py"))
54 make_empty_file(join(TMP_TEST_DIR, "pack.py"))
54 make_empty_file(join(TMP_TEST_DIR, "packpyc.pyc"))
55 make_empty_file(join(TMP_TEST_DIR, "packpyc.pyc"))
55 sys.path = [TMP_TEST_DIR]
56 sys.path = [TMP_TEST_DIR]
56
57
57 def teardown():
58 def teardown():
58 """Teardown testenvironment for the module:
59 """Teardown testenvironment for the module:
59
60
60 - Remove tempdir
61 - Remove tempdir
61 - restore sys.path
62 - restore sys.path
62 """
63 """
63 # Note: we remove the parent test dir, which is the root of all test
64 # Note: we remove the parent test dir, which is the root of all test
64 # subdirs we may have created. Use shutil instead of os.removedirs, so
65 # subdirs we may have created. Use shutil instead of os.removedirs, so
65 # that non-empty directories are all recursively removed.
66 # that non-empty directories are all recursively removed.
66 shutil.rmtree(TMP_TEST_DIR)
67 shutil.rmtree(TMP_TEST_DIR)
67 sys.path = old_syspath
68 sys.path = old_syspath
68
69
70 def test_tempdir():
71 """
72 Ensure the test are done with a temporary file that have a dot somewhere.
73 """
74 nt.assert_in('.',TMP_TEST_DIR)
75
76
69 def test_find_mod_1():
77 def test_find_mod_1():
70 """
78 """
71 Search for a directory's file path.
79 Search for a directory's file path.
72 Expected output: a path to that directory's __init__.py file.
80 Expected output: a path to that directory's __init__.py file.
73 """
81 """
74 modpath = join(TMP_TEST_DIR, "xmod", "__init__.py")
82 modpath = join(TMP_TEST_DIR, "xmod", "__init__.py")
75 nt.assert_equal(mp.find_mod("xmod"), modpath)
83 nt.assert_equal(mp.find_mod("xmod"), modpath)
76
84
77 def test_find_mod_2():
85 def test_find_mod_2():
78 """
86 """
79 Search for a directory's file path.
87 Search for a directory's file path.
80 Expected output: a path to that directory's __init__.py file.
88 Expected output: a path to that directory's __init__.py file.
81 TODO: Confirm why this is a duplicate test.
89 TODO: Confirm why this is a duplicate test.
82 """
90 """
83 modpath = join(TMP_TEST_DIR, "xmod", "__init__.py")
91 modpath = join(TMP_TEST_DIR, "xmod", "__init__.py")
84 nt.assert_equal(mp.find_mod("xmod"), modpath)
92 nt.assert_equal(mp.find_mod("xmod"), modpath)
85
93
86 def test_find_mod_3():
94 def test_find_mod_3():
87 """
95 """
88 Search for a directory + a filename without its .py extension
96 Search for a directory + a filename without its .py extension
89 Expected output: full path with .py extension.
97 Expected output: full path with .py extension.
90 """
98 """
91 modpath = join(TMP_TEST_DIR, "xmod", "sub.py")
99 modpath = join(TMP_TEST_DIR, "xmod", "sub.py")
92 nt.assert_equal(mp.find_mod("xmod.sub"), modpath)
100 nt.assert_equal(mp.find_mod("xmod.sub"), modpath)
93
101
94 def test_find_mod_4():
102 def test_find_mod_4():
95 """
103 """
96 Search for a filename without its .py extension
104 Search for a filename without its .py extension
97 Expected output: full path with .py extension
105 Expected output: full path with .py extension
98 """
106 """
99 modpath = join(TMP_TEST_DIR, "pack.py")
107 modpath = join(TMP_TEST_DIR, "pack.py")
100 nt.assert_equal(mp.find_mod("pack"), modpath)
108 nt.assert_equal(mp.find_mod("pack"), modpath)
101
109
102 def test_find_mod_5():
110 def test_find_mod_5():
103 """
111 """
104 Search for a filename with a .pyc extension
112 Search for a filename with a .pyc extension
105 Expected output: TODO: do we exclude or include .pyc files?
113 Expected output: TODO: do we exclude or include .pyc files?
106 """
114 """
107 nt.assert_equal(mp.find_mod("packpyc"), None)
115 nt.assert_equal(mp.find_mod("packpyc"), None)
General Comments 0
You need to be logged in to leave comments. Login now