# 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
        assert s.xpath("//a/@target")[0].text == "_blank"

    def test_text_selection(self):
        html = """<div><p>expression: <var>x</var>+<var>y</var>=<var>z</var></p></div>"""
        s = Selector(html)
        assert s.xpath("//var/text()")[0].text == "x"
        assert s.xpath("//var")[0].text == "x"
        assert s.xpath("//var[last()]").text == ["z"]
        assert s.xpath("//var/text()").text == ["x", "y", "z"]
        assert s.xpath("//var").text == ["x", "y", "z"]
        assert s.xpath("//p")[0].text == "expression: x+y=z"

    def test_diff_between_string_and_text(self):
        html = """<div><p>expression: <var>x</var>+<var>y</var>=<var>z</var></p></div>"""
        s = Selector(html)
        assert s.xpath("//var")[0].text == "x"
        assert s.xpath("//var")[0].string == "<var>x</var>"
        assert s.xpath("//var").text == ["x", "y", "z"]
        assert s.xpath("//var").string == ["<var>x</var>", "<var>y</var>", "<var>z</var>"]

    def test_node_selection(self):
        html = """<p></p><p class='primary'>primary</p><p class="minor gray">minor</p>"""
        s = Selector(html)
        primary = s.xpath("//p[@class='primary']")
        assert len(primary) == 1 and primary[0].text == 'primary'
        minor = s.xpath("//p[@class='minor']")
        assert len(minor) == 0
        minor = s.xpath("//p[@class='gray minor']")
        assert len(minor) == 0
        minor = s.xpath("//p[@class='minor gray']")

# 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

        assert s.xpath("//a/@target")[0].text == "_blank"

    def test_text_selection(self):
        html = """<div><p>expression: <var>x</var>+<var>y</var>=<var>z</var></p></div>"""
        s = Selector(html)
        assert s.xpath("//var/text()")[0].text == "x"
        assert s.xpath("//var")[0].text == "x"
        assert s.xpath("//var[last()]").text == ["z"]
        assert s.xpath("//var/text()").text == ["x", "y", "z"]
        assert s.xpath("//var").text == ["x", "y", "z"]
        assert s.xpath("//p")[0].text == "expression: x+y=z"

    def test_diff_between_string_and_text(self):
        html = """<div><p>expression: <var>x</var>+<var>y</var>=<var>z</var></p></div>"""
        s = Selector(html)
        assert s.xpath("//var")[0].text == "x"
        assert s.xpath("//var")[0].string == "<var>x</var>"
        assert s.xpath("//var").text == ["x", "y", "z"]
        assert s.xpath("//var").string == ["<var>x</var>", "<var>y</var>", "<var>z</var>"]

    def test_node_selection(self):
        html = """<p></p><p class='primary'>primary</p><p class="minor gray">minor</p>"""
        s = Selector(html)
        primary = s.xpath("//p[@class='primary']")
        assert len(primary) == 1 and primary[0].text == 'primary'
        minor = s.xpath("//p[@class='minor']")
        assert len(minor) == 0
        minor = s.xpath("//p[@class='gray minor']")
        assert len(minor) == 0
        minor = s.xpath("//p[@class='minor gray']")

        assert len(minor) == 1 and minor[0].text == 'minor'