Package: derivation
DerivationDerivation is a flexible payload generating framework with highly-customizable patterns and rules which raise your efficiency significantly on test case implementation against complicated inputs.View Page on Pypi >>DerivativeDerivative is the primary object which helps you sort out all of possible results with the given inputs.The script below can be executed directlyfromenumimportEnum,autofromoperatorimportor_fromderivation.constraintimportMutuallyExclusiveConstraint,OccurrenceConstraintfromderivation.derivativeimportDerivativeclassDerivativeEvent(Enum):@staticmethoddef_generate_next_value_(name,start,count,last_values):returnname.upper()classDerivativeEventExample(DerivativeEvent):ESSENTIALS=auto()OPTIONAL_1=auto()OPTIONAL_2=auto()EVENTS_EXAMPLE={event:{event.value:None}foreventinDerivativeEventExample}occurrence_constraint=OccurrenceConstraint((DerivativeEventExample.ESSENTIALS,),min_times=1,max_times=1,)mutually_exclusive_constraint=MutuallyExclusiveConstraint((DerivativeEventExample.OPTIONAL_1,DerivativeEventExample.OPTIONAL_2,),)derivative=Derivative(EVENTS_EXAMPLE,or_,(occurrence_constraint,mutually_exclusive_constraint),)fororder,resultinderivative.exhaustive():print(f"{order}\n{result}\n")ConstraintConstraint helps you construct the rules for specific requirements of deriving recipe.OccurrenceOccurrence Constraint make us able to limit the total occurrence times of a specific group of events.occurrence_constraint=OccurrenceConstraint((DerivativeEventExample.ESSENTIALS,),min_times=1,max_times=1,)# passoccurrence_constraint.constrain((DerivativeEventExample.ESSENTIALS,DerivativeEventExample.OPTIONAL_1),)# erroroccurrence_constraint.constrain((DerivativeEventExample.OPTIONAL_1,),)Mutually ExclusiveOccurrence Constraint make us able to avoid conflicts of a specific group of events.mutually_exclusive_constraint=MutuallyExclusiveConstraint((DerivativeEventExample.OPTIONAL_1,DerivativeEventExample.OPTIONAL_2,),)# passmutually_exclusive_constraint.constrain((DerivativeEventExample.ESSENTIALS,DerivativeEventExample.OPTIONAL_1),)# errormutually_exclusive_constraint.constrain((DerivativeEventExample.OPTIONAL_1,DerivativeEventExample.OPTIONAL_2),)PrerequisitePrerequisite Constraint define the ordering and dependencies of valid event series.prerequisite_constraint=PrerequisiteConstraint((DerivativeEventExample.ESSENTIALS,),(DerivativeEventExample.OPTIONAL_1,DerivativeEventExample.OPTIONAL_2),)# passprerequisite_constraint.constrain((DerivativeEventExample.ESSENTIALS,DerivativeEventExample.OPTIONAL_1),)# errorprerequisite_constraint.constrain((DerivativeEventExample.OPTIONAL_2,),)TerminationTermination constraints focus on the specific group of termination events.termination_constraint=TerminationConstraint((DerivativeEventExample.OPTIONAL_1,DerivativeEventExample.OPTIONAL_2),)# passtermination_constraint.constrain((DerivativeEventExample.ESSENTIALS,DerivativeEventExample.OPTIONAL_1),)# errortermination_constraint.constrain((DerivativeEventExample.ESSENTIALS,),)FederationFederation objects allow you construct a more complicated structure with multiple derivation instances, as well as a couple of parameters sets and filtering rules.Append script below to the bottom of the previous example for derivation.fromderivation.federationimportFederationclassDerivativePatternExample(DerivativeEvent):COMPOSITED=auto()PATTERNS_EXAMPLE={DerivativePatternExample.COMPOSITED:(lambdaslot_1,slot_2,constant,customized:{"slot_1":slot_1,"slot_2":slot_2,"constant":constant,"customized":customized,})}classDerivativeParamsMapExample(DerivativeEvent):DEFAULT=auto()PARAMS_MAPS_EXAMPLE={DerivativeParamsMapExample.DEFAULT:{"constant":"default"},}classDerivativeFilterExample(DerivativeEvent):RICH_SLOT_1=auto()FILTERS_EXAMPLE={DerivativeFilterExample.RICH_SLOT_1:lambdax:len(x["slot_1"])>1,}federation=Federation[DerivativePatternExample,DerivativeParamsMapExample,DerivativeFilterExample,dict,]({"slot_1":derivative,"slot_2":derivative},PATTERNS_EXAMPLE,PARAMS_MAPS_EXAMPLE,FILTERS_EXAMPLE,)forcomposited_resultinfederation.exhaustive(DerivativePatternExample.COMPOSITED,(DerivativeParamsMapExample.DEFAULT,),{"customized":"customized"},(DerivativeFilterExample.RICH_SLOT_1,),):print(f"{composited_result}\n")Derivatives & PatternsFederation object allows you pre-register some patterns which describe how should the derivatives combine with each other.Pattern 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.PATTERNS_EXAMPLE={DerivativePatternExample.COMPOSITED:(# Callable object as pre-defined pattern.lambdaslot_1,slot_2,constant,customized:{"slot_1":slot_1,"slot_2":slot_2,"constant":constant,"customized":customized,})}Parameters MapsFor the parameters do not require exhausting via a derivative object, parameters maps can be attached as the fixed values.PARAMS_MAPS_EXAMPLE={# Apply fixed string object "default" to `constant` parameter inside patternsDerivativeParamsMapExample.DEFAULT:{"constant":"default"},}FiltersIn order to re-use federation object in many similar scenarios, pre-register filters provide a more flexible approach for fetching candidates with specific features.FILTERS_EXAMPLE={# Only allow results which contain more than one item in slot_1.DerivativeFilterExample.RICH_SLOT_1:lambdax:len(x["slot_1"])>1,}Customized ParametersTemporary parameters right inside each exhaustive iterator are also supported, which can help you achieve much more flexible design against edge cases.forcomposited_resultinfederation.exhaustive(DerivativePatternExample.COMPOSITED,(DerivativeParamsMapExample.DEFAULT,),# Temporary parameters only take effects within this iterator.{"customized":"customized"},(DerivativeFilterExample.RICH_SLOT_1,),):print(f"{composited_result}\n")ContributionRainrainWu