Show More
@@ -12,13 +12,11 b'' | |||
|
12 | 12 | # Imports |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | ||
|
16 | import os | |
|
17 | 15 | import shutil |
|
18 | 16 | import sys |
|
19 | 17 | import tempfile |
|
20 | 18 | |
|
21 |
from |
|
|
19 | from pathlib import Path | |
|
22 | 20 | |
|
23 | 21 | from IPython.testing.tools import make_tempfile |
|
24 | 22 | |
@@ -26,10 +24,9 b' import IPython.utils.module_paths as mp' | |||
|
26 | 24 | |
|
27 | 25 | import nose.tools as nt |
|
28 | 26 | |
|
29 | env = os.environ | |
|
30 | TEST_FILE_PATH = split(abspath(__file__))[0] | |
|
27 | TEST_FILE_PATH = Path(__file__).resolve().parent | |
|
31 | 28 | |
|
32 |
TMP_TEST_DIR = tempfile.mkdtemp(suffix= |
|
|
29 | TMP_TEST_DIR = Path(tempfile.mkdtemp(suffix="with.dot")) | |
|
33 | 30 | # |
|
34 | 31 | # Setup/teardown functions/decorators |
|
35 | 32 | # |
@@ -46,13 +43,13 b' def setup_module():' | |||
|
46 | 43 | """ |
|
47 | 44 | # Do not mask exceptions here. In particular, catching WindowsError is a |
|
48 | 45 | # problem because that exception is only defined on Windows... |
|
49 | os.makedirs(join(TMP_TEST_DIR, "xmod")) | |
|
50 | os.makedirs(join(TMP_TEST_DIR, "nomod")) | |
|
51 |
make_empty_file( |
|
|
52 |
make_empty_file( |
|
|
53 |
make_empty_file( |
|
|
54 |
make_empty_file( |
|
|
55 | sys.path = [TMP_TEST_DIR] | |
|
46 | Path(TMP_TEST_DIR / "xmod").mkdir(parents=True) | |
|
47 | Path(TMP_TEST_DIR / "nomod").mkdir(parents=True) | |
|
48 | make_empty_file(TMP_TEST_DIR / "xmod/__init__.py") | |
|
49 | make_empty_file(TMP_TEST_DIR / "xmod/sub.py") | |
|
50 | make_empty_file(TMP_TEST_DIR / "pack.py") | |
|
51 | make_empty_file(TMP_TEST_DIR / "packpyc.pyc") | |
|
52 | sys.path = [str(TMP_TEST_DIR)] | |
|
56 | 53 | |
|
57 | 54 | def teardown_module(): |
|
58 | 55 | """Teardown testenvironment for the module: |
@@ -70,7 +67,7 b' def test_tempdir():' | |||
|
70 | 67 | """ |
|
71 | 68 | Ensure the test are done with a temporary file that have a dot somewhere. |
|
72 | 69 | """ |
|
73 |
nt.assert_in( |
|
|
70 | nt.assert_in(".", str(TMP_TEST_DIR)) | |
|
74 | 71 | |
|
75 | 72 | |
|
76 | 73 | def test_find_mod_1(): |
@@ -78,8 +75,8 b' def test_find_mod_1():' | |||
|
78 | 75 | Search for a directory's file path. |
|
79 | 76 | Expected output: a path to that directory's __init__.py file. |
|
80 | 77 | """ |
|
81 |
modpath = |
|
|
82 | nt.assert_equal(mp.find_mod("xmod"), modpath) | |
|
78 | modpath = TMP_TEST_DIR / "xmod" / "__init__.py" | |
|
79 | nt.assert_equal(Path(mp.find_mod("xmod")), modpath) | |
|
83 | 80 | |
|
84 | 81 | def test_find_mod_2(): |
|
85 | 82 | """ |
@@ -87,24 +84,24 b' def test_find_mod_2():' | |||
|
87 | 84 | Expected output: a path to that directory's __init__.py file. |
|
88 | 85 | TODO: Confirm why this is a duplicate test. |
|
89 | 86 | """ |
|
90 |
modpath = |
|
|
91 | nt.assert_equal(mp.find_mod("xmod"), modpath) | |
|
87 | modpath = TMP_TEST_DIR / "xmod" / "__init__.py" | |
|
88 | nt.assert_equal(Path(mp.find_mod("xmod")), modpath) | |
|
92 | 89 | |
|
93 | 90 | def test_find_mod_3(): |
|
94 | 91 | """ |
|
95 | 92 | Search for a directory + a filename without its .py extension |
|
96 | 93 | Expected output: full path with .py extension. |
|
97 | 94 | """ |
|
98 |
modpath = |
|
|
99 | nt.assert_equal(mp.find_mod("xmod.sub"), modpath) | |
|
95 | modpath = TMP_TEST_DIR / "xmod" / "sub.py" | |
|
96 | nt.assert_equal(Path(mp.find_mod("xmod.sub")), modpath) | |
|
100 | 97 | |
|
101 | 98 | def test_find_mod_4(): |
|
102 | 99 | """ |
|
103 | 100 | Search for a filename without its .py extension |
|
104 | 101 | Expected output: full path with .py extension |
|
105 | 102 | """ |
|
106 |
modpath = |
|
|
107 | nt.assert_equal(mp.find_mod("pack"), modpath) | |
|
103 | modpath = TMP_TEST_DIR / "pack.py" | |
|
104 | nt.assert_equal(Path(mp.find_mod("pack")), modpath) | |
|
108 | 105 | |
|
109 | 106 | def test_find_mod_5(): |
|
110 | 107 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now