@@ -350,7 +350,7 @@ def resolve_path(self, path):
350350 def get_absolute_path (self , path ):
351351 return os .path .join (self .root , path )
352352
353- def get_file (self , path ):
353+ def get_file (self , path , need_content ):
354354 path = self .resolve_path (path )
355355 if path in self .files :
356356 return self .files [path ]
@@ -359,6 +359,9 @@ def get_file(self, path):
359359 if not (os .path .exists (abspath ) and os .path .isfile (abspath )):
360360 raise FailedCheck ('File does not exist {!r}' .format (path ))
361361
362+ if not need_content :
363+ return None
364+
362365 with io .open (abspath , encoding = 'utf-8' ) as f :
363366 data = f .read ()
364367 self .files [path ] = data
@@ -614,15 +617,15 @@ def check_command(c, cache):
614617 # has <path> = file existence
615618 if len (c .args ) == 1 and not regexp and 'raw' not in c .cmd :
616619 try :
617- cache .get_file (c .args [0 ])
620+ cache .get_file (c .args [0 ], False )
618621 ret = True
619622 except FailedCheck as err :
620623 cerr = str (err )
621624 ret = False
622625 # hasraw/matchesraw <path> <pat> = string test
623626 elif len (c .args ) == 2 and 'raw' in c .cmd :
624627 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 )
626629 # has/matches <path> <pat> <match> = XML tree test
627630 elif len (c .args ) == 3 and 'raw' not in c .cmd :
628631 cerr = "`XPATH PATTERN` did not match"
0 commit comments