2
2
# coding: utf-8
3
3
4
4
import os
5
- import sys
6
5
import unittest
6
+
7
+ try :
8
+ from unittest import mock # Python 3+
9
+ except ImportError :
10
+ import mock # Python 2.7
11
+
7
12
from mpyq import MPQArchive
13
+ import six
8
14
9
15
TEST_DIR = os .path .realpath (os .path .dirname (__file__ )) + '/'
10
16
@@ -13,6 +19,10 @@ class TestMPQArchive(unittest.TestCase):
13
19
def setUp (self ):
14
20
self .archive = MPQArchive (TEST_DIR + 'test.SC2Replay' )
15
21
22
+ def tearDown (self ):
23
+ self .archive .close ()
24
+ self .archive = None
25
+
16
26
def test_init_with_file (self ):
17
27
self .archive = MPQArchive (open (TEST_DIR + 'test.SC2Replay' , 'rb' ))
18
28
@@ -41,9 +51,10 @@ def test_files(self):
41
51
b'replay.smartcam.events' ,
42
52
b'replay.sync.events' ])
43
53
44
- def test_print_hash_table (self ):
54
+ @mock .patch ('sys.stdout' , new_callable = six .StringIO )
55
+ def test_print_hash_table (self , mock_stdout ):
45
56
self .archive .print_hash_table ()
46
- self .assertEqual (sys . stdout .getvalue (),
57
+ self .assertEqual (mock_stdout .getvalue (),
47
58
"MPQ archive hash table\n "
48
59
"----------------------\n "
49
60
" Hash A Hash B Locl Plat BlockIdx\n "
@@ -65,9 +76,10 @@ def test_print_hash_table(self):
65
76
"31952289 6A5FFAA3 0000 0000 00000003\n "
66
77
"\n " )
67
78
68
- def test_print_block_table (self ):
79
+ @mock .patch ('sys.stdout' , new_callable = six .StringIO )
80
+ def test_print_block_table (self , mock_stdout ):
69
81
self .archive .print_block_table ()
70
- self .assertEqual (sys . stdout .getvalue (),
82
+ self .assertEqual (mock_stdout .getvalue (),
71
83
"MPQ archive block table\n "
72
84
"-----------------------\n "
73
85
" Offset ArchSize RealSize Flags\n "
@@ -82,3 +94,7 @@ def test_print_block_table(self):
82
94
"00031DDE 120 164 81000200\n "
83
95
"00031E56 254 288 81000200\n "
84
96
"\n " )
97
+
98
+
99
+ if __name__ == '__main__' :
100
+ unittest .main ()
0 commit comments