{"id":22746234,"url":"https://github.com/yukihiko-shinoda/fixture-file-handler","last_synced_at":"2025-09-04T18:51:06.696Z","repository":{"id":57429899,"uuid":"196045974","full_name":"yukihiko-shinoda/fixture-file-handler","owner":"yukihiko-shinoda","description":"This project helps you to vacate specific file path or deploy resource file into specific file path when unit testing.","archived":false,"fork":false,"pushed_at":"2020-08-17T06:18:12.000Z","size":94,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T05:23:13.050Z","etag":null,"topics":["fixture","framework","pytest","python","unittest"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yukihiko-shinoda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-09T16:30:46.000Z","updated_at":"2020-08-17T06:17:46.000Z","dependencies_parsed_at":"2022-08-26T02:41:12.931Z","dependency_job_id":null,"html_url":"https://github.com/yukihiko-shinoda/fixture-file-handler","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/yukihiko-shinoda/fixture-file-handler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihiko-shinoda%2Ffixture-file-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihiko-shinoda%2Ffixture-file-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihiko-shinoda%2Ffixture-file-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihiko-shinoda%2Ffixture-file-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yukihiko-shinoda","download_url":"https://codeload.github.com/yukihiko-shinoda/fixture-file-handler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihiko-shinoda%2Ffixture-file-handler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273656987,"owners_count":25145003,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fixture","framework","pytest","python","unittest"],"created_at":"2024-12-11T02:12:28.817Z","updated_at":"2025-09-04T18:51:06.672Z","avatar_url":"https://github.com/yukihiko-shinoda.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fixture File Handler\n\n[![Test](https://github.com/yukihiko-shinoda/fixture-file-handler/workflows/Test/badge.svg)](https://github.com/yukihiko-shinoda/fixture-file-handler/actions?query=workflow%3ATest)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/063cfb039d7d9a2ff69d/test_coverage)](https://codeclimate.com/github/yukihiko-shinoda/fixture-file-handler/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/063cfb039d7d9a2ff69d/maintainability)](https://codeclimate.com/github/yukihiko-shinoda/fixture-file-handler/maintainability)\n[![Code Climate technical debt](https://img.shields.io/codeclimate/tech-debt/yukihiko-shinoda/fixture-file-handler)](https://codeclimate.com/github/yukihiko-shinoda/fixture-file-handler)\n[![Updates](https://pyup.io/repos/github/yukihiko-shinoda/fixture-file-handler/shield.svg)](https://pyup.io/repos/github/yukihiko-shinoda/fixture-file-handler/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fixturefilehandler)](https://pypi.org/project/fixturefilehandler/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/fixturefilehandler)](https://pypi.org/project/fixturefilehandler/)\n[![Twitter URL](https://img.shields.io/twitter/url?style=social\u0026url=https%3A%2F%2Fgithub.com%2Fyukihiko-shinoda%2Ffixture-file-handler)](http://twitter.com/share?text=Fixture%20File%20Handler\u0026url=https://pypi.org/project/fixturefilehandler/\u0026hashtags=python)\n\nThis project helps you to vacate specific file path or deploy resource file into specific file path when unit testing.\n\n## Context\n\nThe most popular setup / teardown tasks about file system on unit testing is\nalmost 2 kinds.\n\n1. vacate specific file path for testing file export function\n2. deploy fixture file / directory into specific file path for testing file import /export function\n\nThen we have to think about how to back up existing file / directory between unit testing\nbecause maybe developer wants to keep those handwritten files for development.\n\n`Fixture File Handler` is framework to realize simply implement\nthe vacate and deploy actions while keeping the existing files.\nOf course, even if there is no file in the target path, it works fine.\n\n## Ubiquitous Language\n\n### target\n\nThe target file path to vacate or deploy file / directory for unit testing.\n\n### backup\n\nThe file path to back up existing file / directory on target file path between unit testing.\n\n### resource\n\nThe file / directory you want to deploy and let product code read / write in unit testing.\nIt may test resource file or template file like `*.dist` file.\n\n## Basic behavior\n\n### Vacator\n\ntarget path|backup path\n---|---\nexisting file /dir|\u0026nbsp;\n\n↓ setup\n\ntarget path|backup path\n---|---\n\u0026nbsp;|existing file / dir\n\n↓ teardown\n\ntarget path|backup path\n---|---\nexisting file / dir|\u0026nbsp;\n\n### Deployer\n\ntarget path|backup path|resource path\n---|---|---\nexisting file / dir|\u0026nbsp;|resource file / dir\n\n↓ setup\n\ntarget path|backup path|resource path\n---|---|---\nresource file / dir|existing file /dir|resource file / dir\n\n↓ teardown\n\ntarget path|backup path|resource path\n---|---|---\nexisting file / dir|\u0026nbsp;|resource file / dir\n\n### Common behavior\n\nIf file / directory already exists on backup path,\nsetup raise `BackupAlreadyExistError`\nbecause it's unexpected situation and developer may want to resque those backup files.\n\n## Quickstart\n\n### 1. Install\n\n```console\npip install fixturefilehandler\n```\n\n### 2-1. Case when unittest: implement setUp() and doCleanups()\n\n```python\nfrom pathlib import Path\nimport unittest\n\nfrom fixturefilehandler.factories import VacatorFactory\nfrom fixturefilehandler.file_paths import RelativeVacateFilePath\n\nVACATOR = VacatorFactory.create(\n    RelativeVacateFilePath(\n        Path('test.txt'),\n        Path('test.txt.bak'),\n        Path(__file__).parent\n    )\n)\n\n\nclass ConfigurableTestCase(unittest.TestCase):\n    def setUp(self):\n        VACATOR.setup()\n\n    def doCleanups(self):\n        VACATOR.teardown()\n```\n\n### 2-2. Case when pytest: implement fixture\n\n```python\nfrom pathlib import Path\nimport pytest\n\nfrom fixturefilehandler.factories import DeployerFactory\nfrom fixturefilehandler.file_paths import RelativeDeployFilePath\n\nDEPLOYER = DeployerFactory.create(\n    RelativeDeployFilePath(\n        Path('test.txt'),\n        Path('test.txt.bak'),\n        Path('testresources/test.txt.dist'),\n        Path(__file__).parent\n    )\n)\n\n\n@pytest.fixture\ndef fixture_file():\n    DEPLOYER.setup()\n    yield DEPLOYER.FILE_PATH\n    DEPLOYER.teardown()\n\n\ndef test_something(fixture_file):\n    \"\"\"test something\"\"\"\n```\n\n## API\n\n### file_paths\n\n#### SimpleVacateFilePath\n\nThis instance holds path to target and backup.\nEach path is independent each other.\n\n#### SimpleDeployFilePath\n\nThis instance holds path to target, backup, and resource.\nEach path is independent each other.\n\n#### RelativeVacateFilePath\n\nThis instance holds path to target, backup, and base.\nEach path is relative based on base path.\n\n#### RelativeDeployFilePath\n\nThis instance holds path to target, backup, resource, and base.\nEach path is relative based on base path.\n\n\u003c!-- markdownlint-disable no-trailing-punctuation --\u003e\n## How do I...\n\u003c!-- markdownlint-enable no-trailing-punctuation --\u003e\n\n\u003c!-- markdownlint-disable no-trailing-punctuation --\u003e\n### Use different paths for each test?\n\u003c!-- markdownlint-enable no-trailing-punctuation --\u003e\n\n`setup()` and `teardown()` also accept file_paths argument.\n\nCase when unittest:\n\n```python\nfrom pathlib import Path\n\nimport unittest\n\nfrom fixturefilehandler import ResourceFileDeployer\nfrom fixturefilehandler.file_paths import RelativeDeployFilePath\n\n\nclass AdvancedConfigurableTestCase(unittest.TestCase):\n    @property\n    def file_path(self) -\u003e RelativeDeployFilePath:\n        return RelativeDeployFilePath(\n            Path('test.txt'),\n            Path('test.txt.bak'),\n            Path(f'testresources/{self._testMethodName}.txt'),\n            Path(__file__).parent\n        )\n\n    def setUp(self):\n        ResourceFileDeployer.setup(self.file_path)\n\n    def doCleanups(self):\n        ResourceFileDeployer.teardown(self.file_path)\n```\n\nCase when pytest:\n\n```python\nfrom pathlib import Path\n\nimport pytest\n\nfrom fixturefilehandler import ResourceFileDeployer\nfrom fixturefilehandler.file_paths import RelativeDeployFilePath\n\n\n@pytest.fixture\ndef fixture_file_advanced(request):\n    file_path = RelativeDeployFilePath(\n        Path('test.txt'),\n        Path('test.txt.bak'),\n        Path(f'testresources/{request.node.name}.txt'),\n        Path(__file__).parent\n    )\n\n    ResourceFileDeployer.setup(file_path)\n    yield file_path\n    ResourceFileDeployer.teardown(file_path)\n\n\ndef test_something(fixture_file_advanced):\n    \"\"\"test something\"\"\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyukihiko-shinoda%2Ffixture-file-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyukihiko-shinoda%2Ffixture-file-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyukihiko-shinoda%2Ffixture-file-handler/lists"}