{"id":18326620,"url":"https://github.com/jimfulton/testvars","last_synced_at":"2025-04-09T16:27:50.131Z","repository":{"id":57474560,"uuid":"96546572","full_name":"jimfulton/testvars","owner":"jimfulton","description":"Helper for making assertions on complex data structures with variable parts.","archived":false,"fork":false,"pushed_at":"2017-07-07T14:38:21.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-17T07:09:59.926Z","etag":null,"topics":["python","test-framework","testing","testing-framework"],"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/jimfulton.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-07T14:28:24.000Z","updated_at":"2019-08-01T19:24:32.000Z","dependencies_parsed_at":"2022-09-10T02:21:23.751Z","dependency_job_id":null,"html_url":"https://github.com/jimfulton/testvars","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimfulton%2Ftestvars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimfulton%2Ftestvars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimfulton%2Ftestvars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimfulton%2Ftestvars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimfulton","download_url":"https://codeload.github.com/jimfulton/testvars/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248067084,"owners_count":21042229,"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","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":["python","test-framework","testing","testing-framework"],"created_at":"2024-11-05T19:07:29.366Z","updated_at":"2025-04-09T16:27:50.115Z","avatar_url":"https://github.com/jimfulton.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"===================================================\ntestvars - Place-holders in complex test assertions\n===================================================\n\nSometimes, when writing tests, you want to assert that a data\nstructure computed in a test matches some expected value, but the\nexpected value might have components, such as times or generated ids\nthat can't be predicted ahead of time.  Options in this situation\ninclude:\n\n- break the assertion into many assertions about various parts of the\n  data structure.\n\n- Use mocking/stubbing to control things like time and ids to make\n  unpredictable parts of the data predictable.\n\nBoth of these approaches tend to be pretty tedious and potentially\nerror prone.\n\nThe tiny testvars package provides an alternative that is much easier\nto use in many cases.  The package provides a ``Vars`` class::\n\n  \u003e\u003e\u003e import testvars\n  \u003e\u003e\u003e vars = testvars.Vars()\n\nWhen ``Vars`` attributes are compared equal the first time, the\ncomparison succeeds and alse sets their value:\n\n  \u003e\u003e\u003e vars.x == 1\n  True\n\nAt that point, the value is set, and you can make assertions\nagainst it:\n\n  \u003e\u003e\u003e vars.x\n  1\n  \u003e\u003e\u003e vars.x \u003e 0\n  True\n\nFurther comparisons are against this set value:\n\n  \u003e\u003e\u003e vars.x == 2\n  False\n\nThis is useful when dealing with data structures with unpredictable\nparts:\n\n  \u003e\u003e\u003e expected = {'id': vars.child_id, 'name':\"Alex\"}\n  \u003e\u003e\u003e {'id': 32, 'name':\"Alex\"} == expected\n  True\n\nIt's also interesting when, while you don't know what values will be,\nyou can make assertions about how values are related:\n\n  \u003e\u003e\u003e expected = {'id': vars.parent_id, 'name':'Cas',\n  ...             'children': [vars.child_id]}\n  \u003e\u003e\u003e expected == {'id': 42, 'name':'Cas', 'children':[32]}\n  True\n  \u003e\u003e\u003e expected == {'id': 42, 'name':'Cas', 'children':[33]}\n  False\n\n  \u003e\u003e\u003e [vars.y, 2, 3, vars.y] == [9, 2, 3, 9]\n  True\n\n  \u003e\u003e\u003e [vars.z, 2, 3, vars.z] == [8, 2, 3, 9]\n  False\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimfulton%2Ftestvars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimfulton%2Ftestvars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimfulton%2Ftestvars/lists"}