1919
2020from splunklib .searchcommands .internals import MetadataDecoder , MetadataEncoder , Recorder , RecordWriterV2
2121from splunklib .searchcommands import SearchMetric
22- from collections import deque , namedtuple , OrderedDict
22+ try :
23+ from collections import OrderedDict # must be python 2.7
24+ except ImportError :
25+ from splunklib .ordereddict import OrderedDict
26+ try :
27+ __named_tuple_check = namedtuple
28+ except NameError :
29+ # for Python 2.6
30+ from collections import namedtuple
2331from cStringIO import StringIO
2432from functools import wraps
2533from glob import iglob
2836from tempfile import mktemp
2937from time import time
3038from types import MethodType
31- from unittest import main , TestCase
39+ from sys import version_info as python_version
40+ try :
41+ from unittest2 import main , TestCase
42+ except ImportError :
43+ from unittest import main , TestCase
3244
3345import cPickle as pickle
3446import gzip
@@ -106,13 +118,18 @@ def test_object_view(self):
106118
107119 def test_recorder (self ):
108120
121+ if (python_version [0 ] == 2 and python_version [1 ] < 7 ):
122+ print ("Skipping test since we're on {1}" .format ("" .join (python_version )))
123+ pass
124+
109125 # Grab an input/output recording, the results of a prior countmatches run
110126
111127 recording = os .path .join (self ._package_path , 'recordings' , 'scpv2' , 'Splunk-6.3' , 'countmatches.' )
112128
113- with gzip .open (recording + 'input.gz' , 'rb' ) as file_1 , io .open (recording + 'output' , 'rb' ) as file_2 :
114- ifile = StringIO (file_1 .read ())
115- result = StringIO (file_2 .read ())
129+ with gzip .open (recording + 'input.gz' , 'rb' ) as file_1 :
130+ with io .open (recording + 'output' , 'rb' ) as file_2 :
131+ ifile = StringIO (file_1 .read ())
132+ result = StringIO (file_2 .read ())
116133
117134 # Set up the input/output recorders that are under test
118135
@@ -138,9 +155,10 @@ def test_recorder(self):
138155 ifile ._recording .close ()
139156 ofile ._recording .close ()
140157
141- with gzip .open (ifile ._recording .name , 'rb' ) as file_1 , gzip .open (ofile ._recording .name , 'rb' ) as file_2 :
142- self .assertEqual (file_1 .read (), ifile ._file .getvalue ())
143- self .assertEqual (file_2 .read (), ofile ._file .getvalue ())
158+ with gzip .open (ifile ._recording .name , 'rb' ) as file_1 :
159+ with gzip .open (ofile ._recording .name , 'rb' ) as file_2 :
160+ self .assertEqual (file_1 .read (), ifile ._file .getvalue ())
161+ self .assertEqual (file_2 .read (), ofile ._file .getvalue ())
144162
145163 finally :
146164 ofile ._recording .close ()
0 commit comments