29
29
import binascii
30
30
import os
31
31
import sys
32
-
33
- # TODO: remove this as it should not be needed with PYTHONPATH properly set
34
- #sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), ".")))
32
+ import unittest
35
33
36
34
# NOTE: wrap next imports in try except to prevent autopep8 shuffling up
37
35
try :
36
+ from tests .support import MigTestCase , cleanpath , temppath , testmain
38
37
import mig .shared .fileio as fileio
39
38
except ImportError as ioe :
40
39
print ("Failed to import mig core modules: %s" % ioe )
41
40
exit (1 )
42
41
43
- # NOTE: prevent autopep8 shuffling next imports up
44
- try :
45
- from support import MigTestCase , cleanpath , temppath , testmain
46
- except ImportError as ioe :
47
- print ("Failed to import mig test modules: %s" % ioe )
48
- exit (1 )
49
-
50
-
51
42
DUMMY_BYTES = binascii .unhexlify ('DEADBEEF' ) # 4 bytes
52
43
DUMMY_BYTES_LENGTH = 4
53
44
DUMMY_UNICODE = u'UniCode123½¾µßðþđŋħĸþł@ª€£$¥©®'
@@ -66,9 +57,7 @@ def setUp(self):
66
57
cleanpath (os .path .dirname (DUMMY_FILE_WRITECHUNK ), self )
67
58
68
59
def test_return_false_on_invalid_data (self ):
69
- # NOTE: we make sure to disable any forced stringification here
70
- did_succeed = fileio .write_chunk (self .tmp_path , 1234 , 0 , self .logger ,
71
- force_string = False )
60
+ did_succeed = fileio .write_chunk (self .tmp_path , 1234 , 0 , self .logger )
72
61
self .assertFalse (did_succeed )
73
62
74
63
def test_return_false_on_invalid_offset (self ):
@@ -108,35 +97,35 @@ def test_store_bytes_at_offset(self):
108
97
"expected a hole was left" )
109
98
self .assertEqual (content [3 :], DUMMY_BYTES )
110
99
111
- # TODO: enable again - requires the temporarily disabled auto mode select
112
- # def test_store_bytes_in_text_mode(self):
113
- # fileio.write_chunk(self.tmp_path, DUMMY_BYTES, 0, self.logger,
114
- # mode="r+")
115
- #
116
- # with open(self.tmp_path, 'rb') as file:
117
- # content = file.read(1024)
118
- # self.assertEqual(len(content), DUMMY_BYTES_LENGTH)
119
- # self.assertEqual(content[:], DUMMY_BYTES)
120
-
121
- # TODO: enable again - requires the temporarily disabled auto mode select
122
- # def test_store_unicode(self):
123
- # fileio.write_chunk(self.tmp_path, DUMMY_UNICODE, 0, self.logger,
124
- # mode='r+')
125
- #
126
- # with open(self.tmp_path, 'r') as file:
127
- # content = file.read(1024)
128
- # self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
129
- # self.assertEqual(content[:], DUMMY_UNICODE)
130
-
131
- # TODO: enable again - requires the temporarily disabled auto mode select
132
- # def test_store_unicode_in_binary_mode(self):
133
- # fileio.write_chunk(self.tmp_path, DUMMY_UNICODE, 0, self.logger,
134
- # mode='r+b')
135
- #
136
- # with open(self.tmp_path, 'r') as file:
137
- # content = file.read(1024)
138
- # self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
139
- # self.assertEqual(content[:], DUMMY_UNICODE)
100
+ @ unittest . skip ( " TODO: enable again - requires the temporarily disabled auto mode select" )
101
+ def test_store_bytes_in_text_mode (self ):
102
+ fileio .write_chunk (self .tmp_path , DUMMY_BYTES , 0 , self .logger ,
103
+ mode = "r+" )
104
+
105
+ with open (self .tmp_path , 'rb' ) as file :
106
+ content = file .read (1024 )
107
+ self .assertEqual (len (content ), DUMMY_BYTES_LENGTH )
108
+ self .assertEqual (content [:], DUMMY_BYTES )
109
+
110
+ @ unittest . skip ( " TODO: enable again - requires the temporarily disabled auto mode select" )
111
+ def test_store_unicode (self ):
112
+ fileio .write_chunk (self .tmp_path , DUMMY_UNICODE , 0 , self .logger ,
113
+ mode = 'r+' )
114
+
115
+ with open (self .tmp_path , 'r' ) as file :
116
+ content = file .read (1024 )
117
+ self .assertEqual (len (content ), DUMMY_UNICODE_LENGTH )
118
+ self .assertEqual (content [:], DUMMY_UNICODE )
119
+
120
+ @ unittest . skip ( " TODO: enable again - requires the temporarily disabled auto mode select" )
121
+ def test_store_unicode_in_binary_mode (self ):
122
+ fileio .write_chunk (self .tmp_path , DUMMY_UNICODE , 0 , self .logger ,
123
+ mode = 'r+b' )
124
+
125
+ with open (self .tmp_path , 'r' ) as file :
126
+ content = file .read (1024 )
127
+ self .assertEqual (len (content ), DUMMY_UNICODE_LENGTH )
128
+ self .assertEqual (content [:], DUMMY_UNICODE )
140
129
141
130
142
131
class MigSharedFileio__write_file (MigTestCase ):
@@ -146,9 +135,7 @@ def setUp(self):
146
135
cleanpath (os .path .dirname (DUMMY_FILE_WRITEFILE ), self )
147
136
148
137
def test_return_false_on_invalid_data (self ):
149
- # NOTE: we make sure to disable any forced stringification here
150
- did_succeed = fileio .write_file (1234 , self .tmp_path , self .logger ,
151
- force_string = False )
138
+ did_succeed = fileio .write_file (1234 , self .tmp_path , self .logger )
152
139
self .assertFalse (did_succeed )
153
140
154
141
def test_return_false_on_invalid_dir (self ):
@@ -184,38 +171,38 @@ def test_store_bytes(self):
184
171
self .assertEqual (len (content ), DUMMY_BYTES_LENGTH )
185
172
self .assertEqual (content [:], DUMMY_BYTES )
186
173
187
- # TODO: enable again - requires the temporarily disabled auto mode select
188
- # def test_store_bytes_in_text_mode(self):
189
- # did_succeed = fileio.write_file(DUMMY_BYTES, self.tmp_path, self.logger,
190
- # mode="w")
191
- # self.assertTrue(did_succeed)
192
- #
193
- # with open(self.tmp_path, 'rb') as file:
194
- # content = file.read(1024)
195
- # self.assertEqual(len(content), DUMMY_BYTES_LENGTH)
196
- # self.assertEqual(content[:], DUMMY_BYTES)
197
-
198
- # TODO: enable again - requires the temporarily disabled auto mode select
199
- # def test_store_unicode(self):
200
- # did_succeed = fileio.write_file(DUMMY_UNICODE, self.tmp_path,
201
- # self.logger, mode='w')
202
- # self.assertTrue(did_succeed)
203
- #
204
- # with open(self.tmp_path, 'r') as file:
205
- # content = file.read(1024)
206
- # self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
207
- # self.assertEqual(content[:], DUMMY_UNICODE)
208
-
209
- # TODO: enable again - requires the temporarily disabled auto mode select
210
- # def test_store_unicode_in_binary_mode(self):
211
- # did_succeed = fileio.write_file(DUMMY_UNICODE, self.tmp_path,
212
- # self.logger, mode='wb')
213
- # self.assertTrue(did_succeed)
214
- #
215
- # with open(self.tmp_path, 'r') as file:
216
- # content = file.read(1024)
217
- # self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
218
- # self.assertEqual(content[:], DUMMY_UNICODE)
174
+ @ unittest . skip ( " TODO: enable again - requires the temporarily disabled auto mode select" )
175
+ def test_store_bytes_in_text_mode (self ):
176
+ did_succeed = fileio .write_file (DUMMY_BYTES , self .tmp_path , self .logger ,
177
+ mode = "w" )
178
+ self .assertTrue (did_succeed )
179
+
180
+ with open (self .tmp_path , 'rb' ) as file :
181
+ content = file .read (1024 )
182
+ self .assertEqual (len (content ), DUMMY_BYTES_LENGTH )
183
+ self .assertEqual (content [:], DUMMY_BYTES )
184
+
185
+ @ unittest . skip ( " TODO: enable again - requires the temporarily disabled auto mode select" )
186
+ def test_store_unicode (self ):
187
+ did_succeed = fileio .write_file (DUMMY_UNICODE , self .tmp_path ,
188
+ self .logger , mode = 'w' )
189
+ self .assertTrue (did_succeed )
190
+
191
+ with open (self .tmp_path , 'r' ) as file :
192
+ content = file .read (1024 )
193
+ self .assertEqual (len (content ), DUMMY_UNICODE_LENGTH )
194
+ self .assertEqual (content [:], DUMMY_UNICODE )
195
+
196
+ @ unittest . skip ( " TODO: enable again - requires the temporarily disabled auto mode select" )
197
+ def test_store_unicode_in_binary_mode (self ):
198
+ did_succeed = fileio .write_file (DUMMY_UNICODE , self .tmp_path ,
199
+ self .logger , mode = 'wb' )
200
+ self .assertTrue (did_succeed )
201
+
202
+ with open (self .tmp_path , 'r' ) as file :
203
+ content = file .read (1024 )
204
+ self .assertEqual (len (content ), DUMMY_UNICODE_LENGTH )
205
+ self .assertEqual (content [:], DUMMY_UNICODE )
219
206
220
207
221
208
if __name__ == '__main__' :
0 commit comments