# Path: pyxmpp2/test/_support.py
# DATA_DIR = os.path.join(TEST_DIR, "data")
# 
# Path: pyxmpp2/xmppparser.py
# COMMON_NS = "http://pyxmpp.jajcus.net/xmlns/common"
# class XMLStreamHandler(object):
# class ParserTarget(object):
# class StreamReader(object):
#     def stream_start(self, element):
#     def stream_end(self):
#     def stream_element(self, element):
#     def stream_parse_error(self, descr):
#     def stream_eof(self):
#     def __init__(self, handler):
#     def data(self, data):
#     def start(self, tag, attrs):
#     def close(self):
#     def end(self, tag):
#     def __init__(self, handler):
#     def feed(self, data):
# 
# Path: pyxmpp2/utils.py
# def xml_elements_equal(element1, element2, ignore_level1_cdata = False):
#     """Check if two XML elements are equal.
# 
#     :Parameters:
#         - `element1`: the first element to compare
#         - `element2`: the other element to compare
#         - `ignore_level1_cdata`: if direct text children of the elements
#           should be ignored for the comparision
#     :Types:
#         - `element1`: :etree:`ElementTree.Element`
#         - `element2`: :etree:`ElementTree.Element`
#         - `ignore_level1_cdata`: `bool`
# 
#     :Returntype: `bool`
#     """
#     # pylint: disable-msg=R0911
#     if None in (element1, element2) or element1.tag != element2.tag:
#         return False
#     attrs1 = element1.items()
#     attrs1.sort()
#     attrs2 = element2.items()
#     attrs2.sort()
# 
#     if not ignore_level1_cdata:
#         if element1.text != element2.text:
#             return False
# 
#     if attrs1 != attrs2:
#         return False
# 
#     if len(element1) != len(element2):
#         return False
#     for child1, child2 in zip(element1, element2):
#         if child1.tag != child2.tag:
#             return False
#         if not ignore_level1_cdata:
#             if element1.text != element2.text:
#                 return False
#         if not xml_elements_equal(child1, child2):
#             return False
#     return True
# 
# Path: pyxmpp2/test/_support.py
# def load_tests(loader, tests, pattern):
#     """Use default test list, just remove the classes which names start with
#     '_'."""
#     # pylint: disable=W0613
#     suite = filter_tests(tests)
#     return suite
# 
# def setup_logging():
#     """Set up logging for the tests.
# 
#     Log level used depends on number of '-v' in sys.argv
#     """
#     # pylint: disable=W0603
#     global logging_ready
#     if logging_ready:
#         return
#     if sys.argv.count("-v") > 2:
#         logging.basicConfig(level=logging.DEBUG)
#     elif sys.argv.count("-v") == 2:
#         logging.basicConfig(level=logging.INFO)
#     else:
#         logging.basicConfig(level=logging.ERROR)
#     logging_ready = True


import os
import logging
import unittest
from pyxmpp2.test._support import DATA_DIR
from xml.etree import ElementTree
from pyxmpp2 import xmppparser
from pyxmpp2.utils import xml_elements_equal
from pyxmpp2.test._support import load_tests, setup_logging
    def stream_start(self, element):
        self.test_case.event("start", element)
    def stream_end(self):
        self.test_case.event("end", None)
    def stream_element(self, element):
        self.test_case.event("node", element)

# pylint: disable=C0103
expected_events = []
# pylint: disable=C0103
whole_stream = None

def load_expected_events():
    with open(os.path.join(DATA_DIR, "stream_info.txt")) as stream_info:
        for line in stream_info:
            if line.startswith("#"):
                continue
            line = line.strip()
            expected_events.append(EventTemplate(line))

def load_whole_stream():
    # pylint: disable=W0603
    global whole_stream
    whole_stream = ElementTree.parse(os.path.join(DATA_DIR, "stream.xml"))

class TestStreamReader(unittest.TestCase):
    def setUp(self):
        self.expected_events = list(expected_events)
        self.handler = StreamHandler(self)
        self.reader = xmppparser.StreamReader(self.handler)

