mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
unittest helper: Skip if exectuable not found
This commit is contained in:
parent
b73d984ec9
commit
d4e981f916
1 changed files with 20 additions and 0 deletions
|
|
@ -4,6 +4,8 @@ __all__ = [
|
||||||
'unittest',
|
'unittest',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
|
@ -35,3 +37,21 @@ def get_article(title, slug, content, lang, extra_metadata=None):
|
||||||
if extra_metadata is not None:
|
if extra_metadata is not None:
|
||||||
metadata.update(extra_metadata)
|
metadata.update(extra_metadata)
|
||||||
return Article(content, metadata=metadata)
|
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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
|
||||||
|
return lambda func: func
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue