1
1
import unittest
2
2
from cwltest import CompareFail
3
- from cwltest .utils import compare_file
3
+ from cwltest .utils import compare_file , compare
4
4
5
5
6
- class TestCompareFile (unittest .TestCase ):
6
+ class TestCompare (unittest .TestCase ):
7
7
8
- def test_general (self ):
8
+ def compare_success (self , expected , actual ):
9
+ try :
10
+ compare (expected , actual )
11
+ except CompareFail :
12
+ self .fail ("Comparison failed unexpectedly" )
13
+
14
+
15
+ class TestCompareFile (TestCompare ):
16
+
17
+ def test_compare_file (self ):
9
18
expected = {
10
19
"location" : "cores.txt" ,
11
20
"size" : 2 ,
@@ -21,8 +30,44 @@ def test_general(self):
21
30
"path" : "/var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt" ,
22
31
"size" : 2
23
32
}
24
-
25
33
try :
26
34
compare_file (expected , actual )
27
35
except CompareFail :
28
- self .fail ("File comparison failed unexpectedly" )
36
+ self .fail ("File comparison failed unexpectedly" )
37
+
38
+ def test_compare_contents_success (self ):
39
+ expected = {
40
+ "location" : "cores.txt" ,
41
+ "size" : 2 ,
42
+ "class" : "File" ,
43
+ "contents" : "2\n "
44
+ }
45
+
46
+ actual = {
47
+ "basename" : "cores.txt" ,
48
+ "checksum" : "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a" ,
49
+ "class" : "File" ,
50
+ "location" : "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt" ,
51
+ "path" : "tests/test-data/cores.txt" ,
52
+ "size" : 2
53
+ }
54
+ self .compare_success (expected , actual )
55
+
56
+ def test_compare_contents_failure (self ):
57
+ expected = {
58
+ "location" : "cores.txt" ,
59
+ "size" : 2 ,
60
+ "class" : "File" ,
61
+ "contents" : "2"
62
+ }
63
+
64
+ actual = {
65
+ "basename" : "cores.txt" ,
66
+ "checksum" : "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a" ,
67
+ "class" : "File" ,
68
+ "location" : "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt" ,
69
+ "path" : "tests/test-data/cores.txt" ,
70
+ "size" : 2
71
+ }
72
+ with self .assertRaises (CompareFail ):
73
+ compare_file (expected , actual )
0 commit comments