1616
1717from splunklib .modularinput .modularinput_testlib import unittest , xml_compare
1818from splunklib .modularinput .event import Event , ET
19- from splunklib .modularinput .event_writer import EventWriter
20-
21- try :
22- import cStringIO as StringIO
23- except ImportError :
24- import StringIO
19+ from splunklib .modularinput .event_writer import EventWriter , StringIO
2520
2621class EventTestCase (unittest .TestCase ):
2722 def test_event_without_enough_fields_fails (self ):
2823 """Check that events without data throw an error"""
2924 with self .assertRaises (ValueError ):
3025 event = Event ()
31- stream = StringIO . StringIO ()
26+ stream = StringIO ()
3227 event .write_to (stream )
3328 self .assertTrue (True )
3429
3530 def test_xml_of_event_with_minimal_configuration (self ):
36- """Generate XML from an event object with a small number of fields, and see if it matches what we expect."""
31+ """Generate XML from an event object with a small number of fields,
32+ and see if it matches what we expect."""
3733
38- stream = StringIO . StringIO ()
34+ stream = StringIO ()
3935 event = Event ()
4036 event .time = "%.3f" % 1372187084.000
4137 event .stanza = "fubar"
@@ -48,8 +44,9 @@ def test_xml_of_event_with_minimal_configuration(self):
4844 self .assertTrue (xml_compare (expected , constructed ))
4945
5046 def test_xml_of_event_with_more_configuration (self ):
51- """Generate XML from an even object with all fields set, see if it matches what we expect"""
52- stream = StringIO .StringIO ()
47+ """Generate XML from an even object with all fields set, see if
48+ it matches what we expect"""
49+ stream = StringIO ()
5350
5451 event = Event ()
5552 event .stanza = "fubar"
@@ -69,10 +66,10 @@ def test_xml_of_event_with_more_configuration(self):
6966 self .assertTrue (xml_compare (expected , constructed ))
7067
7168 def test_writing_events_on_event_writer (self ):
72- """Write a pair of events with an EventWriter, and ensure that they are
73- being encoded immediately and correctly onto the output stream"""
74- out = StringIO . StringIO ()
75- err = StringIO . StringIO ()
69+ """Write a pair of events with an EventWriter, and ensure that they
70+ are being encoded immediately and correctly onto the output stream"""
71+ out = StringIO ()
72+ err = StringIO ()
7673
7774 ew = EventWriter (out , err )
7875
@@ -103,10 +100,11 @@ def test_writing_events_on_event_writer(self):
103100 self .assertTrue (xml_compare (expected , found ))
104101
105102 def test_error_in_event_writer (self ):
106- """An event which cannot write itself onto an output stream (such as because it doesn't have a data field set)
103+ """An event which cannot write itself onto an output stream
104+ (such as because it doesn't have a data field set)
107105 should write an error. Check that it does so."""
108- out = StringIO . StringIO ()
109- err = StringIO . StringIO ()
106+ out = StringIO ()
107+ err = StringIO ()
110108
111109 ew = EventWriter (out , err )
112110 e = Event ()
@@ -116,9 +114,10 @@ def test_error_in_event_writer(self):
116114 self .assertTrue (err .getvalue ().startswith (ew .WARN ))
117115
118116 def test_logging_errors_with_event_writer (self ):
119- """Check that the log method on EventWriter produces the expected error message."""
120- out = StringIO .StringIO ()
121- err = StringIO .StringIO ()
117+ """Check that the log method on EventWriter produces the
118+ expected error message."""
119+ out = StringIO ()
120+ err = StringIO ()
122121
123122 ew = EventWriter (out , err )
124123
@@ -127,9 +126,10 @@ def test_logging_errors_with_event_writer(self):
127126 self .assertEqual ("ERROR Something happened!\n " , err .getvalue ())
128127
129128 def test_write_xml_is_sane (self ):
130- """Check that EventWriter.writeXmlDocument writes sensible XML to the output stream."""
131- out = StringIO .StringIO ()
132- err = StringIO .StringIO ()
129+ """Check that EventWriter.writeXmlDocument writes sensible
130+ XML to the output stream."""
131+ out = StringIO ()
132+ err = StringIO ()
133133
134134 ew = EventWriter (out , err )
135135
0 commit comments