##// END OF EJS Templates
suppress warnings test_pandoc
MinRK -
Show More
@@ -1,62 +1,70 b''
1 """Test Pandoc module"""
1 """Test Pandoc module"""
2 #-----------------------------------------------------------------------------
2 #-----------------------------------------------------------------------------
3 # Copyright (C) 2014 The IPython Development Team
3 # Copyright (C) 2014 The IPython Development Team
4 #
4 #
5 # Distributed under the terms of the BSD License. The full license is in
5 # Distributed under the terms of the BSD License. The full license is in
6 # the file COPYING, distributed as part of this software.
6 # the file COPYING, distributed as part of this software.
7 #-----------------------------------------------------------------------------
7 #-----------------------------------------------------------------------------
8
8
9 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
10 # Imports
10 # Imports
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12 import os
12 import os
13 import warnings
13
14
14 from IPython.testing import decorators as dec
15 from IPython.testing import decorators as dec
15
16
16 from IPython.nbconvert.tests.base import TestsBase
17 from IPython.nbconvert.tests.base import TestsBase
17 from .. import pandoc
18 from .. import pandoc
18
19
19 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
20 # Classes and functions
21 # Classes and functions
21 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
22 class TestPandoc(TestsBase):
23 class TestPandoc(TestsBase):
23 """Collection of Pandoc tests"""
24 """Collection of Pandoc tests"""
24
25
25 def __init__(self, *args, **kwargs):
26 def __init__(self, *args, **kwargs):
26 super(TestPandoc, self).__init__(*args, **kwargs)
27 super(TestPandoc, self).__init__(*args, **kwargs)
27 self.original_env = os.environ.copy()
28 self.original_env = os.environ.copy()
28
29
29 @dec.onlyif_cmds_exist('pandoc')
30 @dec.onlyif_cmds_exist('pandoc')
30 def test_pandoc_available(self):
31 def test_pandoc_available(self):
31 """ Test behaviour that pandoc functions raise PandocMissing as documented """
32 """ Test behaviour that pandoc functions raise PandocMissing as documented """
32 pandoc.clean_cache()
33 pandoc.clean_cache()
33
34
34 os.environ["PATH"] = ""
35 os.environ["PATH"] = ""
35 assert pandoc_function_raised_missing(pandoc.get_pandoc_version) == True
36 with self.assertRaises(pandoc.PandocMissing):
36 assert pandoc_function_raised_missing(pandoc.check_pandoc_version) == True
37 pandoc.get_pandoc_version()
37 assert pandoc_function_raised_missing(pandoc.pandoc, "", "markdown", "html") == True
38 with self.assertRaises(pandoc.PandocMissing):
39 pandoc.check_pandoc_version()
40 with self.assertRaises(pandoc.PandocMissing):
41 pandoc.pandoc("", "markdown", "html")
38
42
39 # original_env["PATH"] should contain pandoc
43 # original_env["PATH"] should contain pandoc
40 os.environ["PATH"] = self.original_env["PATH"]
44 os.environ["PATH"] = self.original_env["PATH"]
41 assert pandoc_function_raised_missing(pandoc.get_pandoc_version) == False
45 with warnings.catch_warnings(True) as w:
42 assert pandoc_function_raised_missing(pandoc.check_pandoc_version) == False
46 pandoc.get_pandoc_version()
43 assert pandoc_function_raised_missing(pandoc.pandoc, "", "markdown", "html") == False
47 pandoc.check_pandoc_version()
48 pandoc.pandoc("", "markdown", "html")
49 self.assertEqual(w, [])
44
50
45 @dec.onlyif_cmds_exist('pandoc')
51 @dec.onlyif_cmds_exist('pandoc')
46 def test_minimal_version(self):
52 def test_minimal_version(self):
47 original_minversion = pandoc._minimal_version
53 original_minversion = pandoc._minimal_version
48
54
49 pandoc._minimal_version = "120.0"
55 pandoc._minimal_version = "120.0"
56 with warnings.catch_warnings(True) as w:
50 assert not pandoc.check_pandoc_version()
57 assert not pandoc.check_pandoc_version()
58 self.assertEqual(len(w), 1)
51
59
52 pandoc._minimal_version = pandoc.get_pandoc_version()
60 pandoc._minimal_version = pandoc.get_pandoc_version()
53 assert pandoc.check_pandoc_version()
61 assert pandoc.check_pandoc_version()
54
62
55
63
56 def pandoc_function_raised_missing(f, *args, **kwargs):
64 def pandoc_function_raised_missing(f, *args, **kwargs):
57 try:
65 try:
58 f(*args, **kwargs)
66 f(*args, **kwargs)
59 except pandoc.PandocMissing:
67 except pandoc.PandocMissing:
60 return True
68 return True
61 else:
69 else:
62 return False
70 return False
General Comments 0
You need to be logged in to leave comments. Login now