示例#1
0
    def test_writing_events_on_event_writer(self):
        """Write a pair of events with an EventWriter, and ensure that they
        are being encoded immediately and correctly onto the output stream"""
        out = StringIO()
        err = StringIO()

        ew = EventWriter(out, err)

        e = Event(data="This is a test of the emergency broadcast system.",
                  stanza="fubar",
                  time="%.3f" % 1372275124.466,
                  host="localhost",
                  index="main",
                  source="hilda",
                  sourcetype="misc",
                  done=True,
                  unbroken=True)
        ew.write_event(e)

        found = ET.fromstring("%s</stream>" % out.getvalue())
        expected = ET.parse(
            data_open("data/stream_with_one_event.xml")).getroot()

        self.assertTrue(xml_compare(expected, found))
        self.assertEqual(err.getvalue(), "")

        ew.write_event(e)
        ew.close()

        found = ET.fromstring(out.getvalue())
        expected = ET.parse(
            data_open("data/stream_with_two_events.xml")).getroot()

        self.assertTrue(xml_compare(expected, found))
    def test_writing_events_on_event_writer(self):
        """Write a pair of events with an EventWriter, and ensure that they
        are being encoded immediately and correctly onto the output stream"""
        out = StringIO()
        err = StringIO()

        ew = EventWriter(out, err)

        e = Event(
            data="This is a test of the emergency broadcast system.",
            stanza="fubar",
            time="%.3f" % 1372275124.466,
            host="localhost",
            index="main",
            source="hilda",
            sourcetype="misc",
            done=True,
            unbroken=True
        )
        ew.write_event(e)

        found = ET.fromstring("%s</stream>" % out.getvalue())
        expected = ET.parse(data_open("data/stream_with_one_event.xml")).getroot()

        self.assertTrue(xml_compare(expected, found))
        self.assertEqual(err.getvalue(), "")

        ew.write_event(e)
        ew.close()

        found = ET.fromstring(out.getvalue())
        expected = ET.parse(data_open("data/stream_with_two_events.xml")).getroot()

        self.assertTrue(xml_compare(expected, found))
示例#3
0
def test_writing_events_on_event_writer(capsys):
    """Write a pair of events with an EventWriter, and ensure that they
    are being encoded immediately and correctly onto the output stream"""

    ew = EventWriter(sys.stdout, sys.stderr)

    e = Event(data="This is a test of the emergency broadcast system.",
              stanza="fubar",
              time="%.3f" % 1372275124.466,
              host="localhost",
              index="main",
              source="hilda",
              sourcetype="misc",
              done=True,
              unbroken=True)
    ew.write_event(e)

    captured = capsys.readouterr()

    first_out_part = captured.out

    with data_open("data/stream_with_one_event.xml") as data:
        found = ET.fromstring("%s</stream>" % first_out_part)
        expected = ET.parse(data).getroot()

        assert xml_compare(expected, found)
        assert captured.err == ""

    ew.write_event(e)
    ew.close()

    captured = capsys.readouterr()
    with data_open("data/stream_with_two_events.xml") as data:
        found = ET.fromstring(first_out_part + captured.out)
        expected = ET.parse(data).getroot()

        assert xml_compare(expected, found)