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