1"""
2Test case for ZipFS binary file reading/writing
3Passes ok on Linux, fails on Windows (tested: Win7, 64-bit):
4
5AssertionError: ' \r\n' != ' \n'
6"""
7
8import unittest
9from fs.zipfs import ZipFS
10import os
11
12from six import b
13
14class ZipFsBinaryWriteRead(unittest.TestCase):
15    test_content = b(chr(32) + chr(10))
16
17    def setUp(self):
18        self.z = ZipFS('test.zip', 'w')
19
20    def tearDown(self):
21        try:
22            os.remove('test.zip')
23        except:
24            pass
25
26    def test_binary_write_read(self):
27        # GIVEN zipfs
28        z = self.z
29
30        # WHEN binary data is written to a test file in zipfs
31        f = z.open('test.data', 'wb')
32        f.write(self.test_content)
33        f.close()
34        z.close()
35
36        # THEN the same binary data is retrieved when opened again
37        z = ZipFS('test.zip', 'r')
38        f = z.open('test.data', 'rb')
39        content = f.read()
40        f.close()
41        z.close()
42        self.assertEqual(content, self.test_content)
43
44if __name__ == '__main__':
45    unittest.main()
46