{"id":34073580,"url":"https://github.com/rainrainwu/derivation","last_synced_at":"2026-05-28T12:32:13.609Z","repository":{"id":65235572,"uuid":"579578282","full_name":"RainrainWu/derivation","owner":"RainrainWu","description":"Derivation is a flexible payload generating framework with highly-customizable patterns and rules which raise your efficiency significantly on test case implementation against complicated inputs.","archived":false,"fork":false,"pushed_at":"2023-02-26T09:21:47.000Z","size":114,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-24T22:36:48.690Z","etag":null,"topics":["fuzzy-testing","python","python3","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RainrainWu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-18T06:35:54.000Z","updated_at":"2023-04-07T12:01:17.000Z","dependencies_parsed_at":"2023-01-15T18:45:40.872Z","dependency_job_id":null,"html_url":"https://github.com/RainrainWu/derivation","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/RainrainWu/derivation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RainrainWu%2Fderivation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RainrainWu%2Fderivation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RainrainWu%2Fderivation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RainrainWu%2Fderivation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RainrainWu","download_url":"https://codeload.github.com/RainrainWu/derivation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RainrainWu%2Fderivation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27724007,"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-12-14T02:00:11.348Z","response_time":56,"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":["fuzzy-testing","python","python3","unit-testing"],"created_at":"2025-12-14T08:58:57.857Z","updated_at":"2025-12-14T08:58:58.918Z","avatar_url":"https://github.com/RainrainWu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Derivation\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/08e384eaba6ad7375e8b/maintainability)](https://codeclimate.com/github/RainrainWu/derivation/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/08e384eaba6ad7375e8b/test_coverage)](https://codeclimate.com/github/RainrainWu/derivation/test_coverage)\n[![codecov](https://codecov.io/gh/RainrainWu/derivation/branch/master/graph/badge.svg?token=at8Ckp5iLi)](https://codecov.io/gh/RainrainWu/derivation)\n[![Github Actions](https://github.com/RainrainWu/derivation/actions/workflows/pull_request.yml/badge.svg)](https://github.com/RainrainWu/derivation/actions/workflows/pull_request.yml)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/derivation.svg)](https://pypi.python.org/pypi/derivation/)\n\nDerivation is a flexible payload generating framework with highly-customizable patterns and rules which raise your efficiency significantly on test case implementation against complicated inputs.\n\n[View Page on Pypi \u003e\u003e](https://pypi.org/project/derivation/)\n\n## Derivative\n\nDerivative is the primary object which helps you sort out all of possible results with the given inputs.\n\n\u003e The script below can be executed directly\n```python\nfrom enum import Enum, auto\nfrom operator import or_\n\nfrom derivation.constraint import MutuallyExclusiveConstraint, OccurrenceConstraint\nfrom derivation.derivative import Derivative\n\n\nclass DerivativeEvent(Enum):\n    @staticmethod\n    def _generate_next_value_(name, start, count, last_values):\n        return name.upper()\n\n\nclass DerivativeEventExample(DerivativeEvent):\n\n    ESSENTIALS = auto()\n\n    OPTIONAL_1 = auto()\n    OPTIONAL_2 = auto()\n\n\nEVENTS_EXAMPLE = {event: {event.value: None} for event in DerivativeEventExample}\n\noccurrence_constraint = OccurrenceConstraint(\n    (DerivativeEventExample.ESSENTIALS,),\n    min_times=1,\n    max_times=1,\n)\nmutually_exclusive_constraint = MutuallyExclusiveConstraint(\n    (\n        DerivativeEventExample.OPTIONAL_1,\n        DerivativeEventExample.OPTIONAL_2,\n    ),\n)\nderivative = Derivative(\n    EVENTS_EXAMPLE,\n    or_,\n    (occurrence_constraint, mutually_exclusive_constraint),\n)\n\nfor order, result in derivative.exhaustive():\n\n    print(f\"{order}\\n{result}\\n\")\n\n```\n\n## Constraint\n\nConstraint helps you construct the rules for specific requirements of deriving recipe.\n\n### Occurrence\n\nOccurrence Constraint make us able to limit the total occurrence times of a specific group of events.\n\n```python\noccurrence_constraint = OccurrenceConstraint(\n    (DerivativeEventExample.ESSENTIALS,),\n    min_times=1,\n    max_times=1,\n)\n\n# pass\noccurrence_constraint.constrain(\n    (DerivativeEventExample.ESSENTIALS, DerivativeEventExample.OPTIONAL_1),\n)\n\n# error\noccurrence_constraint.constrain(\n    (DerivativeEventExample.OPTIONAL_1,),\n)\n```\n\n### Mutually Exclusive\n\nOccurrence Constraint make us able to avoid conflicts of a specific group of events.\n\n```python\nmutually_exclusive_constraint = MutuallyExclusiveConstraint(\n    (\n        DerivativeEventExample.OPTIONAL_1,\n        DerivativeEventExample.OPTIONAL_2,\n    ),\n)\n\n# pass\nmutually_exclusive_constraint.constrain(\n    (DerivativeEventExample.ESSENTIALS, DerivativeEventExample.OPTIONAL_1),\n)\n\n# error\nmutually_exclusive_constraint.constrain(\n    (DerivativeEventExample.OPTIONAL_1, DerivativeEventExample.OPTIONAL_2),\n)\n```\n\n### Prerequisite\n\nPrerequisite Constraint define the ordering and dependencies of valid event series.\n\n```python\nprerequisite_constraint = PrerequisiteConstraint(\n    (DerivativeEventExample.ESSENTIALS,),\n    (DerivativeEventExample.OPTIONAL_1, DerivativeEventExample.OPTIONAL_2),\n)\n\n# pass\nprerequisite_constraint.constrain(\n    (DerivativeEventExample.ESSENTIALS, DerivativeEventExample.OPTIONAL_1),\n)\n\n# error\nprerequisite_constraint.constrain(\n    (DerivativeEventExample.OPTIONAL_2,),\n)\n```\n\n### Termination\n\nTermination constraints focus on the specific group of termination events.\n\n```python\ntermination_constraint = TerminationConstraint(\n    (DerivativeEventExample.OPTIONAL_1, DerivativeEventExample.OPTIONAL_2),\n)\n\n# pass\ntermination_constraint.constrain(\n    (DerivativeEventExample.ESSENTIALS, DerivativeEventExample.OPTIONAL_1),\n)\n\n# error\ntermination_constraint.constrain(\n    (DerivativeEventExample.ESSENTIALS,),\n)\n```\n\n## Federation\n\nFederation objects allow you construct a more complicated structure with multiple derivation instances, as well as a couple of parameters sets and filtering rules.\n\n\n\u003e Append script below to the bottom of the previous example for derivation.\n\n```python\nfrom derivation.federation import Federation\n\n\nclass DerivativePatternExample(DerivativeEvent):\n\n    COMPOSITED = auto()\n\n\nPATTERNS_EXAMPLE = {\n    DerivativePatternExample.COMPOSITED: (\n        lambda slot_1, slot_2, constant, customized: {\n            \"slot_1\": slot_1,\n            \"slot_2\": slot_2,\n            \"constant\": constant,\n            \"customized\": customized,\n        }\n    )\n}\n\n\nclass DerivativeParamsMapExample(DerivativeEvent):\n\n    DEFAULT = auto()\n\n\nPARAMS_MAPS_EXAMPLE = {\n    DerivativeParamsMapExample.DEFAULT: {\"constant\": \"default\"},\n}\n\n\nclass DerivativeFilterExample(DerivativeEvent):\n\n    RICH_SLOT_1 = auto()\n\n\nFILTERS_EXAMPLE = {\n    DerivativeFilterExample.RICH_SLOT_1: lambda x: len(x[\"slot_1\"]) \u003e 1,\n}\n\nfederation = Federation[\n    DerivativePatternExample,\n    DerivativeParamsMapExample,\n    DerivativeFilterExample,\n    dict,\n](\n    {\"slot_1\": derivative, \"slot_2\": derivative},\n    PATTERNS_EXAMPLE,\n    PARAMS_MAPS_EXAMPLE,\n    FILTERS_EXAMPLE,\n)\n\nfor composited_result in federation.exhaustive(\n    DerivativePatternExample.COMPOSITED,\n    (DerivativeParamsMapExample.DEFAULT,),\n    {\"customized\": \"customized\"},\n    (DerivativeFilterExample.RICH_SLOT_1,),\n):\n\n    print(f\"{composited_result}\\n\")\n```\n\n### Derivatives \u0026 Patterns\n\nFederation object allows you pre-register some patterns which describe how should the derivatives combine with each other.\n\nPattern are generally a callable function and introduce candidates of the derivatives or apply fixed value as the parameters, we encourage users define readable variable name for better collaboration.\n\n```python\nPATTERNS_EXAMPLE = {\n    DerivativePatternExample.COMPOSITED: (\n\n        # Callable object as pre-defined pattern.\n        lambda slot_1, slot_2, constant, customized: {\n            \"slot_1\": slot_1,\n            \"slot_2\": slot_2,\n            \"constant\": constant,\n            \"customized\": customized,\n        }\n    )\n}\n```\n\n### Parameters Maps\n\nFor the parameters do not require exhausting via a derivative object, parameters maps can be attached as the fixed values.\n\n```python\nPARAMS_MAPS_EXAMPLE = {\n\n    # Apply fixed string object \"default\" to `constant` parameter inside patterns\n    DerivativeParamsMapExample.DEFAULT: {\"constant\": \"default\"},\n}\n```\n\n### Filters\n\nIn order to re-use federation object in many similar scenarios, pre-register filters provide a more flexible approach for fetching candidates with specific features.\n\n```python\nFILTERS_EXAMPLE = {\n\n    # Only allow results which contain more than one item in slot_1.\n    DerivativeFilterExample.RICH_SLOT_1: lambda x: len(x[\"slot_1\"]) \u003e 1,\n}\n```\n\n### Customized Parameters\n\nTemporary parameters right inside each exhaustive iterator are also supported, which can help you achieve much more flexible design against edge cases.\n\n```python\nfor composited_result in federation.exhaustive(\n    DerivativePatternExample.COMPOSITED,\n    (DerivativeParamsMapExample.DEFAULT,),\n\n    # Temporary parameters only take effects within this iterator.\n    {\"customized\": \"customized\"},\n    (DerivativeFilterExample.RICH_SLOT_1,),\n):\n\n    print(f\"{composited_result}\\n\")\n```\n\n## Contribution\n\n- [RainrainWu](https://github.com/RainrainWu)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frainrainwu%2Fderivation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frainrainwu%2Fderivation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frainrainwu%2Fderivation/lists"}