##// END OF EJS Templates
[utils][tests][module_paths] Remove nose
Samuel Gaist -
Show More
@@ -1,111 +1,109 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 import shutil
15 import shutil
16 import sys
16 import sys
17 import tempfile
17 import tempfile
18
18
19 from pathlib import Path
19 from pathlib import Path
20
20
21 from IPython.testing.tools import make_tempfile
21 from IPython.testing.tools import make_tempfile
22
22
23 import IPython.utils.module_paths as mp
23 import IPython.utils.module_paths as mp
24
24
25 import nose.tools as nt
26
27 TEST_FILE_PATH = Path(__file__).resolve().parent
25 TEST_FILE_PATH = Path(__file__).resolve().parent
28
26
29 TMP_TEST_DIR = Path(tempfile.mkdtemp(suffix="with.dot"))
27 TMP_TEST_DIR = Path(tempfile.mkdtemp(suffix="with.dot"))
30 #
28 #
31 # Setup/teardown functions/decorators
29 # Setup/teardown functions/decorators
32 #
30 #
33
31
34 old_syspath = sys.path
32 old_syspath = sys.path
35
33
36 def make_empty_file(fname):
34 def make_empty_file(fname):
37 open(fname, 'w').close()
35 open(fname, 'w').close()
38
36
39
37
40 def setup_module():
38 def setup_module():
41 """Setup testenvironment for the module:
39 """Setup testenvironment for the module:
42
40
43 """
41 """
44 # Do not mask exceptions here. In particular, catching WindowsError is a
42 # Do not mask exceptions here. In particular, catching WindowsError is a
45 # problem because that exception is only defined on Windows...
43 # problem because that exception is only defined on Windows...
46 Path(TMP_TEST_DIR / "xmod").mkdir(parents=True)
44 Path(TMP_TEST_DIR / "xmod").mkdir(parents=True)
47 Path(TMP_TEST_DIR / "nomod").mkdir(parents=True)
45 Path(TMP_TEST_DIR / "nomod").mkdir(parents=True)
48 make_empty_file(TMP_TEST_DIR / "xmod/__init__.py")
46 make_empty_file(TMP_TEST_DIR / "xmod/__init__.py")
49 make_empty_file(TMP_TEST_DIR / "xmod/sub.py")
47 make_empty_file(TMP_TEST_DIR / "xmod/sub.py")
50 make_empty_file(TMP_TEST_DIR / "pack.py")
48 make_empty_file(TMP_TEST_DIR / "pack.py")
51 make_empty_file(TMP_TEST_DIR / "packpyc.pyc")
49 make_empty_file(TMP_TEST_DIR / "packpyc.pyc")
52 sys.path = [str(TMP_TEST_DIR)]
50 sys.path = [str(TMP_TEST_DIR)]
53
51
54 def teardown_module():
52 def teardown_module():
55 """Teardown testenvironment for the module:
53 """Teardown testenvironment for the module:
56
54
57 - Remove tempdir
55 - Remove tempdir
58 - restore sys.path
56 - restore sys.path
59 """
57 """
60 # Note: we remove the parent test dir, which is the root of all test
58 # Note: we remove the parent test dir, which is the root of all test
61 # subdirs we may have created. Use shutil instead of os.removedirs, so
59 # subdirs we may have created. Use shutil instead of os.removedirs, so
62 # that non-empty directories are all recursively removed.
60 # that non-empty directories are all recursively removed.
63 shutil.rmtree(TMP_TEST_DIR)
61 shutil.rmtree(TMP_TEST_DIR)
64 sys.path = old_syspath
62 sys.path = old_syspath
65
63
66 def test_tempdir():
64 def test_tempdir():
67 """
65 """
68 Ensure the test are done with a temporary file that have a dot somewhere.
66 Ensure the test are done with a temporary file that have a dot somewhere.
69 """
67 """
70 nt.assert_in(".", str(TMP_TEST_DIR))
68 assert "." in str(TMP_TEST_DIR)
71
69
72
70
73 def test_find_mod_1():
71 def test_find_mod_1():
74 """
72 """
75 Search for a directory's file path.
73 Search for a directory's file path.
76 Expected output: a path to that directory's __init__.py file.
74 Expected output: a path to that directory's __init__.py file.
77 """
75 """
78 modpath = TMP_TEST_DIR / "xmod" / "__init__.py"
76 modpath = TMP_TEST_DIR / "xmod" / "__init__.py"
79 nt.assert_equal(Path(mp.find_mod("xmod")), modpath)
77 assert Path(mp.find_mod("xmod")) == modpath
80
78
81 def test_find_mod_2():
79 def test_find_mod_2():
82 """
80 """
83 Search for a directory's file path.
81 Search for a directory's file path.
84 Expected output: a path to that directory's __init__.py file.
82 Expected output: a path to that directory's __init__.py file.
85 TODO: Confirm why this is a duplicate test.
83 TODO: Confirm why this is a duplicate test.
86 """
84 """
87 modpath = TMP_TEST_DIR / "xmod" / "__init__.py"
85 modpath = TMP_TEST_DIR / "xmod" / "__init__.py"
88 nt.assert_equal(Path(mp.find_mod("xmod")), modpath)
86 assert Path(mp.find_mod("xmod")) == modpath
89
87
90 def test_find_mod_3():
88 def test_find_mod_3():
91 """
89 """
92 Search for a directory + a filename without its .py extension
90 Search for a directory + a filename without its .py extension
93 Expected output: full path with .py extension.
91 Expected output: full path with .py extension.
94 """
92 """
95 modpath = TMP_TEST_DIR / "xmod" / "sub.py"
93 modpath = TMP_TEST_DIR / "xmod" / "sub.py"
96 nt.assert_equal(Path(mp.find_mod("xmod.sub")), modpath)
94 assert Path(mp.find_mod("xmod.sub")) == modpath
97
95
98 def test_find_mod_4():
96 def test_find_mod_4():
99 """
97 """
100 Search for a filename without its .py extension
98 Search for a filename without its .py extension
101 Expected output: full path with .py extension
99 Expected output: full path with .py extension
102 """
100 """
103 modpath = TMP_TEST_DIR / "pack.py"
101 modpath = TMP_TEST_DIR / "pack.py"
104 nt.assert_equal(Path(mp.find_mod("pack")), modpath)
102 assert Path(mp.find_mod("pack")) == modpath
105
103
106 def test_find_mod_5():
104 def test_find_mod_5():
107 """
105 """
108 Search for a filename with a .pyc extension
106 Search for a filename with a .pyc extension
109 Expected output: TODO: do we exclude or include .pyc files?
107 Expected output: TODO: do we exclude or include .pyc files?
110 """
108 """
111 nt.assert_equal(mp.find_mod("packpyc"), None)
109 assert mp.find_mod("packpyc") == None
General Comments 0
You need to be logged in to leave comments. Login now