Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_invalid_syntax(self):
"""Test invalid syntax."""
self.assert_raises('div?', SelectorSyntaxError)
self.assert_raises('-', SelectorSyntaxError)
def test_invalid_double_comma(self):
"""Test that selectors cannot have double combinators."""
self.assert_raises('div,, a', SelectorSyntaxError)
def test_simple_syntax_error(self):
"""Test a simple syntax error (no context)."""
with self.assertRaises(sv.SelectorSyntaxError) as cm:
raise sv.SelectorSyntaxError('Syntax Message')
e = cm.exception
self.assertEqual(e.context, None)
self.assertEqual(e.line, None)
self.assertEqual(e.col, None)
self.assertEqual(str(e), 'Syntax Message')
def test_invalid_incomplete_has(self):
"""Test `:has()` fails with just a combinator."""
self.assert_raises(':has(>)', SelectorSyntaxError)
def test_attribute_forced_case_needs_value(self):
"""Test attribute value case insensitivity requires a value."""
self.assert_raises('[id i]', SelectorSyntaxError)
def test_invalid_pseudo_class_start_combinator(self):
"""Test invalid start combinator in pseudo-classes other than `:has()`."""
self.assert_raises(':is(> div)', SelectorSyntaxError)
self.assert_raises(':is(div, > div)', SelectorSyntaxError)
def test_malformed_class(self):
"""Test malformed class."""
# Malformed class
self.assert_raises('td.+#some-id', SelectorSyntaxError)
def test_custom_dependency_recursion(self):
"""Test that we fail on dependency recursion."""
custom_selectors = {
":--parent-paragraph": "p:--parent",
":--parent": "p:--parent-paragraph"
}
self.assert_raises(':--parent', sv.SelectorSyntaxError, custom=custom_selectors)
def test_invalid_start_comma(self):
"""Test that selectors cannot start with a comma."""
self.assert_raises(', p', SelectorSyntaxError)
def test_simple_syntax_error(self):
"""Test a simple syntax error (no context)."""
with self.assertRaises(sv.SelectorSyntaxError) as cm:
raise sv.SelectorSyntaxError('Syntax Message')
e = cm.exception
self.assertEqual(e.context, None)
self.assertEqual(e.line, None)
self.assertEqual(e.col, None)
self.assertEqual(str(e), 'Syntax Message')