🗂 Easily create temporary folders, add files into them and don't worry about deleting them, tempfolder will take care
Project description
tempfolder
🗂 Easily create temporary folders, add files into them and don't worry about deleting them, tempfolder will take care
Installation
tempfolder is published on PyPI and can be installed from there:
pip install tempfolder
Usage
Let's see a case in which we want to test a function that creates a file inside a folder
from pathlib import Path
from tempfolder import use_temp_folder
# A function that create a file inside a folder
def add_config_file_to_folder(folder: str):
with open(Path(folder) / 'config.cfg', 'w') as f:
f.write('i-like: tempfolder')
# Name of the temporary folder
TEMP_FOLDER = Path('temp_folder')
# Test the function
@use_temp_folder(TEMP_FOLDER)
def test_add_config_file_to_folder():
add_config_file_to_folder(TEMP_FOLDER)
assert TEMP_FOLDER.exists()
# Check that the temporary folder was deleted
assert not TEMP_FOLDER.exists()
Run with pytest:
========= 1 passed in 0.05s =========
If we remove the decorator from the previous code and run the test, we get:
from pathlib import Path
# A function that create a file inside a folder
def add_config_file_to_folder(folder: str):
with open(Path(folder) / 'config.cfg', 'w') as f:
f.write('i-like: tempfolder')
# Name of the temporary folder
TEMP_FOLDER = Path('temp_folder')
# Test the function, now with no decorator
def test_add_config_file_to_folder():
add_config_file_to_folder(TEMP_FOLDER)
assert TEMP_FOLDER.exists()
Test:
> with open(Path(folder) / 'config.cfg', 'w') as f:
E FileNotFoundError: [Errno 2] No such file or directory: 'temp_folder/config.cfg'
As you can see the folder wasn't even created, because tempfolder is the one who takes care of the creation and deletion of your temporary folders (and its files).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tempfolder-0.3.1.tar.gz
.
File metadata
- Download URL: tempfolder-0.3.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.7 CPython/3.8.0 Darwin/20.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3aa32f7be1abd38fe67fb90859f40c902da601f2e18661905721f8f9396ae345 |
|
MD5 | 84f3c1bdbdf5e6f2bd351765f80199d5 |
|
BLAKE2b-256 | 1dd1a51dcb2d3b1e635aba7991dd4ffdabc71f48ec13ef0cd1d4276c5e24f660 |
File details
Details for the file tempfolder-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: tempfolder-0.3.1-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.7 CPython/3.8.0 Darwin/20.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2282c1dd4f0fdeac3836d1c84235004b7bdaa09fbe82b9e18aadc9a9024bce46 |
|
MD5 | b46e9d59505cb44f1e8de89c1a7ec167 |
|
BLAKE2b-256 | eb1c928c07f988666a506446c158b1dc2d3d468775269411918970f963c0cbf2 |