@@ -350,7 +350,7 @@ def resolve_path(self, path):
350
350
def get_absolute_path (self , path ):
351
351
return os .path .join (self .root , path )
352
352
353
- def get_file (self , path ):
353
+ def get_file (self , path , need_content ):
354
354
path = self .resolve_path (path )
355
355
if path in self .files :
356
356
return self .files [path ]
@@ -359,6 +359,9 @@ def get_file(self, path):
359
359
if not (os .path .exists (abspath ) and os .path .isfile (abspath )):
360
360
raise FailedCheck ('File does not exist {!r}' .format (path ))
361
361
362
+ if not need_content :
363
+ return None
364
+
362
365
with io .open (abspath , encoding = 'utf-8' ) as f :
363
366
data = f .read ()
364
367
self .files [path ] = data
@@ -614,15 +617,15 @@ def check_command(c, cache):
614
617
# has <path> = file existence
615
618
if len (c .args ) == 1 and not regexp and 'raw' not in c .cmd :
616
619
try :
617
- cache .get_file (c .args [0 ])
620
+ cache .get_file (c .args [0 ], False )
618
621
ret = True
619
622
except FailedCheck as err :
620
623
cerr = str (err )
621
624
ret = False
622
625
# hasraw/matchesraw <path> <pat> = string test
623
626
elif len (c .args ) == 2 and 'raw' in c .cmd :
624
627
cerr = "`PATTERN` did not match"
625
- ret = check_string (cache .get_file (c .args [0 ]), c .args [1 ], regexp )
628
+ ret = check_string (cache .get_file (c .args [0 ], True ), c .args [1 ], regexp )
626
629
# has/matches <path> <pat> <match> = XML tree test
627
630
elif len (c .args ) == 3 and 'raw' not in c .cmd :
628
631
cerr = "`XPATH PATTERN` did not match"
0 commit comments