##// END OF EJS Templates
capture logging in a few tests...
MinRK -
Show More
@@ -1,73 +1,74 b''
1 """Test NotebookApp"""
1 """Test NotebookApp"""
2
2
3 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
4 # Copyright (C) 2013 The IPython Development Team
4 # Copyright (C) 2013 The IPython Development Team
5 #
5 #
6 # Distributed under the terms of the BSD License. The full license is in
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
7 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9
9
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11 # Imports
11 # Imports
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13
13
14 import logging
14 import os
15 import os
15 from tempfile import NamedTemporaryFile
16 from tempfile import NamedTemporaryFile
16
17
17 import nose.tools as nt
18 import nose.tools as nt
18
19
19 from IPython.utils.tempdir import TemporaryDirectory
20 from IPython.utils.tempdir import TemporaryDirectory
20 from IPython.utils.traitlets import TraitError
21 from IPython.utils.traitlets import TraitError
21 import IPython.testing.tools as tt
22 import IPython.testing.tools as tt
22 from IPython.html import notebookapp
23 from IPython.html import notebookapp
23 NotebookApp = notebookapp.NotebookApp
24 NotebookApp = notebookapp.NotebookApp
24
25
25 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
26 # Test functions
27 # Test functions
27 #-----------------------------------------------------------------------------
28 #-----------------------------------------------------------------------------
28
29
29 def test_help_output():
30 def test_help_output():
30 """ipython notebook --help-all works"""
31 """ipython notebook --help-all works"""
31 tt.help_all_output_test('notebook')
32 tt.help_all_output_test('notebook')
32
33
33 def test_server_info_file():
34 def test_server_info_file():
34 nbapp = NotebookApp(profile='nbserver_file_test')
35 nbapp = NotebookApp(profile='nbserver_file_test', log=logging.getLogger())
35 def get_servers():
36 def get_servers():
36 return list(notebookapp.list_running_servers(profile='nbserver_file_test'))
37 return list(notebookapp.list_running_servers(profile='nbserver_file_test'))
37 nbapp.initialize(argv=[])
38 nbapp.initialize(argv=[])
38 nbapp.write_server_info_file()
39 nbapp.write_server_info_file()
39 servers = get_servers()
40 servers = get_servers()
40 nt.assert_equal(len(servers), 1)
41 nt.assert_equal(len(servers), 1)
41 nt.assert_equal(servers[0]['port'], nbapp.port)
42 nt.assert_equal(servers[0]['port'], nbapp.port)
42 nt.assert_equal(servers[0]['url'], nbapp.connection_url)
43 nt.assert_equal(servers[0]['url'], nbapp.connection_url)
43 nbapp.remove_server_info_file()
44 nbapp.remove_server_info_file()
44 nt.assert_equal(get_servers(), [])
45 nt.assert_equal(get_servers(), [])
45
46
46 # The ENOENT error should be silenced.
47 # The ENOENT error should be silenced.
47 nbapp.remove_server_info_file()
48 nbapp.remove_server_info_file()
48
49
49 def test_nb_dir():
50 def test_nb_dir():
50 with TemporaryDirectory() as td:
51 with TemporaryDirectory() as td:
51 app = NotebookApp(notebook_dir=td)
52 app = NotebookApp(notebook_dir=td)
52 nt.assert_equal(app.notebook_dir, td)
53 nt.assert_equal(app.notebook_dir, td)
53
54
54 def test_no_create_nb_dir():
55 def test_no_create_nb_dir():
55 with TemporaryDirectory() as td:
56 with TemporaryDirectory() as td:
56 nbdir = os.path.join(td, 'notebooks')
57 nbdir = os.path.join(td, 'notebooks')
57 app = NotebookApp()
58 app = NotebookApp()
58 with nt.assert_raises(TraitError):
59 with nt.assert_raises(TraitError):
59 app.notebook_dir = nbdir
60 app.notebook_dir = nbdir
60
61
61 def test_missing_nb_dir():
62 def test_missing_nb_dir():
62 with TemporaryDirectory() as td:
63 with TemporaryDirectory() as td:
63 nbdir = os.path.join(td, 'notebook', 'dir', 'is', 'missing')
64 nbdir = os.path.join(td, 'notebook', 'dir', 'is', 'missing')
64 app = NotebookApp()
65 app = NotebookApp()
65 with nt.assert_raises(TraitError):
66 with nt.assert_raises(TraitError):
66 app.notebook_dir = nbdir
67 app.notebook_dir = nbdir
67
68
68 def test_invalid_nb_dir():
69 def test_invalid_nb_dir():
69 with NamedTemporaryFile() as tf:
70 with NamedTemporaryFile() as tf:
70 app = NotebookApp()
71 app = NotebookApp()
71 with nt.assert_raises(TraitError):
72 with nt.assert_raises(TraitError):
72 app.notebook_dir = tf
73 app.notebook_dir = tf
73
74
@@ -1,68 +1,69 b''
1 """
1 """
2 Module with tests for the PDF post-processor
2 Module with tests for the PDF post-processor
3 """
3 """
4
4
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
7 #
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9 #
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 import logging
17 import os
18 import os
18
19
19 from IPython.testing import decorators as dec
20 from IPython.testing import decorators as dec
20
21
21 from ...tests.base import TestsBase
22 from ...tests.base import TestsBase
22 from ..pdf import PDFPostProcessor
23 from ..pdf import PDFPostProcessor
23
24
24
25
25 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
26 # Constants
27 # Constants
27 #-----------------------------------------------------------------------------
28 #-----------------------------------------------------------------------------
28
29
29 HELLO_WORLD = r"""% hello.tex - Our first LaTeX example!
30 HELLO_WORLD = r"""% hello.tex - Our first LaTeX example!
30 \documentclass{article}
31 \documentclass{article}
31 \begin{document}
32 \begin{document}
32 Hello World!
33 Hello World!
33 \end{document}"""
34 \end{document}"""
34
35
35
36
36 #-----------------------------------------------------------------------------
37 #-----------------------------------------------------------------------------
37 # Class
38 # Class
38 #-----------------------------------------------------------------------------
39 #-----------------------------------------------------------------------------
39
40
40 class TestPDF(TestsBase):
41 class TestPDF(TestsBase):
41 """Contains test functions for pdf.py"""
42 """Contains test functions for pdf.py"""
42
43
43
44
44 def test_constructor(self):
45 def test_constructor(self):
45 """Can a PDFPostProcessor be constructed?"""
46 """Can a PDFPostProcessor be constructed?"""
46 PDFPostProcessor()
47 PDFPostProcessor()
47
48
48
49
49 @dec.onlyif_cmds_exist('pdflatex')
50 @dec.onlyif_cmds_exist('pdflatex')
50 def test_pdf(self):
51 def test_pdf(self):
51 """Can a PDF be made using the PDFPostProcessor?"""
52 """Can a PDF be made using the PDFPostProcessor?"""
52
53
53 # Work in a temporary directory with hello world latex in it.
54 # Work in a temporary directory with hello world latex in it.
54 with self.create_temp_cwd():
55 with self.create_temp_cwd():
55 with open('a.tex', 'w') as f:
56 with open('a.tex', 'w') as f:
56 f.write(HELLO_WORLD)
57 f.write(HELLO_WORLD)
57
58
58 # Construct post-processor
59 # Construct post-processor
59 processor = PDFPostProcessor()
60 processor = PDFPostProcessor(log=logging.getLogger())
60 processor.verbose = False
61 processor.verbose = False
61 processor('a.tex')
62 processor('a.tex')
62
63
63 # Check that the PDF was created.
64 # Check that the PDF was created.
64 assert os.path.isfile('a.pdf')
65 assert os.path.isfile('a.pdf')
65
66
66 # Make sure that temp files are cleaned up
67 # Make sure that temp files are cleaned up
67 for ext in processor.temp_file_exts:
68 for ext in processor.temp_file_exts:
68 assert not os.path.isfile('a'+ext)
69 assert not os.path.isfile('a'+ext)
General Comments 0
You need to be logged in to leave comments. Login now