|
| 1 | +# coding: utf-8 |
1 | 2 | from __future__ import unicode_literals |
2 | 3 |
|
3 | 4 | import errno |
@@ -68,23 +69,23 @@ def test_not_exists(self): |
68 | 69 | with self.assertRaises(errors.CreateFailed): |
69 | 70 | fs = osfs.OSFS("/does/not/exists/") |
70 | 71 |
|
71 | | - @unittest.skipIf(osfs.sendfile is None, 'sendfile not supported') |
| 72 | + @unittest.skipIf(osfs.sendfile is None, "sendfile not supported") |
72 | 73 | def test_copy_sendfile(self): |
73 | 74 | # try copying using sendfile |
74 | | - with mock.patch.object(osfs, 'sendfile') as sendfile: |
75 | | - sendfile.side_effect = OSError(errno.ENOTSUP, 'sendfile not supported') |
| 75 | + with mock.patch.object(osfs, "sendfile") as sendfile: |
| 76 | + sendfile.side_effect = OSError(errno.ENOTSUP, "sendfile not supported") |
76 | 77 | self.test_copy() |
77 | 78 | # check other errors are transmitted |
78 | | - self.fs.touch('foo') |
79 | | - with mock.patch.object(osfs, 'sendfile') as sendfile: |
| 79 | + self.fs.touch("foo") |
| 80 | + with mock.patch.object(osfs, "sendfile") as sendfile: |
80 | 81 | sendfile.side_effect = OSError(errno.EWOULDBLOCK) |
81 | 82 | with self.assertRaises(OSError): |
82 | | - self.fs.copy('foo', 'foo_copy') |
| 83 | + self.fs.copy("foo", "foo_copy") |
83 | 84 | # check parent exist and is dir |
84 | 85 | with self.assertRaises(errors.ResourceNotFound): |
85 | | - self.fs.copy('foo', 'spam/eggs') |
| 86 | + self.fs.copy("foo", "spam/eggs") |
86 | 87 | with self.assertRaises(errors.DirectoryExpected): |
87 | | - self.fs.copy('foo', 'foo_copy/foo') |
| 88 | + self.fs.copy("foo", "foo_copy/foo") |
88 | 89 |
|
89 | 90 | def test_create(self): |
90 | 91 | """Test create=True""" |
@@ -131,3 +132,12 @@ def test_symlinks(self): |
131 | 132 | bar_info = self.fs.getinfo("bar", namespaces=["link", "lstat"]) |
132 | 133 | self.assertIn("link", bar_info.raw) |
133 | 134 | self.assertIn("lstat", bar_info.raw) |
| 135 | + |
| 136 | + def test_validatepath(self): |
| 137 | + """Check validatepath detects bad encodings.""" |
| 138 | + |
| 139 | + with mock.patch("fs.osfs.fsencode") as fsencode: |
| 140 | + fsencode.side_effect = lambda error: "–".encode("ascii") |
| 141 | + with self.assertRaises(errors.InvalidCharsInPath): |
| 142 | + with self.fs.open("13 – Marked Register.pdf", "wb") as fh: |
| 143 | + fh.write(b"foo") |
0 commit comments