From 3cd92d2f9d9aedcb2eed33e2c5f823d19346766a Mon Sep 17 00:00:00 2001 From: Bongjin Koo Date: Mon, 16 May 2022 16:20:43 -0700 Subject: [PATCH] Issue #74: Testing test_datasets.py, using subprocess.run(). --- ioSPI/datasets.py | 10 ++++++---- tests/test_datasets.py | 8 ++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ioSPI/datasets.py b/ioSPI/datasets.py index 54ec0de..e7d022c 100644 --- a/ioSPI/datasets.py +++ b/ioSPI/datasets.py @@ -57,7 +57,7 @@ def ls(self): """List all files in the project.""" print(f"Listing files from OSF project: {self.project_id}...") # os.system("osf ls") - subprocess.run(["osf", "ls"], text=True, capture_output=True) + subprocess.run(f"osf ls", shell=True, text=True, capture_output=True) def download(self, remote_path: str, local_path: str): """Download a file from an OSF project and save it locally. @@ -83,7 +83,8 @@ def download(self, remote_path: str, local_path: str): print(f"Downloading {full_remote_path} to {local_path}...") # os.system(f"osf fetch {full_remote_path} {local_path}") subprocess.run( - ["osf", "fetch", f"{full_remote_path}, f{local_path}"], + f"osf fetch {full_remote_path} {local_path}", + shell=True, text=True, capture_output=True, ) @@ -117,7 +118,8 @@ def upload(self, local_path: str, remote_path: str): print(f"Uploading {local_path} to {full_remote_path}...") # os.system(f"osf upload {local_path} {full_remote_path}") subprocess.run( - ["osf", "upload", f"{local_path}", f"{full_remote_path}"], + f"osf upload {local_path} {full_remote_path}", + shell=True, text=True, capture_output=True, ) @@ -142,6 +144,6 @@ def remove(self, remote_path: str): print(f"Removing {full_remote_path} in the project...") # os.system(f"osf remove {full_remote_path}") subprocess.run( - ["osf", "remove", f"{full_remote_path}"], text=True, capture_output=True + f"osf remove {full_remote_path}", shell=True, text=True, capture_output=True ) print("Done!") diff --git a/tests/test_datasets.py b/tests/test_datasets.py index 5051a0b..bba97ea 100644 --- a/tests/test_datasets.py +++ b/tests/test_datasets.py @@ -58,7 +58,9 @@ def test_upload_valid(setup, set_file_path): 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.run(["osf", "ls"], text=True, capture_output=True).stdout + file_list = subprocess.run( + f"osf ls", shell=True, text=True, capture_output=True + ).stdout file_list = io.StringIO(file_list) line = file_list.readline() while line: @@ -109,7 +111,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.run(["osf", "ls"], text=True, capture_output=True).stdout + file_list = subprocess.run( + f"osf ls", shell=True, text=True, capture_output=True + ).stdout file_list = io.StringIO(file_list) line = file_list.readline() while line: