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