test_pandoc.py
75 lines
| 2.6 KiB
| text/x-python
|
PythonLexer
|
r14766 | """Test Pandoc module""" | ||
#----------------------------------------------------------------------------- | ||||
# Copyright (C) 2013 The IPython Development Team | ||||
# | ||||
# Distributed under the terms of the BSD License. The full license is in | ||||
# the file COPYING, distributed as part of this software. | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
import os | ||||
from .base import TestsBase | ||||
from ..utils import pandoc | ||||
from IPython.testing import decorators as dec | ||||
#----------------------------------------------------------------------------- | ||||
# Constants | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Classes and functions | ||||
#----------------------------------------------------------------------------- | ||||
|
r14768 | |||
|
r14766 | class TestPandoc(TestsBase): | ||
"""Collection of Pandoc tests""" | ||||
def __init__(self, *args, **kwargs): | ||||
super(TestPandoc, self).__init__(*args, **kwargs) | ||||
self.original_env = os.environ.copy() | ||||
@dec.onlyif_cmds_exist('pandoc') | ||||
def test_pandoc_available(self): | ||||
|
r14768 | """ Test behaviour that pandoc functions raise PandocMissing as documented """ | ||
pandoc.clean_cache() | ||||
|
r14766 | os.environ["PATH"] = "" | ||
|
r14768 | assert pandoc_function_raised_missing(pandoc.get_pandoc_version) == True | ||
assert pandoc_function_raised_missing(pandoc.check_pandoc_version) == True | ||||
assert pandoc_function_raised_missing(pandoc.pandoc, "", "markdown", "html") == True | ||||
|
r14766 | |||
|
r14768 | # original_env["PATH"] should contain pandoc | ||
|
r14766 | os.environ["PATH"] = self.original_env["PATH"] | ||
|
r14768 | assert pandoc_function_raised_missing(pandoc.get_pandoc_version) == False | ||
assert pandoc_function_raised_missing(pandoc.check_pandoc_version) == False | ||||
assert pandoc_function_raised_missing(pandoc.pandoc, "", "markdown", "html") == False | ||||
|
r14766 | |||
@dec.onlyif_cmds_exist('pandoc') | ||||
def test_minimal_version(self): | ||||
|
r14768 | original_minversion = pandoc._minimal_version | ||
|
r14766 | |||
|
r14768 | pandoc._minimal_version = "120.0" | ||
|
r14766 | assert not pandoc.check_pandoc_version() | ||
|
r14768 | pandoc._minimal_version = pandoc.get_pandoc_version() | ||
|
r14766 | assert pandoc.check_pandoc_version() | ||
|
r14768 | |||
def pandoc_function_raised_missing(f, *args, **kwargs): | ||||
try: | ||||
f(*args, **kwargs) | ||||
except pandoc.PandocMissing as e: | ||||
print e | ||||
return True | ||||
else: | ||||
return False | ||||