Skip to content

Commit

Permalink
Redo byte reading/writing tests
Browse files Browse the repository at this point in the history
This adds a general case for all supported Python versions and specific
cases for Py2 vs Py3 behavior when reading/writing files.
  • Loading branch information
dougluce committed Jan 14, 2016
1 parent 6e40760 commit d4e1663
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions fake_filesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2077,8 +2077,8 @@ def testUnicodeContents(self):
self.assertEqual(contents, text_fractions)

@unittest.skipIf(sys.version_info >= (3, 0),
'Does not work on Python3 per issue #63')
def testByteContents(self):
'Python2-specific behavior')
def testByteContentsPy2(self):
self.file = fake_filesystem.FakeFileOpen(self.filesystem)
file_path = 'foo'
byte_fractions = b'\xe2\x85\x93 \xe2\x85\x94 \xe2\x85\x95 \xe2\x85\x96'
Expand All @@ -2088,6 +2088,28 @@ def testByteContents(self):
contents = f.read()
self.assertEqual(contents, byte_fractions)

@unittest.skipIf(sys.version_info < (3, 0),
'Python3-specific behavior')
def testByteContentsPy3(self):
self.file = fake_filesystem.FakeFileOpen(self.filesystem)
file_path = 'foo'
byte_fractions = b'\xe2\x85\x93 \xe2\x85\x94 \xe2\x85\x95 \xe2\x85\x96'
with self.file(file_path, 'wb') as f:
f.write(byte_fractions)
with self.file(file_path) as f:
contents = f.read()
self.assertEqual(contents, byte_fractions.decode('utf-8'))

def testByteContents(self):
self.file = fake_filesystem.FakeFileOpen(self.filesystem)
file_path = 'foo'
byte_fractions = b'\xe2\x85\x93 \xe2\x85\x94 \xe2\x85\x95 \xe2\x85\x96'
with self.file(file_path, 'wb') as f:
f.write(byte_fractions)
with self.file(file_path, 'rb') as f:
contents = f.read()
self.assertEqual(contents, byte_fractions)

def testOpenValidFile(self):
contents = [
'I am he as\n',
Expand Down

0 comments on commit d4e1663

Please sign in to comment.