Skip to content

Commit

Permalink
Patch fs test to be compatible with Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Feb 29, 2024
1 parent d332a6f commit f98d501
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/pcloud/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ def file_write(self, **kwargs):
files = [("file", ("upload-file.io", BytesIO(kwargs.pop("data"))))]
kwargs["fd"] = str(kwargs["fd"])
return self._upload("file_write", files, **kwargs)
# return self._do_request("file_write", **kwargs)

@RequiredParameterCheck(("fd",))
def file_pwrite(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/pcloud/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

PORT = 65432
REDIRECT_URL = f"http://localhost:{PORT}/"
AUTHORIZE_URL = f"https://my.pcloud.com/oauth2/authorize"
AUTHORIZE_URL = "https://my.pcloud.com/oauth2/authorize"


class HTTPServerHandler(BaseHTTPRequestHandler):
Expand Down
33 changes: 33 additions & 0 deletions src/pcloud/tests/test_pyfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest
import uuid

from fs import errors
from fs.test import FSTestCases
from pcloud.pcloudfs import PCloudFS

Expand Down Expand Up @@ -35,3 +36,35 @@ def setUp(self):
# override to not destroy filesystem
def tearDown(self):
self.pcloudfs.pcloud.deletefolderrecursive(folderid=self.testdirid)

# This is a literal copy of the test_remove test of the FSTestCases
# without using the deprecated 'assertRaisesRegexp',
# which was removed in Python 3.12.
# Remove this method once this is fixed in the 'fs'-package itself
def test_remove(self):
self.fs.writebytes("foo1", b"test1")
self.fs.writebytes("foo2", b"test2")
self.fs.writebytes("foo3", b"test3")

self.assert_isfile("foo1")
self.assert_isfile("foo2")
self.assert_isfile("foo3")

self.fs.remove("foo2")

self.assert_isfile("foo1")
self.assert_not_exists("foo2")
self.assert_isfile("foo3")

with self.assertRaises(errors.ResourceNotFound):
self.fs.remove("bar")

self.fs.makedir("dir")
with self.assertRaises(errors.FileExpected):
self.fs.remove("dir")

self.fs.makedirs("foo/bar/baz/")

error_msg = "resource 'foo/bar/egg/test.txt' not found"
with self.assertRaisesRegex(errors.ResourceNotFound, error_msg):
self.fs.remove("foo/bar/egg/test.txt")

0 comments on commit f98d501

Please sign in to comment.