Raise IOError instead of OSError for open() with trailing separator

- fixes #362
diff --git a/pyfakefs/fake_filesystem.py b/pyfakefs/fake_filesystem.py
index 4511c55..3106b71 100644
--- a/pyfakefs/fake_filesystem.py
+++ b/pyfakefs/fake_filesystem.py
@@ -4653,7 +4653,7 @@
                 error = (errno.EINVAL if self.filesystem.is_windows_fs
                          else errno.ENOENT if self.filesystem.is_macos
                          else errno.EISDIR)
-                self.filesystem.raise_os_error(error, file_path)
+                error_fct(error, file_path)
             file_object = self.filesystem.create_file_internally(
                 real_path, create_missing_dirs=False,
                 apply_umask=True, raw_io=self.raw_io)
diff --git a/tests/fake_os_test.py b/tests/fake_os_test.py
index d06c458..ddcd0c0 100644
--- a/tests/fake_os_test.py
+++ b/tests/fake_os_test.py
@@ -407,6 +407,23 @@
             self.assertEqual(errno.ENOENT, os_error.errno)
             self.assertEqual(file_path, os_error.filename)
 
+    def check_open_with_trailing_sep(self, error_nr):
+        # regression test for #362
+        path0 = self.make_path('foo') + self.os.path.sep
+        self.assert_raises_io_error(error_nr, self.open, path0, 'w')
+
+    def test_open_with_trailing_sep_linux(self):
+        self.check_linux_only()
+        self.check_open_with_trailing_sep(errno.EISDIR)
+
+    def test_open_with_trailing_sep_macos(self):
+        self.check_macos_only()
+        self.check_open_with_trailing_sep(errno.ENOENT)
+
+    def test_open_with_trailing_sep_windows(self):
+        self.check_windows_only()
+        self.check_open_with_trailing_sep(errno.EINVAL)
+
     def test_readlink(self):
         self.skip_if_symlink_not_supported()
         link_path = self.make_path('foo', 'bar', 'baz')