Show More
@@ -1,73 +1,70 | |||||
1 | # coding: utf-8 |
|
1 | # coding: utf-8 | |
2 | """Tests for IPython.core.application""" |
|
2 | """Tests for IPython.core.application""" | |
3 |
|
3 | |||
4 | import os |
|
4 | import os | |
5 | import tempfile |
|
5 | import tempfile | |
6 |
|
6 | |||
7 | import nose.tools as nt |
|
|||
8 |
|
||||
9 | from traitlets import Unicode |
|
7 | from traitlets import Unicode | |
10 |
|
8 | |||
11 | from IPython.core.application import BaseIPythonApplication |
|
9 | from IPython.core.application import BaseIPythonApplication | |
12 | from IPython.testing import decorators as dec |
|
10 | from IPython.testing import decorators as dec | |
13 | from IPython.utils.tempdir import TemporaryDirectory |
|
11 | from IPython.utils.tempdir import TemporaryDirectory | |
14 |
|
12 | |||
15 |
|
13 | |||
16 | @dec.onlyif_unicode_paths |
|
14 | @dec.onlyif_unicode_paths | |
17 | def test_unicode_cwd(): |
|
15 | def test_unicode_cwd(): | |
18 | """Check that IPython starts with non-ascii characters in the path.""" |
|
16 | """Check that IPython starts with non-ascii characters in the path.""" | |
19 | wd = tempfile.mkdtemp(suffix=u"€") |
|
17 | wd = tempfile.mkdtemp(suffix=u"€") | |
20 |
|
18 | |||
21 | old_wd = os.getcwd() |
|
19 | old_wd = os.getcwd() | |
22 | os.chdir(wd) |
|
20 | os.chdir(wd) | |
23 | #raise Exception(repr(os.getcwd())) |
|
21 | #raise Exception(repr(os.getcwd())) | |
24 | try: |
|
22 | try: | |
25 | app = BaseIPythonApplication() |
|
23 | app = BaseIPythonApplication() | |
26 | # The lines below are copied from Application.initialize() |
|
24 | # The lines below are copied from Application.initialize() | |
27 | app.init_profile_dir() |
|
25 | app.init_profile_dir() | |
28 | app.init_config_files() |
|
26 | app.init_config_files() | |
29 | app.load_config_file(suppress_errors=False) |
|
27 | app.load_config_file(suppress_errors=False) | |
30 | finally: |
|
28 | finally: | |
31 | os.chdir(old_wd) |
|
29 | os.chdir(old_wd) | |
32 |
|
30 | |||
33 | @dec.onlyif_unicode_paths |
|
31 | @dec.onlyif_unicode_paths | |
34 | def test_unicode_ipdir(): |
|
32 | def test_unicode_ipdir(): | |
35 | """Check that IPython starts with non-ascii characters in the IP dir.""" |
|
33 | """Check that IPython starts with non-ascii characters in the IP dir.""" | |
36 | ipdir = tempfile.mkdtemp(suffix=u"€") |
|
34 | ipdir = tempfile.mkdtemp(suffix=u"€") | |
37 |
|
35 | |||
38 | # Create the config file, so it tries to load it. |
|
36 | # Create the config file, so it tries to load it. | |
39 | with open(os.path.join(ipdir, 'ipython_config.py'), "w") as f: |
|
37 | with open(os.path.join(ipdir, 'ipython_config.py'), "w") as f: | |
40 | pass |
|
38 | pass | |
41 |
|
39 | |||
42 | old_ipdir1 = os.environ.pop("IPYTHONDIR", None) |
|
40 | old_ipdir1 = os.environ.pop("IPYTHONDIR", None) | |
43 | old_ipdir2 = os.environ.pop("IPYTHON_DIR", None) |
|
41 | old_ipdir2 = os.environ.pop("IPYTHON_DIR", None) | |
44 | os.environ["IPYTHONDIR"] = ipdir |
|
42 | os.environ["IPYTHONDIR"] = ipdir | |
45 | try: |
|
43 | try: | |
46 | app = BaseIPythonApplication() |
|
44 | app = BaseIPythonApplication() | |
47 | # The lines below are copied from Application.initialize() |
|
45 | # The lines below are copied from Application.initialize() | |
48 | app.init_profile_dir() |
|
46 | app.init_profile_dir() | |
49 | app.init_config_files() |
|
47 | app.init_config_files() | |
50 | app.load_config_file(suppress_errors=False) |
|
48 | app.load_config_file(suppress_errors=False) | |
51 | finally: |
|
49 | finally: | |
52 | if old_ipdir1: |
|
50 | if old_ipdir1: | |
53 | os.environ["IPYTHONDIR"] = old_ipdir1 |
|
51 | os.environ["IPYTHONDIR"] = old_ipdir1 | |
54 | if old_ipdir2: |
|
52 | if old_ipdir2: | |
55 | os.environ["IPYTHONDIR"] = old_ipdir2 |
|
53 | os.environ["IPYTHONDIR"] = old_ipdir2 | |
56 |
|
54 | |||
57 | def test_cli_priority(): |
|
55 | def test_cli_priority(): | |
58 | with TemporaryDirectory() as td: |
|
56 | with TemporaryDirectory() as td: | |
59 |
|
57 | |||
60 | class TestApp(BaseIPythonApplication): |
|
58 | class TestApp(BaseIPythonApplication): | |
61 | test = Unicode().tag(config=True) |
|
59 | test = Unicode().tag(config=True) | |
62 |
|
60 | |||
63 | # Create the config file, so it tries to load it. |
|
61 | # Create the config file, so it tries to load it. | |
64 | with open(os.path.join(td, 'ipython_config.py'), "w") as f: |
|
62 | with open(os.path.join(td, 'ipython_config.py'), "w") as f: | |
65 | f.write("c.TestApp.test = 'config file'") |
|
63 | f.write("c.TestApp.test = 'config file'") | |
66 |
|
64 | |||
67 | app = TestApp() |
|
65 | app = TestApp() | |
68 |
app.initialize([ |
|
66 | app.initialize(["--profile-dir", td]) | |
69 |
|
|
67 | assert app.test == "config file" | |
70 | app = TestApp() |
|
68 | app = TestApp() | |
71 |
app.initialize([ |
|
69 | app.initialize(["--profile-dir", td, "--TestApp.test=cli"]) | |
72 |
|
|
70 | assert app.test == "cli" | |
73 |
|
General Comments 0
You need to be logged in to leave comments.
Login now