3
3
import sys
4
4
import shutil
5
5
import tempfile
6
+ import subprocess
6
7
from cyaron import IO , Compare , log
7
8
from cyaron .output_capture import captured_output
8
9
from cyaron .graders .mismatch import *
10
+ from cyaron .compare import CompareMismatch
9
11
10
12
log .set_verbose ()
11
13
@@ -48,7 +50,9 @@ def test_noipstyle_incorrect(self):
48
50
try :
49
51
with captured_output () as (out , err ):
50
52
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
52
56
self .assertEqual (e .content , 'test123\r \n test124 ' )
53
57
self .assertEqual (e .std , 'test123 \n test123\n \n ' )
54
58
self .assertEqual (str (e ), 'On line 2 column 7, read 4, expected 3.' )
@@ -74,7 +78,9 @@ def test_fulltext_program(self):
74
78
try :
75
79
with captured_output () as (out , err ):
76
80
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
78
84
self .assertEqual (e .content , '2\n ' )
79
85
self .assertEqual (e .std , '1\n ' )
80
86
self .assertEqual (e .content_hash , '53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3' )
@@ -106,3 +112,13 @@ def test_concurrent(self):
106
112
finally :
107
113
for io in ios :
108
114
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