docs(notion-writer): fix Task 2 upload tests to mock builtins.open
upload() opens the file before subprocess.run; the two upload tests must mock open() so the nonexistent /tmp paths don't raise FileNotFoundError. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -165,7 +165,10 @@ def test_upload_returns_id():
|
|||||||
stdout="43833259-72ae-404e-8441-b6577f3159b4\tphoto.png\tuploaded\n",
|
stdout="43833259-72ae-404e-8441-b6577f3159b4\tphoto.png\tuploaded\n",
|
||||||
stderr="",
|
stderr="",
|
||||||
)
|
)
|
||||||
with mock.patch("subprocess.run", return_value=fake):
|
# upload() opens the file before subprocess.run; mock open so the file
|
||||||
|
# need not exist (subprocess.run is mocked and never reads the handle).
|
||||||
|
with mock.patch("builtins.open", mock.mock_open(read_data=b"x")), \
|
||||||
|
mock.patch("subprocess.run", return_value=fake):
|
||||||
upload_id = ntn_files.upload(Path("/tmp/photo.png"))
|
upload_id = ntn_files.upload(Path("/tmp/photo.png"))
|
||||||
assert upload_id == "43833259-72ae-404e-8441-b6577f3159b4"
|
assert upload_id == "43833259-72ae-404e-8441-b6577f3159b4"
|
||||||
|
|
||||||
@@ -175,7 +178,8 @@ def test_upload_failure_raises():
|
|||||||
fake = subprocess.CompletedProcess(
|
fake = subprocess.CompletedProcess(
|
||||||
args=[], returncode=1, stdout="", stderr="boom: invalid file",
|
args=[], returncode=1, stdout="", stderr="boom: invalid file",
|
||||||
)
|
)
|
||||||
with mock.patch("subprocess.run", return_value=fake):
|
with mock.patch("builtins.open", mock.mock_open(read_data=b"x")), \
|
||||||
|
mock.patch("subprocess.run", return_value=fake):
|
||||||
try:
|
try:
|
||||||
ntn_files.upload(Path("/tmp/bad.png"))
|
ntn_files.upload(Path("/tmp/bad.png"))
|
||||||
assert False, "expected NtnUploadError"
|
assert False, "expected NtnUploadError"
|
||||||
|
|||||||
Reference in New Issue
Block a user