diff --git a/IPython/core/tests/test_profile.py b/IPython/core/tests/test_profile.py index e63fb3e..f18a064 100644 --- a/IPython/core/tests/test_profile.py +++ b/IPython/core/tests/test_profile.py @@ -20,11 +20,11 @@ Authors # Imports #----------------------------------------------------------------------------- -import os import shutil import sys import tempfile +from pathlib import Path from unittest import TestCase import nose.tools as nt @@ -40,9 +40,9 @@ from IPython.utils.tempdir import TemporaryDirectory #----------------------------------------------------------------------------- # Globals #----------------------------------------------------------------------------- -TMP_TEST_DIR = tempfile.mkdtemp() -HOME_TEST_DIR = os.path.join(TMP_TEST_DIR, "home_test_dir") -IP_TEST_DIR = os.path.join(HOME_TEST_DIR,'.ipython') +TMP_TEST_DIR = Path(tempfile.mkdtemp()) +HOME_TEST_DIR = TMP_TEST_DIR / "home_test_dir" +IP_TEST_DIR = HOME_TEST_DIR / ".ipython" # # Setup/teardown functions/decorators @@ -55,7 +55,7 @@ def setup_module(): """ # Do not mask exceptions here. In particular, catching WindowsError is a # problem because that exception is only defined on Windows... - os.makedirs(IP_TEST_DIR) + (Path.cwd() / IP_TEST_DIR).mkdir(parents=True) def teardown_module(): @@ -84,10 +84,10 @@ def win32_without_pywin32(): class ProfileStartupTest(TestCase): def setUp(self): # create profile dir - self.pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test') - self.options = ['--ipython-dir', IP_TEST_DIR, '--profile', 'test'] - self.fname = os.path.join(TMP_TEST_DIR, 'test.py') - + self.pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, "test") + self.options = ["--ipython-dir", IP_TEST_DIR, "--profile", "test"] + self.fname = TMP_TEST_DIR / "test.py" + def tearDown(self): # We must remove this profile right away so its presence doesn't # confuse other tests. @@ -95,7 +95,7 @@ class ProfileStartupTest(TestCase): def init(self, startup_file, startup, test): # write startup python file - with open(os.path.join(self.pd.startup_dir, startup_file), 'w') as f: + with open(Path(self.pd.startup_dir) / startup_file, "w") as f: f.write(startup) # write simple test file, to check that the startup file was run with open(self.fname, 'w') as f: @@ -118,13 +118,13 @@ class ProfileStartupTest(TestCase): def test_list_profiles_in(): # No need to remove these directories and files, as they will get nuked in # the module-level teardown. - td = tempfile.mkdtemp(dir=TMP_TEST_DIR) - for name in ('profile_foo', 'profile_hello', 'not_a_profile'): - os.mkdir(os.path.join(td, name)) + td = Path(tempfile.mkdtemp(dir=TMP_TEST_DIR)) + for name in ("profile_foo", "profile_hello", "not_a_profile"): + Path(td / name).mkdir(parents=True) if dec.unicode_paths: - os.mkdir(os.path.join(td, u'profile_ünicode')) - - with open(os.path.join(td, 'profile_file'), 'w') as f: + Path(td / u"profile_ünicode").mkdir(parents=True) + + with open(td / "profile_file", "w") as f: f.write("I am not a profile directory") profiles = list_profiles_in(td) @@ -152,10 +152,19 @@ def test_list_bundled_profiles(): def test_profile_create_ipython_dir(): """ipython profile create respects --ipython-dir""" with TemporaryDirectory() as td: - getoutput([sys.executable, '-m', 'IPython', 'profile', 'create', - 'foo', '--ipython-dir=%s' % td]) - profile_dir = os.path.join(td, 'profile_foo') - assert os.path.exists(profile_dir) - ipython_config = os.path.join(profile_dir, 'ipython_config.py') - assert os.path.exists(ipython_config) + getoutput( + [ + sys.executable, + "-m", + "IPython", + "profile", + "create", + "foo", + "--ipython-dir=%s" % td, + ] + ) + profile_dir = Path(td) / "profile_foo" + assert Path(profile_dir).exists() + ipython_config = profile_dir / "ipython_config.py" + assert Path(ipython_config).exists()