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