##// END OF EJS Templates
Remove unused python3 profile.
Thomas Kluyver -
Show More
@@ -1,151 +1,151 b''
1 # coding: utf-8
1 # coding: utf-8
2 """Tests for profile-related functions.
2 """Tests for profile-related functions.
3
3
4 Currently only the startup-dir functionality is tested, but more tests should
4 Currently only the startup-dir functionality is tested, but more tests should
5 be added for:
5 be added for:
6
6
7 * ipython profile create
7 * ipython profile create
8 * ipython profile list
8 * ipython profile list
9 * ipython profile create --parallel
9 * ipython profile create --parallel
10 * security dir permissions
10 * security dir permissions
11
11
12 Authors
12 Authors
13 -------
13 -------
14
14
15 * MinRK
15 * MinRK
16
16
17 """
17 """
18 from __future__ import absolute_import
18 from __future__ import absolute_import
19
19
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21 # Imports
21 # Imports
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23
23
24 import os
24 import os
25 import shutil
25 import shutil
26 import sys
26 import sys
27 import tempfile
27 import tempfile
28
28
29 from unittest import TestCase
29 from unittest import TestCase
30
30
31 import nose.tools as nt
31 import nose.tools as nt
32 from nose import SkipTest
32 from nose import SkipTest
33
33
34 from IPython.core.profileapp import list_profiles_in, list_bundled_profiles
34 from IPython.core.profileapp import list_profiles_in, list_bundled_profiles
35 from IPython.core.profiledir import ProfileDir
35 from IPython.core.profiledir import ProfileDir
36
36
37 from IPython.testing import decorators as dec
37 from IPython.testing import decorators as dec
38 from IPython.testing import tools as tt
38 from IPython.testing import tools as tt
39 from IPython.utils import py3compat
39 from IPython.utils import py3compat
40
40
41
41
42 #-----------------------------------------------------------------------------
42 #-----------------------------------------------------------------------------
43 # Globals
43 # Globals
44 #-----------------------------------------------------------------------------
44 #-----------------------------------------------------------------------------
45 TMP_TEST_DIR = tempfile.mkdtemp()
45 TMP_TEST_DIR = tempfile.mkdtemp()
46 HOME_TEST_DIR = os.path.join(TMP_TEST_DIR, "home_test_dir")
46 HOME_TEST_DIR = os.path.join(TMP_TEST_DIR, "home_test_dir")
47 IP_TEST_DIR = os.path.join(HOME_TEST_DIR,'.ipython')
47 IP_TEST_DIR = os.path.join(HOME_TEST_DIR,'.ipython')
48
48
49 #
49 #
50 # Setup/teardown functions/decorators
50 # Setup/teardown functions/decorators
51 #
51 #
52
52
53 def setup():
53 def setup():
54 """Setup test environment for the module:
54 """Setup test environment for the module:
55
55
56 - Adds dummy home dir tree
56 - Adds dummy home dir tree
57 """
57 """
58 # Do not mask exceptions here. In particular, catching WindowsError is a
58 # Do not mask exceptions here. In particular, catching WindowsError is a
59 # problem because that exception is only defined on Windows...
59 # problem because that exception is only defined on Windows...
60 os.makedirs(IP_TEST_DIR)
60 os.makedirs(IP_TEST_DIR)
61
61
62
62
63 def teardown():
63 def teardown():
64 """Teardown test environment for the module:
64 """Teardown test environment for the module:
65
65
66 - Remove dummy home dir tree
66 - Remove dummy home dir tree
67 """
67 """
68 # Note: we remove the parent test dir, which is the root of all test
68 # Note: we remove the parent test dir, which is the root of all test
69 # subdirs we may have created. Use shutil instead of os.removedirs, so
69 # subdirs we may have created. Use shutil instead of os.removedirs, so
70 # that non-empty directories are all recursively removed.
70 # that non-empty directories are all recursively removed.
71 shutil.rmtree(TMP_TEST_DIR)
71 shutil.rmtree(TMP_TEST_DIR)
72
72
73
73
74 #-----------------------------------------------------------------------------
74 #-----------------------------------------------------------------------------
75 # Test functions
75 # Test functions
76 #-----------------------------------------------------------------------------
76 #-----------------------------------------------------------------------------
77 def win32_without_pywin32():
77 def win32_without_pywin32():
78 if sys.platform == 'win32':
78 if sys.platform == 'win32':
79 try:
79 try:
80 import pywin32
80 import pywin32
81 except ImportError:
81 except ImportError:
82 return True
82 return True
83 return False
83 return False
84
84
85
85
86 class ProfileStartupTest(TestCase):
86 class ProfileStartupTest(TestCase):
87 def setUp(self):
87 def setUp(self):
88 # create profile dir
88 # create profile dir
89 self.pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test')
89 self.pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test')
90 self.options = ['--ipython-dir', IP_TEST_DIR, '--profile', 'test']
90 self.options = ['--ipython-dir', IP_TEST_DIR, '--profile', 'test']
91 self.fname = os.path.join(TMP_TEST_DIR, 'test.py')
91 self.fname = os.path.join(TMP_TEST_DIR, 'test.py')
92
92
93 def tearDown(self):
93 def tearDown(self):
94 # We must remove this profile right away so its presence doesn't
94 # We must remove this profile right away so its presence doesn't
95 # confuse other tests.
95 # confuse other tests.
96 shutil.rmtree(self.pd.location)
96 shutil.rmtree(self.pd.location)
97
97
98 def init(self, startup_file, startup, test):
98 def init(self, startup_file, startup, test):
99 # write startup python file
99 # write startup python file
100 with open(os.path.join(self.pd.startup_dir, startup_file), 'w') as f:
100 with open(os.path.join(self.pd.startup_dir, startup_file), 'w') as f:
101 f.write(startup)
101 f.write(startup)
102 # write simple test file, to check that the startup file was run
102 # write simple test file, to check that the startup file was run
103 with open(self.fname, 'w') as f:
103 with open(self.fname, 'w') as f:
104 f.write(py3compat.doctest_refactor_print(test))
104 f.write(py3compat.doctest_refactor_print(test))
105
105
106 def validate(self, output):
106 def validate(self, output):
107 tt.ipexec_validate(self.fname, output, '', options=self.options)
107 tt.ipexec_validate(self.fname, output, '', options=self.options)
108
108
109 @dec.skipif(win32_without_pywin32(), "Test requires pywin32 on Windows")
109 @dec.skipif(win32_without_pywin32(), "Test requires pywin32 on Windows")
110 def test_startup_py(self):
110 def test_startup_py(self):
111 self.init('00-start.py', 'zzz=123\n',
111 self.init('00-start.py', 'zzz=123\n',
112 py3compat.doctest_refactor_print('print zzz\n'))
112 py3compat.doctest_refactor_print('print zzz\n'))
113 self.validate('123')
113 self.validate('123')
114
114
115 @dec.skipif(win32_without_pywin32(), "Test requires pywin32 on Windows")
115 @dec.skipif(win32_without_pywin32(), "Test requires pywin32 on Windows")
116 def test_startup_ipy(self):
116 def test_startup_ipy(self):
117 self.init('00-start.ipy', '%profile\n', '')
117 self.init('00-start.ipy', '%profile\n', '')
118 self.validate('test')
118 self.validate('test')
119
119
120
120
121 def test_list_profiles_in():
121 def test_list_profiles_in():
122 # No need to remove these directories and files, as they will get nuked in
122 # No need to remove these directories and files, as they will get nuked in
123 # the module-level teardown.
123 # the module-level teardown.
124 td = tempfile.mkdtemp(dir=TMP_TEST_DIR)
124 td = tempfile.mkdtemp(dir=TMP_TEST_DIR)
125 td = py3compat.str_to_unicode(td)
125 td = py3compat.str_to_unicode(td)
126 for name in ('profile_foo', u'profile_ünicode', 'profile_hello',
126 for name in ('profile_foo', u'profile_ünicode', 'profile_hello',
127 'not_a_profile'):
127 'not_a_profile'):
128 os.mkdir(os.path.join(td, name))
128 os.mkdir(os.path.join(td, name))
129 with open(os.path.join(td, 'profile_file'), 'w') as f:
129 with open(os.path.join(td, 'profile_file'), 'w') as f:
130 f.write("I am not a profile directory")
130 f.write("I am not a profile directory")
131 profiles = list_profiles_in(td)
131 profiles = list_profiles_in(td)
132
132
133 # unicode normalization can turn u'ünicode' into u'u\0308nicode',
133 # unicode normalization can turn u'ünicode' into u'u\0308nicode',
134 # so only check for *nicode, and that creating a ProfileDir from the
134 # so only check for *nicode, and that creating a ProfileDir from the
135 # name remains valid
135 # name remains valid
136 found_unicode = False
136 found_unicode = False
137 for p in list(profiles):
137 for p in list(profiles):
138 if p.endswith('nicode'):
138 if p.endswith('nicode'):
139 pd = ProfileDir.find_profile_dir_by_name(td, p)
139 pd = ProfileDir.find_profile_dir_by_name(td, p)
140 profiles.remove(p)
140 profiles.remove(p)
141 found_unicode = True
141 found_unicode = True
142 break
142 break
143 nt.assert_true(found_unicode)
143 nt.assert_true(found_unicode)
144 nt.assert_equals(set(profiles), set(['foo', 'hello']))
144 nt.assert_equals(set(profiles), set(['foo', 'hello']))
145
145
146
146
147 def test_list_bundled_profiles():
147 def test_list_bundled_profiles():
148 # This variable will need to be updated when a new profile gets bundled
148 # This variable will need to be updated when a new profile gets bundled
149 bundled_true = [u'cluster', u'math', u'pysh', u'python3', u'sympy']
149 bundled_true = [u'cluster', u'math', u'pysh', u'sympy']
150 bundled = sorted(list_bundled_profiles())
150 bundled = sorted(list_bundled_profiles())
151 nt.assert_equals(bundled, bundled_true)
151 nt.assert_equals(bundled, bundled_true)
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now