1- from __future__ import division
2-
3- import errno
41import os
5- import shutil
62import stat
7- from sys import stderr
8-
9- try :
10- import simplejson as json
11- except ImportError :
12- import json
3+ import shutil
4+ import json
135
14- from datetime import datetime
15- from .utils import DEFAULT_HOOK_PATH
16- from .exceptions import HookError
6+ from test .basetest .exceptions import HookError
177
188
19- class InvalidJSON ( object ) :
9+ class InvalidJSON :
2010 """
2111 Object representing the original unparsed JSON string and the JSON error
2212 """
@@ -30,15 +20,12 @@ def json_decoder(string):
3020 Attempt to decode a JSON string and in case of error return an
3121 InvalidJSON object
3222 """
33- decoder = json .JSONDecoder ().decode
34-
3523 try :
36- return decoder (string )
37- except ValueError as e :
24+ return json . loads (string )
25+ except json . JSONDecodeError as e :
3826 return InvalidJSON (string , str (e ))
3927
40-
41- class Hooks (object ):
28+ class Hooks :
4229 """
4330 Abstraction to help interact with hooks (add, remove) during tests and
4431 keep track of which are active.
@@ -153,13 +140,13 @@ def clear(self):
153140 shutil .rmtree (self .hookdir )
154141 except OSError as e :
155142 # If the hookdir folder doesn't exist, no harm done and keep going
156- if e .errno != errno . ENOENT :
143+ if e .errno != 2 : # 2 is the errno for ENOENT
157144 raise
158145
159146 os .mkdir (self .hookdir )
160147
161148
162- class Hook ( object ) :
149+ class Hook :
163150 """
164151 Represents a hook script and provides methods to enable/disable hooks
165152 """
@@ -258,14 +245,13 @@ def _check_hook_type(self):
258245 if self .hookname .startswith (hooktype ):
259246 break
260247 else :
261- stderr .write ("WARNING: {0} is not a valid hook type. "
262- "It will not be triggered\n " .format (self .hookname ))
248+ print ("WARNING: {0} is not a valid hook type. It will not be triggered" .format (self .hookname ), file = os .sys .stderr )
263249
264250 def _remove_file (self , file ):
265251 try :
266252 os .remove (file )
267253 except OSError as e :
268- if e .errno == errno . ENOENT :
254+ if e .errno == 2 : # 2 is the errno for ENOENT
269255 raise HookError ("Hook with name {0} was not found on hooks/ folder" .format (file ))
270256 else :
271257 raise
0 commit comments