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