diff options
author | Micah Lee <micah@micahflee.com> | 2022-01-16 15:49:33 -0800 |
---|---|---|
committer | Micah Lee <micah@micahflee.com> | 2022-01-16 15:49:33 -0800 |
commit | 9e99ad8b8d6f0eb0a2162191ec31a68e7c3acee5 (patch) | |
tree | 5a5215260866bd07adc60ead1ae0d1b6cd93174b /cli/tests/conftest.py | |
parent | 74711e7d7c7b825fc580c612530569195156794a (diff) | |
parent | b4e022149d677f9c2acd639e9dfa77bcc712b068 (diff) | |
download | onionshare-9e99ad8b8d6f0eb0a2162191ec31a68e7c3acee5.tar.gz onionshare-9e99ad8b8d6f0eb0a2162191ec31a68e7c3acee5.zip |
Merge branch 'develop' of github.com:onionshare/onionshare into ros-fixes
Diffstat (limited to 'cli/tests/conftest.py')
-rw-r--r-- | cli/tests/conftest.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/cli/tests/conftest.py b/cli/tests/conftest.py index 37b929ec..f4d51f9d 100644 --- a/cli/tests/conftest.py +++ b/cli/tests/conftest.py @@ -37,7 +37,7 @@ def temp_dir(): """Creates a persistent temporary directory for the CLI tests to use""" global test_temp_dir if not test_temp_dir: - test_temp_dir = tempfile.mkdtemp() + test_temp_dir = tempfile.TemporaryDirectory() return test_temp_dir @@ -47,10 +47,9 @@ def temp_dir_1024(temp_dir): particular size (1024 bytes). """ - new_temp_dir = tempfile.mkdtemp(dir=temp_dir) - tmp_file, tmp_file_path = tempfile.mkstemp(dir=new_temp_dir) - with open(tmp_file, "wb") as f: - f.write(b"*" * 1024) + new_temp_dir = tempfile.TemporaryDirectory(dir=temp_dir.name) + tmp_file = tempfile.NamedTemporaryFile(dir=new_temp_dir.name) + tmp_file.write(b"*" * 1024) return new_temp_dir @@ -61,9 +60,8 @@ def temp_dir_1024_delete(temp_dir): the file inside) will be deleted after fixture usage. """ - with tempfile.TemporaryDirectory(dir=temp_dir) as new_temp_dir: - tmp_file, tmp_file_path = tempfile.mkstemp(dir=new_temp_dir) - with open(tmp_file, "wb") as f: + with tempfile.TemporaryDirectory(dir=temp_dir.name) as new_temp_dir: + with open(os.path.join(new_temp_dir, "file"), "wb") as f: f.write(b"*" * 1024) yield new_temp_dir @@ -72,9 +70,10 @@ def temp_dir_1024_delete(temp_dir): def temp_file_1024(temp_dir): """Create a temporary file of a particular size (1024 bytes).""" - with tempfile.NamedTemporaryFile(delete=False, dir=temp_dir) as tmp_file: - tmp_file.write(b"*" * 1024) - return tmp_file.name + filename = os.path.join(temp_dir.name, "file") + with open(filename, "wb") as f: + f.write(b"*" * 1024) + return filename @pytest.fixture @@ -84,11 +83,11 @@ def temp_file_1024_delete(temp_dir): The temporary file will be deleted after fixture usage. """ - with tempfile.NamedTemporaryFile(dir=temp_dir, delete=False) as tmp_file: + with tempfile.NamedTemporaryFile(dir=temp_dir.name, delete=False) as tmp_file: tmp_file.write(b"*" * 1024) tmp_file.flush() tmp_file.close() - yield tmp_file.name + yield tmp_file @pytest.fixture(scope="session") |