From bf151656077c22153027cf5c31f5f3bfce90382d Mon Sep 17 00:00:00 2001 From: Bongjin Koo Date: Tue, 17 May 2022 10:22:00 -0700 Subject: [PATCH] Issue #74: Testing test_datasets.py, using subprocess.check_output() instead of subprocess.run(). --- ioSPI/datasets.py | 22 +++++++--------------- tests/test_datasets.py | 12 +++--------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/ioSPI/datasets.py b/ioSPI/datasets.py index 9d2a4a6..f4aefcf 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(f"osf ls", shell=True, text=True, capture_output=True) + subprocess.check_output(f"osf ls", shell=True, text=True) def download(self, remote_path: str, local_path: str): """Download a file from an OSF project and save it locally. @@ -82,11 +82,8 @@ 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.run( - f"osf fetch {full_remote_path} {local_path}", - shell=True, - text=True, - capture_output=True, + subprocess.check_output( + f"osf fetch {full_remote_path} {local_path}", shell=True, text=True ) print("Done!") @@ -117,12 +114,9 @@ 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.run( - f"osf upload {local_path} {full_remote_path}", - shell=True, - text=True, - capture_output=True, - ).stdout + f = subprocess.check_output( + f"osf upload {local_path} {full_remote_path}", shell=True, text=True + ) print(io.StringIO(f).readlines()) print("Done!") @@ -144,7 +138,5 @@ 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.run( - f"osf remove {full_remote_path}", shell=True, text=True, capture_output=True - ) + subprocess.check_output(f"osf remove {full_remote_path}", shell=True, text=True) print("Done!") diff --git a/tests/test_datasets.py b/tests/test_datasets.py index 61dfc27..244b406 100644 --- a/tests/test_datasets.py +++ b/tests/test_datasets.py @@ -55,17 +55,13 @@ def test_constructor_invalid_because_no_token(): def test_upload_valid(setup, set_file_path): """Test the upload method.""" - file_list = subprocess.run( - "osf ls", shell=True, text=True, capture_output=True - ).stdout + file_list = subprocess.check_output("osf ls", shell=True, text=True) 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.run( - "osf lss", shell=True, text=True, capture_output=True - ).stdout + file_list = subprocess.check_output("osf ls", shell=True, text=True) file_list = io.StringIO(file_list) line = file_list.readline() while line: @@ -116,9 +112,7 @@ 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", shell=True, text=True, capture_output=True - ).stdout + file_list = subprocess.check_output("osf ls", shell=True, text=True) file_list = io.StringIO(file_list) line = file_list.readline() while line: