2222
2323import io
2424
25- import unittest2
25+ try :
26+ import unittest
27+ except ImportError :
28+ import unittest2 as unittest
2629
2730from tests import testlib
2831
3235
3336def check_multiline (testcase , first , second , message = None ):
3437 """Assert that two multi-line strings are equal."""
35- testcase .assertTrue (isinstance (first , six .string_types ),
38+ testcase .assertTrue (isinstance (first , six .string_types ),
3639 'First argument is not a string' )
37- testcase .assertTrue (isinstance (second , six .string_types ),
40+ testcase .assertTrue (isinstance (second , six .string_types ),
3841 'Second argument is not a string' )
3942 # Unix-ize Windows EOL
4043 first = first .replace ("\r " , "" )
@@ -43,7 +46,7 @@ def check_multiline(testcase, first, second, message=None):
4346 testcase .fail ("Multiline strings are not equal: %s" % message )
4447
4548
46- # Run the given python script and return its exit code.
49+ # Run the given python script and return its exit code.
4750def run (script , stdin = None , stdout = PIPE , stderr = None ):
4851 process = start (script , stdin , stdout , stderr )
4952 process .communicate ()
@@ -74,7 +77,7 @@ def setUp(self):
7477 # Ignore result, it might already exist
7578 run ("index.py create sdk-tests" )
7679
77- @unittest2 .skipIf (six .PY3 , "Async needs work to support Python 3" )
80+ @unittest .skipIf (six .PY3 , "Async needs work to support Python 3" )
7881 def test_async (self ):
7982 result = run ("async/async.py sync" )
8083 self .assertEquals (result , 0 )
@@ -121,12 +124,12 @@ def test_event_types(self):
121124 self .check_commands (
122125 "event_types.py --help" ,
123126 "event_types.py" )
124-
127+
125128 def test_fired_alerts (self ):
126129 self .check_commands (
127130 "fired_alerts.py --help" ,
128131 "fired_alerts.py" )
129-
132+
130133 def test_follow (self ):
131134 self .check_commands ("follow.py --help" )
132135
@@ -140,7 +143,7 @@ def test_handlers(self):
140143
141144 # Run the cert handler example with a bad cert file, should error.
142145 result = run (
143- "handlers/handlers_certs.py --ca_file=handlers/cacert.bad.pem" ,
146+ "handlers/handlers_certs.py --ca_file=handlers/cacert.bad.pem" ,
144147 stderr = PIPE )
145148 self .assertNotEquals (result , 0 )
146149
@@ -185,7 +188,7 @@ def test_inputs(self):
185188 self .check_commands (
186189 "inputs.py --help" ,
187190 "inputs.py" )
188-
191+
189192 def test_job (self ):
190193 self .check_commands (
191194 "job.py --help" ,
@@ -197,7 +200,7 @@ def test_kvstore(self):
197200 self .check_commands (
198201 "kvstore.py --help" ,
199202 "kvstore.py" )
200-
203+
201204 def test_loggers (self ):
202205 self .check_commands (
203206 "loggers.py --help" ,
@@ -210,7 +213,7 @@ def test_saved_searches(self):
210213 self .check_commands (
211214 "saved_searches.py --help" ,
212215 "saved_searches.py" )
213-
216+
214217 def test_saved_search (self ):
215218 temp_name = testlib .tmpname ()
216219 self .check_commands (
@@ -227,7 +230,7 @@ def test_search(self):
227230 self .check_commands (
228231 "search.py --help" ,
229232 ["search.py" , "search * | head 10" ],
230- ["search.py" ,
233+ ["search.py" ,
231234 "search * | head 10 | stats count" , '--output_mode=csv' ])
232235
233236 def test_spcmd (self ):
@@ -271,7 +274,7 @@ def test_analytics(self):
271274 # Before we start, we'll clean the index
272275 index = service .indexes ["sdk-test" ]
273276 index .clean ()
274-
277+
275278 tracker .track ("test_event" , distinct_id = "abc123" , foo = "bar" , abc = "123" )
276279 tracker .track ("test_event" , distinct_id = "123abc" , abc = "12345" )
277280
@@ -280,8 +283,8 @@ def test_analytics(self):
280283
281284 # Now, we create a retriever to retrieve the events
282285 retriever = analytics .output .AnalyticsRetriever (
283- "sdk-test" , self .opts .kwargs , index = "sdk-test" )
284-
286+ "sdk-test" , self .opts .kwargs , index = "sdk-test" )
287+
285288 # Assert applications
286289 applications = retriever .applications ()
287290 self .assertEquals (len (applications ), 1 )
@@ -319,17 +322,17 @@ def test_analytics(self):
319322 count = value ["count" ]
320323 self .assertTrue (name in list (expected_property_values .keys ()))
321324 self .assertEqual (count , expected_property_values [name ])
322-
325+
323326 # Assert event over time
324327 over_time = retriever .events_over_time (
325328 time_range = analytics .output .TimeRange .MONTH )
326329 self .assertEquals (len (over_time ), 1 )
327330 self .assertEquals (len (over_time ["test_event" ]), 1 )
328331 self .assertEquals (over_time ["test_event" ][0 ]["count" ], 2 )
329332
330- # Now that we're done, we'll clean the index
333+ # Now that we're done, we'll clean the index
331334 index .clean ()
332-
335+
333336if __name__ == "__main__" :
334337 os .chdir ("../examples" )
335338 try :
0 commit comments