Skip to content

Commit 11b1a9e

Browse files
committed
Merge remote-tracking branch 'origin/master' into edge
2 parents be9297f + f6c07ac commit 11b1a9e

File tree

1 file changed

+65
-78
lines changed

1 file changed

+65
-78
lines changed

tests/test_mig_shared_fileio.py

Lines changed: 65 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,16 @@
2929
import binascii
3030
import os
3131
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
3533

3634
# NOTE: wrap next imports in try except to prevent autopep8 shuffling up
3735
try:
36+
from tests.support import MigTestCase, cleanpath, temppath, testmain
3837
import mig.shared.fileio as fileio
3938
except ImportError as ioe:
4039
print("Failed to import mig core modules: %s" % ioe)
4140
exit(1)
4241

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-
5142
DUMMY_BYTES = binascii.unhexlify('DEADBEEF') # 4 bytes
5243
DUMMY_BYTES_LENGTH = 4
5344
DUMMY_UNICODE = u'UniCode123½¾µßðþđŋħĸþł@ª€£$¥©®'
@@ -66,9 +57,7 @@ def setUp(self):
6657
cleanpath(os.path.dirname(DUMMY_FILE_WRITECHUNK), self)
6758

6859
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)
7261
self.assertFalse(did_succeed)
7362

7463
def test_return_false_on_invalid_offset(self):
@@ -108,35 +97,35 @@ def test_store_bytes_at_offset(self):
10897
"expected a hole was left")
10998
self.assertEqual(content[3:], DUMMY_BYTES)
11099

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)
140129

141130

142131
class MigSharedFileio__write_file(MigTestCase):
@@ -146,9 +135,7 @@ def setUp(self):
146135
cleanpath(os.path.dirname(DUMMY_FILE_WRITEFILE), self)
147136

148137
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)
152139
self.assertFalse(did_succeed)
153140

154141
def test_return_false_on_invalid_dir(self):
@@ -184,38 +171,38 @@ def test_store_bytes(self):
184171
self.assertEqual(len(content), DUMMY_BYTES_LENGTH)
185172
self.assertEqual(content[:], DUMMY_BYTES)
186173

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)
219206

220207

221208
if __name__ == '__main__':

0 commit comments

Comments
 (0)