1515# License for the specific language governing permissions and limitations
1616# under the License.
1717
18- from __future__ import absolute_import , division , print_function , unicode_literals
19-
20- from splunklib .six .moves import cStringIO as StringIO
21- try :
22- from unittest2 import main , TestCase
23- except ImportError :
24- from unittest import main , TestCase
2518
2619import os
2720import sys
2821import logging
2922
3023import pytest
24+ from unittest import main , TestCase
25+ from splunklib .six .moves import cStringIO as StringIO
26+
3127
3228from splunklib .searchcommands import environment
3329from splunklib .searchcommands .decorators import Configuration
@@ -117,18 +113,18 @@ def test_logging_configuration(self):
117113 except ValueError :
118114 pass
119115 except BaseException as e :
120- self .fail ('Expected ValueError, but {} was raised' . format ( type ( e )) )
116+ self .fail (f 'Expected ValueError, but { type ( e ) } was raised' )
121117 else :
122- self .fail ('Expected ValueError, but logging_configuration={}' . format ( command .logging_configuration ) )
118+ self .fail (f 'Expected ValueError, but logging_configuration={ command .logging_configuration } ' )
123119
124120 try :
125121 command .logging_configuration = os .path .join (package_directory , 'non-existent.logging.conf' )
126122 except ValueError :
127123 pass
128124 except BaseException as e :
129- self .fail ('Expected ValueError, but {} was raised' . format ( type ( e )) )
125+ self .fail (f 'Expected ValueError, but { type ( e ) } was raised' )
130126 else :
131- self .fail ('Expected ValueError, but logging_configuration={}' . format ( command .logging_configuration ) )
127+ self .fail (f 'Expected ValueError, but logging_configuration={ command .logging_configuration } ' )
132128
133129 def test_logging_level (self ):
134130
@@ -146,7 +142,7 @@ def test_logging_level(self):
146142 self .assertEqual (warning , command .logging_level )
147143
148144 for level in level_names ():
149- if type (level ) is int :
145+ if isinstance (level , int ) :
150146 command .logging_level = level
151147 level_name = logging .getLevelName (level )
152148 self .assertEqual (command .logging_level , warning if level_name == notset else level_name )
@@ -171,9 +167,9 @@ def test_logging_level(self):
171167 except ValueError :
172168 pass
173169 except BaseException as e :
174- self .fail ('Expected ValueError, but {} was raised' . format ( type ( e )) )
170+ self .fail (f 'Expected ValueError, but { type ( e ) } was raised' )
175171 else :
176- self .fail ('Expected ValueError, but logging_level={}' . format ( command .logging_level ) )
172+ self .fail (f 'Expected ValueError, but logging_level={ command .logging_level } ' )
177173
178174 self .assertEqual (command .logging_level , current_value )
179175
@@ -211,13 +207,9 @@ def _test_boolean_option(self, option):
211207 except ValueError :
212208 pass
213209 except BaseException as error :
214- self .fail ('Expected ValueError when setting {}={}, but {} was raised' .format (
215- option .name , repr (value ), type (error )))
210+ self .fail (f'Expected ValueError when setting { option .name } ={ repr (value )} , but { type (error )} was raised' )
216211 else :
217- self .fail ('Expected ValueError, but {}={} was accepted.' .format (
218- option .name , repr (option .fget (command ))))
219-
220- return
212+ self .fail (f'Expected ValueError, but { option .name } ={ repr (option .fget (command ))} was accepted.' )
221213
222214
223215if __name__ == "__main__" :
0 commit comments