|
12 | 12 | from fs.osfs import OSFS |
13 | 13 |
|
14 | 14 |
|
15 | | -@unittest.skipIf(platform.system() == "Darwin", "Bad unicode not possible on OSX") |
16 | | -class TestEncoding(unittest.TestCase): |
17 | | - |
18 | | - TEST_FILENAME = b"foo\xb1bar" |
19 | | - TEST_FILENAME_UNICODE = fs.fsdecode(TEST_FILENAME) |
20 | | - |
21 | | - def setUp(self): |
22 | | - dir_path = self.dir_path = tempfile.mkdtemp() |
23 | | - if six.PY2: |
24 | | - with open(os.path.join(dir_path, self.TEST_FILENAME), "wb") as f: |
25 | | - f.write(b"baz") |
26 | | - else: |
27 | | - with open(os.path.join(dir_path, self.TEST_FILENAME_UNICODE), "wb") as f: |
28 | | - f.write(b"baz") |
29 | | - |
30 | | - def tearDown(self): |
31 | | - shutil.rmtree(self.dir_path) |
32 | | - |
33 | | - def test_open(self): |
34 | | - with OSFS(self.dir_path) as test_fs: |
35 | | - self.assertTrue(test_fs.exists(self.TEST_FILENAME_UNICODE)) |
36 | | - self.assertTrue(test_fs.isfile(self.TEST_FILENAME_UNICODE)) |
37 | | - self.assertFalse(test_fs.isdir(self.TEST_FILENAME_UNICODE)) |
38 | | - with test_fs.open(self.TEST_FILENAME_UNICODE, "rb") as f: |
39 | | - self.assertEqual(f.read(), b"baz") |
40 | | - self.assertEqual(test_fs.readtext(self.TEST_FILENAME_UNICODE), "baz") |
41 | | - test_fs.remove(self.TEST_FILENAME_UNICODE) |
42 | | - self.assertFalse(test_fs.exists(self.TEST_FILENAME_UNICODE)) |
43 | | - |
44 | | - def test_listdir(self): |
45 | | - with OSFS(self.dir_path) as test_fs: |
46 | | - dirlist = test_fs.listdir("/") |
47 | | - self.assertEqual(dirlist, [self.TEST_FILENAME_UNICODE]) |
48 | | - self.assertEqual(test_fs.readtext(dirlist[0]), "baz") |
49 | | - |
50 | | - def test_scandir(self): |
51 | | - with OSFS(self.dir_path) as test_fs: |
52 | | - for info in test_fs.scandir("/"): |
53 | | - self.assertIsInstance(info.name, six.text_type) |
54 | | - self.assertEqual(info.name, self.TEST_FILENAME_UNICODE) |
| 15 | +if platform.system() != "Windows": |
| 16 | + |
| 17 | + @unittest.skipIf(platform.system() == "Darwin", "Bad unicode not possible on OSX") |
| 18 | + class TestEncoding(unittest.TestCase): |
| 19 | + |
| 20 | + TEST_FILENAME = b"foo\xb1bar" |
| 21 | + # fsdecode throws error on Windows |
| 22 | + TEST_FILENAME_UNICODE = fs.fsdecode(TEST_FILENAME) |
| 23 | + |
| 24 | + def setUp(self): |
| 25 | + dir_path = self.dir_path = tempfile.mkdtemp() |
| 26 | + if six.PY2: |
| 27 | + with open(os.path.join(dir_path, self.TEST_FILENAME), "wb") as f: |
| 28 | + f.write(b"baz") |
| 29 | + else: |
| 30 | + with open( |
| 31 | + os.path.join(dir_path, self.TEST_FILENAME_UNICODE), "wb" |
| 32 | + ) as f: |
| 33 | + f.write(b"baz") |
| 34 | + |
| 35 | + def tearDown(self): |
| 36 | + shutil.rmtree(self.dir_path) |
| 37 | + |
| 38 | + def test_open(self): |
| 39 | + with OSFS(self.dir_path) as test_fs: |
| 40 | + self.assertTrue(test_fs.exists(self.TEST_FILENAME_UNICODE)) |
| 41 | + self.assertTrue(test_fs.isfile(self.TEST_FILENAME_UNICODE)) |
| 42 | + self.assertFalse(test_fs.isdir(self.TEST_FILENAME_UNICODE)) |
| 43 | + with test_fs.open(self.TEST_FILENAME_UNICODE, "rb") as f: |
| 44 | + self.assertEqual(f.read(), b"baz") |
| 45 | + self.assertEqual(test_fs.readtext(self.TEST_FILENAME_UNICODE), "baz") |
| 46 | + test_fs.remove(self.TEST_FILENAME_UNICODE) |
| 47 | + self.assertFalse(test_fs.exists(self.TEST_FILENAME_UNICODE)) |
| 48 | + |
| 49 | + def test_listdir(self): |
| 50 | + with OSFS(self.dir_path) as test_fs: |
| 51 | + dirlist = test_fs.listdir("/") |
| 52 | + self.assertEqual(dirlist, [self.TEST_FILENAME_UNICODE]) |
| 53 | + self.assertEqual(test_fs.readtext(dirlist[0]), "baz") |
| 54 | + |
| 55 | + def test_scandir(self): |
| 56 | + with OSFS(self.dir_path) as test_fs: |
| 57 | + for info in test_fs.scandir("/"): |
| 58 | + self.assertIsInstance(info.name, six.text_type) |
| 59 | + self.assertEqual(info.name, self.TEST_FILENAME_UNICODE) |
0 commit comments