##// END OF EJS Templates
Remove 5s wait on inactivity on GUI inputhook loops...
Remove 5s wait on inactivity on GUI inputhook loops The 5s (and 1s) waits were originally added in commit 5074878, but the 5 second wait meant if you left the console for 5+ minutes idle, it would take up to 5 seconds for a response to a keypress. This tradeoff of CPU cycles for battery life seems too far. Note that commit 5074878 was originally for wx, glut and pyglet are based on the wx version and came into existence after commit 5074878.

File last commit:

r12168:706dd916
r13125:f9e20986
Show More
test_profile.py
153 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
"""
from __future__ import absolute_import
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import os
import shutil
import sys
import tempfile
Fernando Perez
Refactor tests to fix leftover profiles that would collide with other tests.
r6203 from unittest import TestCase
MinRK
add test_profile with startup tests...
r5250 import nose.tools as nt
Fernando Perez
Refactor tests to fix leftover profiles that would collide with other tests.
r6203 from IPython.core.profileapp import list_profiles_in, list_bundled_profiles
MinRK
add test_profile with startup tests...
r5250 from IPython.core.profiledir import ProfileDir
from IPython.testing import decorators as dec
from IPython.testing import tools as tt
from IPython.utils import py3compat
#-----------------------------------------------------------------------------
# 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')
#
# Setup/teardown functions/decorators
#
def setup():
"""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...
os.makedirs(IP_TEST_DIR)
def teardown():
"""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
#-----------------------------------------------------------------------------
MinRK
minor test fixes for win32
r5297 def win32_without_pywin32():
if sys.platform == 'win32':
try:
import pywin32
except ImportError:
return True
return False
MinRK
add test_profile with startup tests...
r5250
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
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')
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
with open(os.path.join(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:
f.write(py3compat.doctest_refactor_print(test))
def validate(self, output):
tt.ipexec_validate(self.fname, output, '', options=self.options)
@dec.skipif(win32_without_pywin32(), "Test requires pywin32 on Windows")
def test_startup_py(self):
self.init('00-start.py', 'zzz=123\n',
py3compat.doctest_refactor_print('print zzz\n'))
self.validate('123')
@dec.skipif(win32_without_pywin32(), "Test requires pywin32 on Windows")
def test_startup_ipy(self):
self.init('00-start.ipy', '%profile\n', '')
self.validate('test')
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.
Fernando Perez
Add improved test with unicode checks, by Min.
r6206 td = tempfile.mkdtemp(dir=TMP_TEST_DIR)
td = py3compat.str_to_unicode(td)
Thomas Kluyver
Skip some more tests that require unicode paths
r12168 for name in ('profile_foo', 'profile_hello', 'not_a_profile'):
Fernando Perez
Add improved test with unicode checks, by Min.
r6206 os.mkdir(os.path.join(td, name))
Thomas Kluyver
Skip some more tests that require unicode paths
r12168 if dec.unicode_paths:
os.mkdir(os.path.join(td, u'profile_ünicode'))
Fernando Perez
Add improved test with unicode checks, by Min.
r6206 with open(os.path.join(td, 'profile_file'), 'w') as f:
f.write("I am not a profile directory")
profiles = list_profiles_in(td)
Fernando Perez
Add test for list_profiles_in
r6204
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:
nt.assert_true(found_unicode)
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(set(profiles), set(['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
Thomas Kluyver
Remove unused python3 profile.
r6490 bundled_true = [u'cluster', u'math', u'pysh', u'sympy']
Fernando Perez
Add test for list_bundled_profiles
r6205 bundled = sorted(list_bundled_profiles())
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(bundled, bundled_true)