# Path: pyxmpp2/test/_support.py
# DATA_DIR = os.path.join(TEST_DIR, "data")
# 
# Path: pyxmpp2/xmppparser.py
# COMMON_NS = "http://pyxmpp.jajcus.net/xmlns/common"
# class XMLStreamHandler(object):
# class ParserTarget(object):
# class StreamReader(object):
#     def stream_start(self, element):
#     def stream_end(self):
#     def stream_element(self, element):
#     def stream_parse_error(self, descr):
#     def stream_eof(self):
#     def __init__(self, handler):
#     def data(self, data):
#     def start(self, tag, attrs):
#     def close(self):
#     def end(self, tag):
#     def __init__(self, handler):
#     def feed(self, data):
# 
# Path: pyxmpp2/utils.py
# def xml_elements_equal(element1, element2, ignore_level1_cdata = False):
#     """Check if two XML elements are equal.
# 
#     :Parameters:
#         - `element1`: the first element to compare
#         - `element2`: the other element to compare
#         - `ignore_level1_cdata`: if direct text children of the elements
#           should be ignored for the comparision
#     :Types:
#         - `element1`: :etree:`ElementTree.Element`
#         - `element2`: :etree:`ElementTree.Element`
#         - `ignore_level1_cdata`: `bool`
# 
#     :Returntype: `bool`
#     """
#     # pylint: disable-msg=R0911
#     if None in (element1, element2) or element1.tag != element2.tag:
#         return False
#     attrs1 = element1.items()
#     attrs1.sort()
#     attrs2 = element2.items()
#     attrs2.sort()
# 
#     if not ignore_level1_cdata:
#         if element1.text != element2.text:
#             return False
# 
#     if attrs1 != attrs2:
#         return False
# 
#     if len(element1) != len(element2):
#         return False
#     for child1, child2 in zip(element1, element2):
#         if child1.tag != child2.tag:
#             return False
#         if not ignore_level1_cdata:
#             if element1.text != element2.text:
#                 return False
#         if not xml_elements_equal(child1, child2):
#             return False
#     return True
# 
# Path: pyxmpp2/test/_support.py
# def load_tests(loader, tests, pattern):
#     """Use default test list, just remove the classes which names start with
#     '_'."""
#     # pylint: disable=W0613
#     suite = filter_tests(tests)
#     return suite
# 
# def setup_logging():
#     """Set up logging for the tests.
# 
#     Log level used depends on number of '-v' in sys.argv
#     """
#     # pylint: disable=W0603
#     global logging_ready
#     if logging_ready:
#         return
#     if sys.argv.count("-v") > 2:
#         logging.basicConfig(level=logging.DEBUG)
#     elif sys.argv.count("-v") == 2:
#         logging.basicConfig(level=logging.INFO)
#     else:
#         logging.basicConfig(level=logging.ERROR)
#     logging_ready = True


# Path: pyxmpp2/test/stream_reader.py
import os
import logging
import unittest
from pyxmpp2.test._support import DATA_DIR
from xml.etree import ElementTree
from pyxmpp2 import xmppparser
from pyxmpp2.utils import xml_elements_equal
from pyxmpp2.test._support import load_tests, setup_logging

    def stream_start(self, element):
        self.test_case.event("start", element)
    def stream_end(self):
        self.test_case.event("end", None)
    def stream_element(self, element):
        self.test_case.event("node", element)

# pylint: disable=C0103
expected_events = []
# pylint: disable=C0103
whole_stream = None

def load_expected_events():
    with open(os.path.join(DATA_DIR, "stream_info.txt")) as stream_info:
        for line in stream_info:
            if line.startswith("#"):
                continue
            line = line.strip()
            expected_events.append(EventTemplate(line))

def load_whole_stream():
    # pylint: disable=W0603
    global whole_stream
    whole_stream = ElementTree.parse(os.path.join(DATA_DIR, "stream.xml"))

class TestStreamReader(unittest.TestCase):
    def setUp(self):
        self.expected_events = list(expected_events)
        self.handler = StreamHandler(self)
        self.reader = xmppparser.StreamReader(self.handler)

        self.file = open(os.path.join(DATA_DIR, "stream.xml"))