33import sys
44import shutil
55import tempfile
6+ import subprocess
67from cyaron import IO , Compare , log
78from cyaron .output_capture import captured_output
89from cyaron .graders .mismatch import *
10+ from cyaron .compare import CompareMismatch
911
1012log .set_verbose ()
1113
@@ -48,7 +50,9 @@ def test_noipstyle_incorrect(self):
4850 try :
4951 with captured_output () as (out , err ):
5052 Compare .output ("test_another_incorrect.out" , std = io )
51- except TextMismatch as e :
53+ except CompareMismatch as e :
54+ self .assertEqual (e .name , 'test_another_incorrect.out' )
55+ e = e .mismatch
5256 self .assertEqual (e .content , 'test123\r \n test124 ' )
5357 self .assertEqual (e .std , 'test123 \n test123\n \n ' )
5458 self .assertEqual (str (e ), 'On line 2 column 7, read 4, expected 3.' )
@@ -74,7 +78,9 @@ def test_fulltext_program(self):
7478 try :
7579 with captured_output () as (out , err ):
7680 Compare .program ("python correct.py" , "python incorrect.py" , std = io , input = io , grader = "FullText" )
77- except HashMismatch as e :
81+ except CompareMismatch as e :
82+ self .assertEqual (e .name , 'python incorrect.py' )
83+ e = e .mismatch
7884 self .assertEqual (e .content , '2\n ' )
7985 self .assertEqual (e .std , '1\n ' )
8086 self .assertEqual (e .content_hash , '53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3' )
@@ -106,3 +112,13 @@ def test_concurrent(self):
106112 finally :
107113 for io in ios :
108114 io .close ()
115+
116+ def test_timeout (self ):
117+ if sys .version_info >= (3 , 3 ):
118+ with IO () as test :
119+ try :
120+ Compare .program (((sys .executable , '-c' , '__import__(\' time\' ).sleep(10)' ), 1 ), std = test , input = test )
121+ except subprocess .TimeoutExpired :
122+ pass
123+ else :
124+ self .assertTrue (False )
0 commit comments