##// END OF EJS Templates
refine wording, and document ptk pin
refine wording, and document ptk pin

File last commit:

r27639:c55dbf99
r28132:a6d2c5f6
Show More
test_profile.py
155 lines | 4.9 KiB | text/x-python | PythonLexer
Fernando Perez
Add improved test with unicode checks, by Min.
r6206 # coding: utf-8
MinRK
add test_profile with startup tests...
r5250 """Tests for profile-related functions.
Currently only the startup-dir functionality is tested, but more tests should
be added for:
* ipython profile create
* ipython profile list
* ipython profile create --parallel
* security dir permissions
Authors
-------
* MinRK
"""
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import shutil
import sys
import tempfile
dswij
os.path replaced with pathlib on test_profile.py
r26120 from pathlib import Path
Fernando Perez
Refactor tests to fix leftover profiles that would collide with other tests.
r6203 from unittest import TestCase
Matthias Bussonnier
MAINT: cleanup imports of tempdir....
r27509 from tempfile import TemporaryDirectory
MinRK
add test_profile with startup tests...
r5250
Matthias Bussonnier
MAINT: cleanup imports of tempdir....
r27509 from IPython.core.profileapp import list_bundled_profiles, list_profiles_in
from IPython.core.profiledir import ProfileDir
MinRK
add test_profile with startup tests...
r5250 from IPython.testing import decorators as dec
from IPython.testing import tools as tt
MinRK
`ipython profile create` respects `--ipython-dir`...
r14898 from IPython.utils.process import getoutput
MinRK
add test_profile with startup tests...
r5250
#-----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
dswij
os.path replaced with pathlib on test_profile.py
r26120 TMP_TEST_DIR = Path(tempfile.mkdtemp())
HOME_TEST_DIR = TMP_TEST_DIR / "home_test_dir"
IP_TEST_DIR = HOME_TEST_DIR / ".ipython"
MinRK
add test_profile with startup tests...
r5250
#
# Setup/teardown functions/decorators
#
Matthias Bussonnier
Use module level setup and teardown compatible both nose and pytest....
r25082 def setup_module():
MinRK
add test_profile with startup tests...
r5250 """Setup test environment for the module:
- Adds dummy home dir tree
"""
# Do not mask exceptions here. In particular, catching WindowsError is a
# problem because that exception is only defined on Windows...
dswij
os.path replaced with pathlib on test_profile.py
r26120 (Path.cwd() / IP_TEST_DIR).mkdir(parents=True)
MinRK
add test_profile with startup tests...
r5250
Matthias Bussonnier
Use module level setup and teardown compatible both nose and pytest....
r25082 def teardown_module():
MinRK
add test_profile with startup tests...
r5250 """Teardown test environment for the module:
- Remove dummy home dir tree
"""
# Note: we remove the parent test dir, which is the root of all test
# subdirs we may have created. Use shutil instead of os.removedirs, so
# that non-empty directories are all recursively removed.
shutil.rmtree(TMP_TEST_DIR)
#-----------------------------------------------------------------------------
# Test functions
#-----------------------------------------------------------------------------
Fernando Perez
Add test for list_profiles_in
r6204 class ProfileStartupTest(TestCase):
Fernando Perez
Refactor tests to fix leftover profiles that would collide with other tests.
r6203 def setUp(self):
# create profile dir
dswij
os.path replaced with pathlib on test_profile.py
r26120 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"
Fernando Perez
Refactor tests to fix leftover profiles that would collide with other tests.
r6203 def tearDown(self):
Fernando Perez
Add test for list_profiles_in
r6204 # We must remove this profile right away so its presence doesn't
# confuse other tests.
Fernando Perez
Refactor tests to fix leftover profiles that would collide with other tests.
r6203 shutil.rmtree(self.pd.location)
def init(self, startup_file, startup, test):
# write startup python file
gousaiyang
Format code
r27495 with open(Path(self.pd.startup_dir) / startup_file, "w", encoding="utf-8") as f:
Fernando Perez
Refactor tests to fix leftover profiles that would collide with other tests.
r6203 f.write(startup)
# write simple test file, to check that the startup file was run
gousaiyang
Format code
r27495 with open(self.fname, "w", encoding="utf-8") as f:
Matthias Bussonnier
remove some py3compat usage
r24265 f.write(test)
Fernando Perez
Refactor tests to fix leftover profiles that would collide with other tests.
r6203
def validate(self, output):
Nikita Kniazev
Add Path support to ipexec
r27014 tt.ipexec_validate(self.fname, output, "", options=self.options)
Fernando Perez
Refactor tests to fix leftover profiles that would collide with other tests.
r6203
def test_startup_py(self):
Matthias Bussonnier
remove some py3compat usage
r24265 self.init('00-start.py', 'zzz=123\n', 'print(zzz)\n')
Fernando Perez
Refactor tests to fix leftover profiles that would collide with other tests.
r6203 self.validate('123')
def test_startup_ipy(self):
Susan Tan
Fixed #4580 -- Deprecated %profile.
r13988 self.init('00-start.ipy', '%xmode plain\n', '')
self.validate('Exception reporting mode: Plain')
Fernando Perez
Add test for list_profiles_in
r6204
Samuel Gaist
[core][tests][profile] Remove nose
r26906
Fernando Perez
Add test for list_profiles_in
r6204 def test_list_profiles_in():
# No need to remove these directories and files, as they will get nuked in
# the module-level teardown.
dswij
os.path replaced with pathlib on test_profile.py
r26120 td = Path(tempfile.mkdtemp(dir=TMP_TEST_DIR))
for name in ("profile_foo", "profile_hello", "not_a_profile"):
Path(td / name).mkdir(parents=True)
Thomas Kluyver
Skip some more tests that require unicode paths
r12168 if dec.unicode_paths:
Matthias Bussonnier
typo and reformat
r27639 Path(td / "profile_ünicode").mkdir(parents=True)
dswij
os.path replaced with pathlib on test_profile.py
r26120
gousaiyang
Format code
r27495 with open(td / "profile_file", "w", encoding="utf-8") as f:
Fernando Perez
Add improved test with unicode checks, by Min.
r6206 f.write("I am not a profile directory")
profiles = list_profiles_in(td)
Samuel Gaist
[core][tests][profile] Remove nose
r26906
Fernando Perez
Add improved test with unicode checks, by Min.
r6206 # unicode normalization can turn u'ünicode' into u'u\0308nicode',
# so only check for *nicode, and that creating a ProfileDir from the
# name remains valid
found_unicode = False
for p in list(profiles):
if p.endswith('nicode'):
pd = ProfileDir.find_profile_dir_by_name(td, p)
profiles.remove(p)
found_unicode = True
break
Thomas Kluyver
Skip some more tests that require unicode paths
r12168 if dec.unicode_paths:
Samuel Gaist
[core][tests][profile] Remove nose
r26906 assert found_unicode is True
assert set(profiles) == {"foo", "hello"}
Fernando Perez
Add improved test with unicode checks, by Min.
r6206
Fernando Perez
Add test for list_profiles_in
r6204
Fernando Perez
Add test for list_bundled_profiles
r6205 def test_list_bundled_profiles():
# This variable will need to be updated when a new profile gets bundled
bundled = sorted(list_bundled_profiles())
Samuel Gaist
[core][tests][profile] Remove nose
r26906 assert bundled == []
MinRK
`ipython profile create` respects `--ipython-dir`...
r14898
def test_profile_create_ipython_dir():
"""ipython profile create respects --ipython-dir"""
with TemporaryDirectory() as td:
dswij
os.path replaced with pathlib on test_profile.py
r26120 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()