-
Notifications
You must be signed in to change notification settings - Fork 68
Raise exception when open with write mode in call stack #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
a7ac50f
81e92d3
5b135a9
ee69c9b
35edbb0
6395eb5
e6c2bae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,11 @@ | |
|
||
import pytest | ||
|
||
from cloudpathlib.exceptions import CloudPathIsADirectoryError, DirectoryNotEmptyError | ||
from cloudpathlib.exceptions import ( | ||
BuiltInOpenWriteError, | ||
CloudPathIsADirectoryError, | ||
DirectoryNotEmptyError, | ||
) | ||
|
||
|
||
def test_file_discovery(rig): | ||
|
@@ -109,7 +113,51 @@ def test_fspath(rig): | |
assert os.fspath(p) == p.fspath | ||
|
||
|
||
def test_os_open(rig): | ||
def test_os_open_read(rig): | ||
p = rig.create_cloud_path("dir_0/file0_0.txt") | ||
with open(p, "r") as f: | ||
assert f.readable() | ||
|
||
|
||
# entire function is passed as source, so check separately | ||
# that all of the built in open write modes fail | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is interesting. I thought it was a feature of my previous version of the test that the function would have both safe and unsafe Anyways, I think some additional things we want to test:
|
||
def test_os_open_write0(rig): | ||
p = rig.create_cloud_path("dir_0/file0_0.txt") | ||
|
||
with pytest.raises(BuiltInOpenWriteError): | ||
with open(p, "w") as f: | ||
assert f.readable() | ||
|
||
|
||
def test_os_open_write1(rig): | ||
p = rig.create_cloud_path("dir_0/file0_0.txt") | ||
|
||
with pytest.raises(BuiltInOpenWriteError): | ||
with open(p, "wb") as f: | ||
assert f.readable() | ||
|
||
|
||
def test_os_open_write2(rig): | ||
p = rig.create_cloud_path("dir_0/file0_0.txt") | ||
|
||
with pytest.raises(BuiltInOpenWriteError): | ||
with open(p, "a") as f: | ||
assert f.readable() | ||
|
||
|
||
def test_os_open_write3(rig): | ||
p = rig.create_cloud_path("dir_0/file0_0.txt") | ||
|
||
with pytest.raises(BuiltInOpenWriteError): | ||
with open(p, "r+") as f: | ||
assert f.readable() | ||
|
||
|
||
def test_os_open_write4(rig): | ||
p = rig.create_cloud_path("dir_0/file0_0.txt") | ||
with pytest.raises(BuiltInOpenWriteError): | ||
with open( | ||
p, | ||
"w", | ||
) as f: | ||
assert f.readable() |
Uh oh!
There was an error while loading. Please reload this page.