Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
Make tests fail if an optional dependecy is missing
Browse files Browse the repository at this point in the history
If lxml or the speedups are missing, the relevant tests are skipped.
(No need to show hundreds of failures.)

This adds one test for each optional dependecy, so that the
suite fails if something is missing, unless a specific enviroment
variable is set. (For when this is expected, like on PyPy.)
  • Loading branch information
SimonSapin committed Mar 12, 2012
1 parent 9505cc6 commit 9df1bc6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
15 changes: 12 additions & 3 deletions tinycss/tests/test_selectors3.py
Expand Up @@ -9,15 +9,16 @@


from __future__ import unicode_literals
import os

import pytest

from tinycss.core import CoreParser
try:
import lxml.cssselect
except ImportError:
lxml = None
else:

from tinycss.core import CoreParser
if lxml is not None:
from tinycss.selectors3 import (
Selector, InvalidSelectorError, Selectors3ParserMixin,
parse_selector_string, parse_selector_group_string)
Expand All @@ -26,6 +27,14 @@ class CSSParser(Selectors3ParserMixin, CoreParser):
"""Custom CSS parser."""


def test_lxml():
if not os.environ.get('TINYCSS_SKIP_LXML_TESTS'):
assert lxml is not None, (
'lxml is not not installed, related tests will be skipped. '
'Set the TINYCSS_SKIP_LXML_TESTS environment variable '
'if this is expected (eg. on PyPy).')


@pytest.mark.parametrize(('css_source', 'expected_num_selectors',
'expected_errors'), [
('', [], []),
Expand Down
10 changes: 10 additions & 0 deletions tinycss/tests/test_tokenizer.py
Expand Up @@ -9,12 +9,22 @@


from __future__ import unicode_literals
import os

import pytest

from tinycss.tokenizer import (
python_tokenize_flat, cython_tokenize_flat, regroup)


def test_speedups():
if not os.environ.get('TINYCSS_SKIP_SPEEDUPS_TESTS'):
assert cython_tokenize_flat is not None, (
'Cython speedups are not installed, related tests will '
'be skipped. Set the TINYCSS_SKIP_SPEEDUPS_TESTS environment '
'variable if this is expected (eg. on PyPy).')


@pytest.mark.parametrize(('tokenize', 'css_source', 'expected_tokens'), [
(tokenize,) + test_data
for tokenize in (python_tokenize_flat, cython_tokenize_flat)
Expand Down
9 changes: 6 additions & 3 deletions tox.ini
Expand Up @@ -5,8 +5,11 @@ envlist = py26,py27,py31,py32,pypy
deps=
pytest
lxml
changedir={toxworkdir}/logs
commands=py.test --pyargs tinycss []
changedir = {toxworkdir}/logs
commands = py.test --pyargs tinycss []

[testenv:pypy]
deps=pytest
deps = pytest
setenv =
TINYCSS_SKIP_SPEEDUPS_TESTS=1
TINYCSS_SKIP_LXML_TESTS=1

0 comments on commit 9df1bc6

Please sign in to comment.