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