<s> import re <EOL> import glob <EOL> import xml . etree . ElementTree as ET <EOL> from os import path , environ <EOL> from tmc . exercise_tests . basetest import BaseTest , TestResult <EOL> class CheckTest ( BaseTest ) : <EOL> def __init__ ( self ) : <EOL> super ( ) . __init__ ( "<STR_LIT>" ) <EOL> def applies_to ( self , exercise ) : <EOL> src_path = path . join ( exercise . path ( ) , "<STR_LIT:src>" ) <EOL> return all ( [ <NUM_LIT:0> < len ( glob . glob ( path . join ( src_path , "<STR_LIT>" ) ) ) , <EOL> <NUM_LIT:0> == len ( glob . glob ( path . join ( src_path , "<STR_LIT>" ) ) ) ] ) <EOL> def test ( self , exercise ) : <EOL> _ , _ , err = self . run ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:all>" , "<STR_LIT>" ] , exercise ) <EOL> ret = [ ] <EOL> testpath = path . join ( exercise . path ( ) , "<STR_LIT:test>" , "<STR_LIT>" ) <EOL> if not path . isfile ( testpath ) : <EOL> return [ TestResult ( success = False , message = err ) ] <EOL> if len ( err ) > <NUM_LIT:0> : <EOL> ret . append ( TestResult ( message = err , warning = True ) ) <EOL> xmlsrc = "<STR_LIT>" <EOL> with open ( testpath ) as fp : <EOL> xmlsrc = fp . read ( ) <EOL> xmlsrc = re . sub ( r"<STR_LIT>" , r"<STR_LIT>" , xmlsrc ) <EOL> ns = "<STR_LIT>" <EOL> matchtest = ns + "<STR_LIT:test>" <EOL> matchdesc = ns + "<STR_LIT:description>" <EOL> matchmsg = ns + "<STR_LIT:message>" <EOL> root = ET . fromstring ( xmlsrc ) <EOL> for test in root . iter ( matchtest ) : <EOL> name = test . find ( matchdesc ) . text <EOL> if test . get ( "<STR_LIT:result>" ) in [ "<STR_LIT>" , "<STR_LIT:error>" ] : <EOL> success = False <EOL> message = test . find ( matchmsg ) . text <EOL> message = message . replace ( r"<STR_LIT>" , "<STR_LIT:&>" ) <EOL> else : <EOL> success = True <EOL> message = "<STR_LIT>" <EOL> ret . append ( TestResult ( success = success , name = name , message = message ) ) <EOL> self . name = "<STR_LIT>" <EOL> err , _ , trace = self . run ( [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] , exercise , <EOL> silent = True , env = dict ( environ , CK_FORK = "<STR_LIT>" ) ) <EOL> success = err == <NUM_LIT:0> <EOL> ret . append ( TestResult ( success = success , name = "<STR_LIT>" , message = trace ) ) <EOL> return ret </s>
