Skip to main content

Multiple temporary files in 1 line of code

Project description

tempf - TempFiles

GitHub code size in bytes GitHub PyPI - Version PyPI - Downloads

Multiple temporary files in 1 line of code.

TempFiles(X) returns a tuple of X non-used paths.

from tempf import TempFiles

with TempFiles(3) as (path1, path2, path3):
    with path1.open('w') as file1:
        file1.write('See how easy it is?')

Install

>>> pip install tempf

Example

Compilation process:

from pathlib import Path
from tempf import TempFiles


def compile_run_and_check_output(code_path: Path, expected_output: str) -> bool:
    """
    Compile the code, run it, and assert the output is as expected.
    :param code_path: The path to the code to compile.
    :param expected_output: The expected output from running the code.
    :returns: True if compilation and run went successful, and the run outputted the expected output. 
    """
    with TempFiles(4) as (compile_log_path, run_log_path, executable_path, run_output_path):
        compile_file(code_path, log=compile_log_path, compiled=executable_path)
        if not is_compile_log_ok(compile_log_path):
            return False

        run_compiled(executable_path, log=run_log_path, run_output=run_output_path)
        if not is_run_log_ok(run_log_path):
            return False

        with run_output_path.open('r') as output_file:
            return expected_output == output_file.read()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tempf-1.0.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

tempf-1.0.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file tempf-1.0.0.tar.gz.

File metadata

  • Download URL: tempf-1.0.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1016-azure

File hashes

Hashes for tempf-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f3c0bc67b20ab1f5acdb9c4d0d95c82af7475fecebd8dc68a64f0e05bd9fe653
MD5 aad2a8be33a6d63da1495f1b2aa077db
BLAKE2b-256 2936c7932bef0fa4aaea7426e2257b8a2bcbd8b6e5faef20dc0a1a3b5a77f072

See more details on using hashes here.

File details

Details for the file tempf-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tempf-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1016-azure

File hashes

Hashes for tempf-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2689134f8c87d051ea37883a1805784ea56372947ffca772d70a4811065cdfbf
MD5 5a7eb5157c4b86ae83bc92a8e4dc83b0
BLAKE2b-256 5f6611df3b2d6d57fdebcb1c2ffbba1455f3b6e5403e3e34e77567c7d299e3e4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page