# Path: fnapy/utils.py
# def extract_text(element, node_name):
#     """Extract the text from the selected node
# 
#     If no text is found, the empty string is returned.
# 
#     """
#     inner_element = find(element, node_name)
#     return inner_element.text if inner_element is not None else ""
# 
# def findall(element, node_name):
#     """A convenient function to look for nodes in the XML
# 
#     >>> nodes = findall(response.element, node_name)
# 
#     """
#     if "/" in node_name:
#         node_name = "//ns:".join(node_name.split("/"))
#     return element.findall(
#         ".//ns:{0}".format(node_name), namespaces={"ns": XHTML_NAMESPACE}
#     )
# 
# def find(element, node_name):
#     """Look for a node in the XML
# 
#     >>> node = find(response.element, node_name)
# 
#     """
#     if "/" in node_name:
#         node_name = "//ns:".join(node_name.split("/"))
#     return element.find(
#         ".//ns:{0}".format(node_name), namespaces={"ns": XHTML_NAMESPACE}
#     )
# 
# class Response(HttpMessage):
#     """A handy class to handle the response"""
# 
#     def __init__(self, content):
#         super(Response, self).__init__(content)
# 
# Path: fnapy/config.py
# XHTML_NAMESPACE = "http://www.fnac.com/schemas/mp-dialog.xsd"


import os
from lxml import etree
from fnapy.utils import extract_text, findall, find, Response
from fnapy.config import XHTML_NAMESPACE
#
# Distributed under terms of the MIT license.

"""
Tests for fnappy.utils module
"""



NAMESPACES = {'ns': XHTML_NAMESPACE}


def test_response_with_empty_content():
    """Response should not crash when its content is an empty string"""
    response = Response('')

    # The dict should be empty
    assert len(response.dict) == 0

    # The tag should be empty_content
    assert response.tag == 'empty_content'


def parse_xml_file(filename):
    return etree.parse(os.path.join(os.path.dirname(__file__), 'assets',
                                    filename))


def test_response():
    """Response should not crash with an empty string"""

# Path: fnapy/utils.py
# def extract_text(element, node_name):
#     """Extract the text from the selected node
# 
#     If no text is found, the empty string is returned.
# 
#     """
#     inner_element = find(element, node_name)
#     return inner_element.text if inner_element is not None else ""
# 
# def findall(element, node_name):
#     """A convenient function to look for nodes in the XML
# 
#     >>> nodes = findall(response.element, node_name)
# 
#     """
#     if "/" in node_name:
#         node_name = "//ns:".join(node_name.split("/"))
#     return element.findall(
#         ".//ns:{0}".format(node_name), namespaces={"ns": XHTML_NAMESPACE}
#     )
# 
# def find(element, node_name):
#     """Look for a node in the XML
# 
#     >>> node = find(response.element, node_name)
# 
#     """
#     if "/" in node_name:
#         node_name = "//ns:".join(node_name.split("/"))
#     return element.find(
#         ".//ns:{0}".format(node_name), namespaces={"ns": XHTML_NAMESPACE}
#     )
# 
# class Response(HttpMessage):
#     """A handy class to handle the response"""
# 
#     def __init__(self, content):
#         super(Response, self).__init__(content)
# 
# Path: fnapy/config.py
# XHTML_NAMESPACE = "http://www.fnac.com/schemas/mp-dialog.xsd"


# Path: tests/test_utils.py
import os
from lxml import etree
from fnapy.utils import extract_text, findall, find, Response
from fnapy.config import XHTML_NAMESPACE

#
# Distributed under terms of the MIT license.

"""
Tests for fnappy.utils module
"""



NAMESPACES = {'ns': XHTML_NAMESPACE}


def test_response_with_empty_content():
    """Response should not crash when its content is an empty string"""
    response = Response('')

    # The dict should be empty
    assert len(response.dict) == 0

    # The tag should be empty_content
    assert response.tag == 'empty_content'


def parse_xml_file(filename):
    return etree.parse(os.path.join(os.path.dirname(__file__), 'assets',
                                    filename))


def test_response():
    """Response should not crash with an empty string"""

    response = Response(b'')