Show More
@@ -20,11 +20,11 b' Authors' | |||||
20 | # Imports |
|
20 | # Imports | |
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 |
|
22 | |||
23 | import os |
|
|||
24 | import shutil |
|
23 | import shutil | |
25 | import sys |
|
24 | import sys | |
26 | import tempfile |
|
25 | import tempfile | |
27 |
|
26 | |||
|
27 | from pathlib import Path | |||
28 | from unittest import TestCase |
|
28 | from unittest import TestCase | |
29 |
|
29 | |||
30 | import nose.tools as nt |
|
30 | import nose.tools as nt | |
@@ -40,9 +40,9 b' from IPython.utils.tempdir import TemporaryDirectory' | |||||
40 | #----------------------------------------------------------------------------- |
|
40 | #----------------------------------------------------------------------------- | |
41 | # Globals |
|
41 | # Globals | |
42 | #----------------------------------------------------------------------------- |
|
42 | #----------------------------------------------------------------------------- | |
43 | TMP_TEST_DIR = tempfile.mkdtemp() |
|
43 | TMP_TEST_DIR = Path(tempfile.mkdtemp()) | |
44 |
HOME_TEST_DIR = |
|
44 | HOME_TEST_DIR = TMP_TEST_DIR / "home_test_dir" | |
45 |
IP_TEST_DIR = |
|
45 | IP_TEST_DIR = HOME_TEST_DIR / ".ipython" | |
46 |
|
46 | |||
47 | # |
|
47 | # | |
48 | # Setup/teardown functions/decorators |
|
48 | # Setup/teardown functions/decorators | |
@@ -55,7 +55,7 b' def setup_module():' | |||||
55 | """ |
|
55 | """ | |
56 | # Do not mask exceptions here. In particular, catching WindowsError is a |
|
56 | # Do not mask exceptions here. In particular, catching WindowsError is a | |
57 | # problem because that exception is only defined on Windows... |
|
57 | # problem because that exception is only defined on Windows... | |
58 | os.makedirs(IP_TEST_DIR) |
|
58 | (Path.cwd() / IP_TEST_DIR).mkdir(parents=True) | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | def teardown_module(): |
|
61 | def teardown_module(): | |
@@ -84,10 +84,10 b' def win32_without_pywin32():' | |||||
84 | class ProfileStartupTest(TestCase): |
|
84 | class ProfileStartupTest(TestCase): | |
85 | def setUp(self): |
|
85 | def setUp(self): | |
86 | # create profile dir |
|
86 | # create profile dir | |
87 |
self.pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, |
|
87 | self.pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, "test") | |
88 |
self.options = [ |
|
88 | self.options = ["--ipython-dir", IP_TEST_DIR, "--profile", "test"] | |
89 |
self.fname = |
|
89 | self.fname = TMP_TEST_DIR / "test.py" | |
90 |
|
90 | |||
91 | def tearDown(self): |
|
91 | def tearDown(self): | |
92 | # We must remove this profile right away so its presence doesn't |
|
92 | # We must remove this profile right away so its presence doesn't | |
93 | # confuse other tests. |
|
93 | # confuse other tests. | |
@@ -95,7 +95,7 b' class ProfileStartupTest(TestCase):' | |||||
95 |
|
95 | |||
96 | def init(self, startup_file, startup, test): |
|
96 | def init(self, startup_file, startup, test): | |
97 | # write startup python file |
|
97 | # write startup python file | |
98 |
with open( |
|
98 | with open(Path(self.pd.startup_dir) / startup_file, "w") as f: | |
99 | f.write(startup) |
|
99 | f.write(startup) | |
100 | # write simple test file, to check that the startup file was run |
|
100 | # write simple test file, to check that the startup file was run | |
101 | with open(self.fname, 'w') as f: |
|
101 | with open(self.fname, 'w') as f: | |
@@ -118,13 +118,13 b' class ProfileStartupTest(TestCase):' | |||||
118 | def test_list_profiles_in(): |
|
118 | def test_list_profiles_in(): | |
119 | # No need to remove these directories and files, as they will get nuked in |
|
119 | # No need to remove these directories and files, as they will get nuked in | |
120 | # the module-level teardown. |
|
120 | # the module-level teardown. | |
121 | td = tempfile.mkdtemp(dir=TMP_TEST_DIR) |
|
121 | td = Path(tempfile.mkdtemp(dir=TMP_TEST_DIR)) | |
122 |
for name in ( |
|
122 | for name in ("profile_foo", "profile_hello", "not_a_profile"): | |
123 | os.mkdir(os.path.join(td, name)) |
|
123 | Path(td / name).mkdir(parents=True) | |
124 | if dec.unicode_paths: |
|
124 | if dec.unicode_paths: | |
125 | os.mkdir(os.path.join(td, u'profile_ünicode')) |
|
125 | Path(td / u"profile_ünicode").mkdir(parents=True) | |
126 |
|
126 | |||
127 |
with open( |
|
127 | with open(td / "profile_file", "w") as f: | |
128 | f.write("I am not a profile directory") |
|
128 | f.write("I am not a profile directory") | |
129 | profiles = list_profiles_in(td) |
|
129 | profiles = list_profiles_in(td) | |
130 |
|
130 | |||
@@ -152,10 +152,19 b' def test_list_bundled_profiles():' | |||||
152 | def test_profile_create_ipython_dir(): |
|
152 | def test_profile_create_ipython_dir(): | |
153 | """ipython profile create respects --ipython-dir""" |
|
153 | """ipython profile create respects --ipython-dir""" | |
154 | with TemporaryDirectory() as td: |
|
154 | with TemporaryDirectory() as td: | |
155 | getoutput([sys.executable, '-m', 'IPython', 'profile', 'create', |
|
155 | getoutput( | |
156 | 'foo', '--ipython-dir=%s' % td]) |
|
156 | [ | |
157 | profile_dir = os.path.join(td, 'profile_foo') |
|
157 | sys.executable, | |
158 | assert os.path.exists(profile_dir) |
|
158 | "-m", | |
159 | ipython_config = os.path.join(profile_dir, 'ipython_config.py') |
|
159 | "IPython", | |
160 | assert os.path.exists(ipython_config) |
|
160 | "profile", | |
|
161 | "create", | |||
|
162 | "foo", | |||
|
163 | "--ipython-dir=%s" % td, | |||
|
164 | ] | |||
|
165 | ) | |||
|
166 | profile_dir = Path(td) / "profile_foo" | |||
|
167 | assert Path(profile_dir).exists() | |||
|
168 | ipython_config = profile_dir / "ipython_config.py" | |||
|
169 | assert Path(ipython_config).exists() | |||
161 |
|
170 |
General Comments 0
You need to be logged in to leave comments.
Login now