refactor the check of executable for unit tests

pandoc was checked directly with a `os.system` call, and the output with version
and copyright of pandoc was displayed when running tests.

- replace the pandoc check with the `skipIfNoExecutable` function.
- in `skipIfNoExecutable`, the `valid_exit_code` is not needed, the executable
  is not found if an `OSError` exception is catched.
This commit is contained in:
Simon 2012-10-25 22:43:58 +02:00
commit ae8cf9defd
2 changed files with 10 additions and 13 deletions

View file

@ -114,7 +114,6 @@ def mute(returns_output=False):
return decorator
def get_article(title, slug, content, lang, extra_metadata=None):
metadata = {'slug': slug, 'title': title, 'lang': lang}
if extra_metadata is not None:
@ -122,19 +121,20 @@ def get_article(title, slug, content, lang, extra_metadata=None):
return Article(content, metadata=metadata)
def skipIfNoExecutable(executable, valid_exit_code=1):
"""Tries to run an executable to make sure it's in the path, Skips the tests
if not found.
def skipIfNoExecutable(executable):
"""Skip test if `executable` is not found
Tries to run `executable` with subprocess to make sure it's in the path,
and skips the tests if not found (if subprocess raises a `OSError`).
"""
# calling with no params the command should exit with 1
with open(os.devnull, 'w') as fnull:
try:
res = subprocess.call(executable, stdout=fnull, stderr=fnull)
except OSError:
res = None
if res != valid_exit_code:
return unittest.skip('{0} compiler not found'.format(executable))
if res is None:
return unittest.skip('{0} executable not found'.format(executable))
return lambda func: func