# Path: xpaw/selector.py
# class Selector:
#     def __init__(self, text=None, root=None, text_type='html'):
#         self.type = _get_text_type(text_type)
#         c = _text_type_config[self.type]
#         self._parser_cls = c['parser_cls']
#         self._tostring_method = c['tostring_method']
#         self._css_translator = c['css_translator']
#         if text is not None:
#             if not isinstance(text, str):
#                 raise TypeError("'text' argument must be str")
#             root = create_root_node(text, parser_cls=self._parser_cls)
#         if root is None:
#             raise ValueError("Needs either text or root argument")
#         self.root = root
# 
#     def xpath(self, xpath, **kwargs):
#         kwargs.setdefault('smart_strings', False)
#         res = self.root.xpath(xpath, **kwargs)
#         if not isinstance(res, list):
#             res = [res]
#         return SelectorList([self.__class__(root=i) for i in res])
# 
#     def css(self, css, **kwargs):
#         xpath = self._css_translator.css_to_xpath(css)
#         return self.xpath(xpath, **kwargs)
# 
#     @property
#     def string(self):
#         try:
#             return etree.tostring(self.root, encoding="unicode", method=self._tostring_method, with_tail=False)
#         except TypeError:
#             return str(self.root)
# 
#     @property
#     def text(self):
#         try:
#             return etree.tostring(self.root, encoding="unicode", method="text", with_tail=False)
#         except TypeError:
#             return str(self.root)
# 
#     def attr(self, name):
#         res = self.xpath('@' + name)
#         if len(res) > 0:
#             return res[0].text


import pytest
from xpaw.selector import Selector
        from lxml.etree import XMLSyntaxError

class TestCssSelector:
    def test_selector_list(self):
        html = """<li>a</li><div><ul><li>b</li><li>c</li></ul></div><ul><li>d</li></ul>"""
        s = Selector(html)
        assert s.css("li")[0].text == "a"
        assert s.css("li")[-1].text == "d"
        assert s.css("div li").text[0] == "b"
        assert s.css("div li").text[-1] == "c"

    def test_node_selection(self):
        s = Selector("""<html>
                <body>
                    <h1 class='header'><a href="http://example.com/">example</a></h1>
                    <ul>
                        <li><a class='primary link' href="http://example.com/index">index</a></li>
                        <li><a class='link' href="http://example.com/content">content</a></li>
                    </ul>
                </body>
                </html>""")
        assert s.css('a')[0].text == 'example'
        assert s.css('a[class=link]')[0].text == 'content'
        assert s.css('a[class~=link]')[0].text == 'index'
        assert s.css('ul>a') == []
        assert len(s.css('li>a')) == 2
        assert s.css('ul a')[0].text == 'index'
        assert s.css('ul').css('a')[0].text == 'index'
        assert s.css('li>a:not([class~=primary])')[0].text == 'content'

    def test_attribute_selection(self):

# Path: xpaw/selector.py
# class Selector:
#     def __init__(self, text=None, root=None, text_type='html'):
#         self.type = _get_text_type(text_type)
#         c = _text_type_config[self.type]
#         self._parser_cls = c['parser_cls']
#         self._tostring_method = c['tostring_method']
#         self._css_translator = c['css_translator']
#         if text is not None:
#             if not isinstance(text, str):
#                 raise TypeError("'text' argument must be str")
#             root = create_root_node(text, parser_cls=self._parser_cls)
#         if root is None:
#             raise ValueError("Needs either text or root argument")
#         self.root = root
# 
#     def xpath(self, xpath, **kwargs):
#         kwargs.setdefault('smart_strings', False)
#         res = self.root.xpath(xpath, **kwargs)
#         if not isinstance(res, list):
#             res = [res]
#         return SelectorList([self.__class__(root=i) for i in res])
# 
#     def css(self, css, **kwargs):
#         xpath = self._css_translator.css_to_xpath(css)
#         return self.xpath(xpath, **kwargs)
# 
#     @property
#     def string(self):
#         try:
#             return etree.tostring(self.root, encoding="unicode", method=self._tostring_method, with_tail=False)
#         except TypeError:
#             return str(self.root)
# 
#     @property
#     def text(self):
#         try:
#             return etree.tostring(self.root, encoding="unicode", method="text", with_tail=False)
#         except TypeError:
#             return str(self.root)
# 
#     def attr(self, name):
#         res = self.xpath('@' + name)
#         if len(res) > 0:
#             return res[0].text


# Path: tests/test_selector.py
import pytest
from xpaw.selector import Selector
        from lxml.etree import XMLSyntaxError


class TestCssSelector:
    def test_selector_list(self):
        html = """<li>a</li><div><ul><li>b</li><li>c</li></ul></div><ul><li>d</li></ul>"""
        s = Selector(html)
        assert s.css("li")[0].text == "a"
        assert s.css("li")[-1].text == "d"
        assert s.css("div li").text[0] == "b"
        assert s.css("div li").text[-1] == "c"

    def test_node_selection(self):
        s = Selector("""<html>
                <body>
                    <h1 class='header'><a href="http://example.com/">example</a></h1>
                    <ul>
                        <li><a class='primary link' href="http://example.com/index">index</a></li>
                        <li><a class='link' href="http://example.com/content">content</a></li>
                    </ul>
                </body>
                </html>""")
        assert s.css('a')[0].text == 'example'
        assert s.css('a[class=link]')[0].text == 'content'
        assert s.css('a[class~=link]')[0].text == 'index'
        assert s.css('ul>a') == []
        assert len(s.css('li>a')) == 2
        assert s.css('ul a')[0].text == 'index'
        assert s.css('ul').css('a')[0].text == 'index'
        assert s.css('li>a:not([class~=primary])')[0].text == 'content'

    def test_attribute_selection(self):

        s = Selector("""<html>