{"id":32599700,"url":"https://github.com/testflows/testflows-snapshots","last_synced_at":"2026-01-20T17:58:12.992Z","repository":{"id":233562802,"uuid":"707390237","full_name":"testflows/TestFlows-Snapshots","owner":"testflows","description":"TestFlows.com Open-Source Software Testing Framework's module for working with snapshots. ","archived":false,"fork":false,"pushed_at":"2024-12-13T13:56:42.000Z","size":73,"stargazers_count":0,"open_issues_count":2,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-27T05:45:22.448Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/testflows.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-19T19:50:32.000Z","updated_at":"2024-12-13T13:56:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"66c2c2ba-f644-487b-9c53-053efe4502fd","html_url":"https://github.com/testflows/TestFlows-Snapshots","commit_stats":null,"previous_names":["testflows/testflows-snapshots"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/testflows/TestFlows-Snapshots","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testflows%2FTestFlows-Snapshots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testflows%2FTestFlows-Snapshots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testflows%2FTestFlows-Snapshots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testflows%2FTestFlows-Snapshots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/testflows","download_url":"https://codeload.github.com/testflows/TestFlows-Snapshots/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testflows%2FTestFlows-Snapshots/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281761855,"owners_count":26557114,"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-10-30T02:00:06.501Z","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":[],"created_at":"2025-10-30T06:51:10.320Z","updated_at":"2025-10-30T06:51:33.181Z","avatar_url":"https://github.com/testflows.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TestFlows-Snapshots\nTestFlows.com Open-Source Software Testing Framework's module for working with snapshots. \n\n## What are snapshots?\n\nSnapshots are specialized files designed to capture and previously recorded output of the system under test. \nThis allows you to identify any changes in the system's behavior during subsequent test runs (regression testing). The state is saved as key-value pairs in the following format:\n\n```python\nkey_name_of_the_entry = r\"\"\"value that represents the state of the system.\"\"\"\n```\n\n### How snapshots work?\n\nWhen you execute your test program a snapshot file is generated if it doesn't exist. This file captures and stores the values representing the system's state at that moment. During subsequent test executions, the actual values from the system are compared against those stored in the snapshot file.\nIf any discrepancies are found between the stored values and the actual output, an assertion error is raised. This error highlights that the expected output differs from the recorded output of the system, enabling you to detect regressions or unexpected changes effectively.\n\nHere is a example of a snapshot file content:\n\n```python\ngreeting_message = r\"\"\"Hello, world!\"\"\"\nstatus_code = r\"\"\"200\"\"\"\ntimestamp = r\"\"\"2024-12-05 12:34:56\"\"\"\n```\n\n## How to use snapshots in TestFlows?\n\nTo utilize snapshots, you need to import the snapshot function from the `testflows.snapshots` module:\n\n```python\nfrom testflows.snapshots import snapshot\n```\n\nHere’s an example of how to use the snapshot function in a test:\n\n```python\nfrom testflows.asserts import values, error\nfrom testflows.snapshots import snapshot\n\nsystem_output = \"Hello, world!\"\n\nwith values() as that:\n    assert that(\n        snapshot(\n            value=system_output,\n            name=snapshot_name,\n            id=snapshot_id,\n            mode=snapshot.CHECK | snapshot.UPDATE,\n        )\n    ), error()\n```\n\n### Parameters of the snapshot Function\n\n- `value:` The actual value from the system that you want to store in the snapshot.\n- `name`: The key name within the snapshot file.\n- `id:` Defines the name of the snapshot file itself, helping to distinguish between different snapshot files.\n- `mode:` Determines the operation mode of the snapshot function. Modes include:\n  - `CHECK:` Compares the actual value against the expected value stored in the snapshot.\n  - `UPDATE:` Updates the snapshot file with the current values without performing assertions.\n  - `REWRITE:` Rewrites the snapshot file with new values.\n\nThe default mode is `CHECK | UPDATE`, allowing the system to either validate or update the snapshot values automatically.\n\n\u003e [!WARNING]\n\u003e For your first run it is fine to use `snapshot.CHECK | snapshot.UPDATE` mode. After that you need to switch to `snapshot.CHECK` mode to ensure that you don't just overwrite the expected values in the snapshot with the actual values.\n\n### Custom Comparison\n\nThe `testflows.snapshots` module offers the ability to specify custom comparison functions, providing flexibility for handling complex or dynamic use cases. Here are some interesting use cases:\n\n#### Regex Substitution for Snapshot and Actual Value\n\nYou can use regular expression substitution to strip dynamic parts from both the snapshot and the actual value before performing the comparison. This ensures that only the static portions are validated.\n\n```python\nsnapshot(\n    value=f\"hello {time.time()}\",\n    mode=snapshot.CHECK,\n    compare=snapshot.COMPARE.resub(r\"\\d+(\\.\\d+)?\")\n)\n```\n\nIn this case:\n\n- The dynamic numeric portion (e.g., timestamps) is removed from both the snapshot and actual value using `resub`.\n- The remaining static portions are compared for equality.\n\n#### Regex Match for Comparison\n\nInstead of checking for strict equality, you can use regular expression matching to validate both the snapshot and the actual value.\n\n```python\nsnapshot(\n    value=f\"hello {time.time()}\",\n    mode=snapshot.CHECK,\n    compare=snapshot.COMPARE.rematch(r\"hello.*\")\n)\n```\n\nHere a regex pattern (e.g., hello.*) ensures that both values match a specified format or pattern rather than being exactly identical.\n\n\n#### Dynamic Evaluation\n\nYou can dynamically evaluate the actual value at runtime and compare it without strictly relying on the snapshot value. This is useful for scenarios where the snapshot serves as a placeholder but the actual validation is context-sensitive.\n\n```python\nsnapshot(\n    value=f\"{time.time()}\",\n    mode=snapshot.CHECK,\n    compare=lambda a, b: time.time() - 1 \u003c float(b[1:-1]) \u003c time.time() + 1\n)\n```\n\nIn this scenario:\n\n- A lambda function dynamically checks if the actual value is within a specific range (e.g., within ±1 second of the current time).\n- The snapshot value is effectively bypassed for comparison, allowing fully dynamic validation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestflows%2Ftestflows-snapshots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftestflows%2Ftestflows-snapshots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestflows%2Ftestflows-snapshots/lists"}