Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve selector_to_xpath tests on pseudo-elements #41

Merged
merged 1 commit into from Oct 18, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions cssselect/tests.py
Expand Up @@ -196,6 +196,21 @@ def parse_one(css):
('Element[bar]', None),
('Element[baz]', 'after')]

# Special cases for CSS 2.1 pseudo-elements are ignored by default
for pseudo in ('after', 'before', 'first-line', 'first-letter'):
selector, = parse('e:%s' % pseudo)
assert selector.pseudo_element == pseudo
assert GenericTranslator().selector_to_xpath(selector, prefix='') == "e"

# Pseudo Elements are ignored by default, but if allowed they are not
# supported by GenericTranslator
tr = GenericTranslator()
selector, = parse('e::foo')
assert selector.pseudo_element == 'foo'
assert tr.selector_to_xpath(selector, prefix='') == "e"
self.assertRaises(ExpressionError, tr.selector_to_xpath, selector,
translate_pseudo_elements=True)

def test_specificity(self):
def specificity(css):
selectors = parse(css)
Expand Down Expand Up @@ -380,11 +395,6 @@ def xpath(css):
assert xpath('div#container p') == (
"div[@id = 'container']/descendant-or-self::*/p")

selector, = parse('e:after')
assert selector.pseudo_element == 'after'
# Pseudo-element is ignored:
assert GenericTranslator().selector_to_xpath(selector, prefix='') == "e"

# Invalid characters in XPath element names
assert xpath(r'di\a0 v') == (
u("*[name() = 'di v']")) # di\xa0v
Expand Down