##// END OF EJS Templates
Refactor tests to fix leftover profiles that would collide with other tests.
Fernando Perez -
Show More
@@ -25,9 +25,12 b' import shutil'
25 import sys
25 import sys
26 import tempfile
26 import tempfile
27
27
28 from unittest import TestCase
29
28 import nose.tools as nt
30 import nose.tools as nt
29 from nose import SkipTest
31 from nose import SkipTest
30
32
33 from IPython.core.profileapp import list_profiles_in, list_bundled_profiles
31 from IPython.core.profiledir import ProfileDir
34 from IPython.core.profiledir import ProfileDir
32
35
33 from IPython.testing import decorators as dec
36 from IPython.testing import decorators as dec
@@ -79,35 +82,35 b' def win32_without_pywin32():'
79 return False
82 return False
80
83
81
84
82 @dec.skipif(win32_without_pywin32(), "Test requires pywin32 on Windows")
85 class ProfileDirTest(TestCase):
83 def test_startup_py():
86 def setUp(self):
84 # create profile dir
87 # create profile dir
85 pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test')
88 self.pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test')
86 # write startup python file
89 self.options = ['--ipython-dir', IP_TEST_DIR, '--profile', 'test']
87 with open(os.path.join(pd.startup_dir, '00-start.py'), 'w') as f:
90 self.fname = os.path.join(TMP_TEST_DIR, 'test.py')
88 f.write('zzz=123\n')
91
89 # write simple test file, to check that the startup file was run
92 def tearDown(self):
90 fname = os.path.join(TMP_TEST_DIR, 'test.py')
93 shutil.rmtree(self.pd.location)
91 with open(fname, 'w') as f:
94
92 f.write(py3compat.doctest_refactor_print('print zzz\n'))
95 def init(self, startup_file, startup, test):
93 # validate output
96 # write startup python file
94 tt.ipexec_validate(fname, '123', '',
97 with open(os.path.join(self.pd.startup_dir, startup_file), 'w') as f:
95 options=['--ipython-dir', IP_TEST_DIR, '--profile', 'test'])
98 f.write(startup)
96
99 # write simple test file, to check that the startup file was run
97 @dec.skipif(win32_without_pywin32(), "Test requires pywin32 on Windows")
100 with open(self.fname, 'w') as f:
98 def test_startup_ipy():
101 f.write(py3compat.doctest_refactor_print(test))
99 # create profile dir
102
100 pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test')
103 def validate(self, output):
101 # write startup ipython file
104 # validate output
102 with open(os.path.join(pd.startup_dir, '00-start.ipy'), 'w') as f:
105 tt.ipexec_validate(self.fname, output, '', options=self.options)
103 f.write('%profile\n')
106
104 # write empty script, because we don't need anything to happen
107 @dec.skipif(win32_without_pywin32(), "Test requires pywin32 on Windows")
105 # after the startup file is run
108 def test_startup_py(self):
106 fname = os.path.join(TMP_TEST_DIR, 'test.py')
109 self.init('00-start.py', 'zzz=123\n',
107 with open(fname, 'w') as f:
110 py3compat.doctest_refactor_print('print zzz\n'))
108 f.write('')
111 self.validate('123')
109 # validate output
112
110 tt.ipexec_validate(fname, 'test', '',
113 @dec.skipif(win32_without_pywin32(), "Test requires pywin32 on Windows")
111 options=['--ipython-dir', IP_TEST_DIR, '--profile', 'test'])
114 def test_startup_ipy(self):
112
115 self.init('00-start.ipy', '%profile\n', '')
113
116 self.validate('test')
General Comments 0
You need to be logged in to leave comments. Login now