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