Skip to content

Commit

Permalink
Issue #74: Testing test_datasets.py, using subprocess.run() with stdo…
Browse files Browse the repository at this point in the history
…ut option.
  • Loading branch information
bongjinkoo committed May 17, 2022
1 parent bf15165 commit 8951bb4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
30 changes: 23 additions & 7 deletions ioSPI/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def ls(self):
"""List all files in the project."""
print(f"Listing files from OSF project: {self.project_id}...")
# os.system("osf ls")
subprocess.check_output(f"osf ls", shell=True, text=True)
subprocess.run(
f"osf ls", shell=True, text=True, check=True, stdout=subprocess.PIPE
)

def download(self, remote_path: str, local_path: str):
"""Download a file from an OSF project and save it locally.
Expand All @@ -82,8 +84,12 @@ def download(self, remote_path: str, local_path: str):
full_remote_path = self.storage + "/" + remote_path
print(f"Downloading {full_remote_path} to {local_path}...")
# os.system(f"osf fetch {full_remote_path} {local_path}")
subprocess.check_output(
f"osf fetch {full_remote_path} {local_path}", shell=True, text=True
subprocess.run(
f"osf fetch {full_remote_path} {local_path}",
shell=True,
text=True,
check=True,
stdout=subprocess.PIPE,
)
print("Done!")

Expand Down Expand Up @@ -114,9 +120,13 @@ def upload(self, local_path: str, remote_path: str):
full_remote_path = self.storage + "/" + remote_path
print(f"Uploading {local_path} to {full_remote_path}...")
# os.system(f"osf upload {local_path} {full_remote_path}")
f = subprocess.check_output(
f"osf upload {local_path} {full_remote_path}", shell=True, text=True
)
f = subprocess.run(
f"osf upload {local_path} {full_remote_path}",
shell=True,
text=True,
check=True,
stdout=subprocess.PIPE,
).stdout
print(io.StringIO(f).readlines())
print("Done!")

Expand All @@ -138,5 +148,11 @@ def remove(self, remote_path: str):
full_remote_path = self.storage + "/" + remote_path
print(f"Removing {full_remote_path} in the project...")
# os.system(f"osf remove {full_remote_path}")
subprocess.check_output(f"osf remove {full_remote_path}", shell=True, text=True)
subprocess.run(
f"osf remove {full_remote_path}",
shell=True,
text=True,
check=True,
stdout=subprocess.PIPE,
)
print("Done!")
12 changes: 9 additions & 3 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ def test_constructor_invalid_because_no_token():

def test_upload_valid(setup, set_file_path):
"""Test the upload method."""
file_list = subprocess.check_output("osf ls", shell=True, text=True)
file_list = subprocess.run(
"osf ls", shell=True, text=True, check=True, stdout=subprocess.PIPE
).stdout
print(io.StringIO(file_list).readlines())

setup.upload(set_file_path[0] + set_file_path[1], set_file_path[1])
file_exists = False
# file_list = os.popen("osf ls")
file_list = subprocess.check_output("osf ls", shell=True, text=True)
file_list = subprocess.run(
"osf ls", shell=True, text=True, check=True, stdout=subprocess.PIPE
).stdout
file_list = io.StringIO(file_list)
line = file_list.readline()
while line:
Expand Down Expand Up @@ -112,7 +116,9 @@ def test_remove_valid(setup, set_file_path):
setup.remove(set_file_path[1])
file_exists = False
# file_list = os.popen("osf ls")
file_list = subprocess.check_output("osf ls", shell=True, text=True)
file_list = subprocess.run(
"osf ls", shell=True, text=True, check=True, stdout=subprocess.PIPE
).stdout
file_list = io.StringIO(file_list)
line = file_list.readline()
while line:
Expand Down

0 comments on commit 8951bb4

Please sign in to comment.