Skip to content

Commit

Permalink
fized implementation with context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
hechth committed Nov 28, 2023
1 parent 18a735d commit 7b0a71d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
49 changes: 44 additions & 5 deletions tests/irods_session_testing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -21,16 +21,55 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"file = session.data_objects.open(\"/tempZone/existing_file.txt\", \"w\", allow_redirect=False)\n",
"file.write(\"test\".encode())\n",
"file.close()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[b'test']\n"
]
}
],
"source": [
"file = session.data_objects.open(\"/tempZone/existing_file.txt\", \"r\", allow_redirect=False)\n",
"print(file.readlines())\n",
"file.close()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"file.close()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<iRODSDataObject 10323 existing_file.txt>"
"<iRODSDataObject 10486 existing_file.txt>"
]
},
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
8 changes: 6 additions & 2 deletions tests/test_iRODSFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ def test_wrap(fs: iRODSFS, path: str, expected:str):
def test_openbin(fs: iRODSFS):
with fs.openbin("/home/rods/existing_file.txt", mode="w") as f:
assert f.writable()
assert f.readable()
assert f.closed == False
f.write("test".encode())
assert f.readlines() == ["test"]
assert f.closed == True

with fs.openbin("/home/rods/existing_file.txt", mode="r") as f:
assert f.readable()
assert f.readlines() == [b"test"]
assert f.closed == True

fs.remove("/home/rods/existing_file.txt")


Expand Down

0 comments on commit 7b0a71d

Please sign in to comment.