mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-03 06:55:09 -04:00
Create temporary file/directory without deleting them after
This commit is contained in:
parent
d5792bd357
commit
19b41cc3b6
1 changed files with 27 additions and 4 deletions
|
@ -10,11 +10,24 @@ from onionshare import common
|
||||||
|
|
||||||
# pytest > 2.9 only needs @pytest.fixture
|
# pytest > 2.9 only needs @pytest.fixture
|
||||||
@pytest.yield_fixture()
|
@pytest.yield_fixture()
|
||||||
def temp_dir_1024_delete():
|
def temp_dir_1024():
|
||||||
|
""" Create a temporary directory that has a single file of a
|
||||||
|
particular size (1024 bytes).
|
||||||
"""
|
"""
|
||||||
Create a temporary directory that has a single file of a particular
|
|
||||||
size (1024 bytes). The temporary directory (and file inside) will
|
tmp_dir = tempfile.mkdtemp()
|
||||||
be deleted after fixture usage.
|
tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir)
|
||||||
|
with open(tmp_file, 'wb') as f:
|
||||||
|
f.write(b'*' * 1024)
|
||||||
|
yield tmp_dir
|
||||||
|
|
||||||
|
|
||||||
|
# pytest > 2.9 only needs @pytest.fixture
|
||||||
|
@pytest.yield_fixture()
|
||||||
|
def temp_dir_1024_delete():
|
||||||
|
""" Create a temporary directory that has a single file of a
|
||||||
|
particular size (1024 bytes). The temporary directory (including
|
||||||
|
the file inside) will be deleted after fixture usage.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
@ -24,6 +37,16 @@ def temp_dir_1024_delete():
|
||||||
yield tmp_dir
|
yield tmp_dir
|
||||||
|
|
||||||
|
|
||||||
|
# pytest > 2.9 only needs @pytest.fixture
|
||||||
|
@pytest.yield_fixture()
|
||||||
|
def temp_file_1024():
|
||||||
|
""" Create a temporary file of a particular size (1024 bytes). """
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
||||||
|
tmp_file.write(b'*' * 1024)
|
||||||
|
yield tmp_file.name
|
||||||
|
|
||||||
|
|
||||||
# pytest > 2.9 only needs @pytest.fixture
|
# pytest > 2.9 only needs @pytest.fixture
|
||||||
@pytest.yield_fixture()
|
@pytest.yield_fixture()
|
||||||
def temp_file_1024_delete():
|
def temp_file_1024_delete():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue