Reference
Submodules
jycm.common module
jycm.helper module
jycm.jycm module
- exception jycm.jycm.DiffLevelException[source]
Bases:
ExceptionThe exception that will be threw from _diff function.
- exception jycm.jycm.DifferentTypeException[source]
Bases:
ExceptionThe exception that will be threw when left and right are of different types
This maybe improved as a feature.
- class jycm.jycm.ListItemPair(value: TreeLevel, left_index, right_index)[source]
Bases:
objectPair of array items
- class jycm.jycm.Record(event: str, level: TreeLevel, info: Dict)[source]
Bases:
objectTo record the info made from operators and differ.
- Parameters
event – a unique string to describe the info
level – where the info and event are described for
info – the additional info attached to the event
- class jycm.jycm.TreeLevel(left, right, left_path: List, right_path: List, up: Optional[TreeLevel], diff: Optional[Callable[[TreeLevel, bool], Tuple[bool, float]]] = None)[source]
Bases:
objectThe base data structure for diffing.
- Parameters
left – left value
right – right value
left_path – left json path
right_path – right json path
up – the parent TreeLevel
diff – a simple way to inject custom operators ; default None
- get_path()[source]
Get the path of this level
- Returns
The left path of this level (matching will be concerned on left mainly)
- class jycm.jycm.YouchamaJsonDiffer(left, right, custom_operators: Optional[List[BaseOperator]] = None, ignore_order_func: Optional[Callable[[TreeLevel, bool], bool]] = None, debug=False, fast_mode=False, use_cache=True)[source]
Bases:
object- Parameters
left – a dict value.
right – a dict value.
custom_operators – List of operators extend from BaseOperator.
ignore_order_func – the func that decides whether the current array should be ignored order or not. (level: TreeLevel, drill: boolean) => bool
debug – set True then some debug info will be collected. default False.
fast_mode – whether or not using LCS. default True
- compare_dict(level: TreeLevel, drill=False) float[source]
Compare Dict
- Parameters
level – the tree level to be diffed
drill – whether this diff is in drill mode.
- Returns
A score between 0~1 to describe how similar level.left and level.right are. The score will be average score for all scores for all keys.
- compare_list_with_order(level: TreeLevel, drill=False) float[source]
Compare two arrays with order
- Parameters
level – the tree level to be diffed
drill – whether this diff is in drill mode.
- Returns
A score between 0~1 to describe how similar level.left and level.right are
- compare_primitive(level: TreeLevel, drill=False) float[source]
Compare primitive values
- Parameters
level – the tree level to be diffed
drill – whether this diff is in drill mode.
- Returns
A score between 0~1 to describe how similar level.left and level.right are.
- diff_level(level: TreeLevel, drill: bool) float[source]
Diff level function It is a wrapper of _diff_level with cache mechanism.
- Parameters
level – the tree level to be diffed
drill – whether this diff is in drill mode.
- Returns
A score between 0~1 to describe how similar level.left and level.right are.
- generate_lcs_pair_list(level: TreeLevel) List[ListItemPair][source]
Generate all ListItemPair
Use LCS algorithm to match arrays with taking order into consideration
- Parameters
level – a tree level
- Returns
List of pairs
- get_diff(no_pairs=False)[source]
Do the diff and return the json diff
Normally to_dict is enough to collect all the info.
- Parameters
no_pairs – boolean to decide whether to report pairs of json path
- Returns
a dict
- report(event: str, level: TreeLevel, info: Optional[Dict] = None)[source]
Report any useful info
- Parameters
event – a unique string to describe the info
level – where the info and event are described for
info – the additional info attached to the event
- report_pair(level: TreeLevel)[source]
Report pair of json path
In order to save space, only the level whose left and right path are different will be reported
- Parameters
level – TreeLevel
- to_dict(no_pairs=False) dict[source]
Convert this to a dict
Normally to_dict is enough to collect all the info.
- Parameters
no_pairs – boolean to decide whether to report pairs of json path
- Returns
a dict
- use_custom_operators(level: TreeLevel, drill=False) Tuple[bool, float][source]
Compare with custom operators
- Parameters
level – the tree level to be diffed
drill – whether this diff is in drill mode.
- Returns
A boolean to determine whether diff should be early stopped. A score between 0~1 to describe how similar level.left and level.right are.
jycm.km_matcher module
jycm.operator module
- class jycm.operator.ExpectChangeOperator(path_regex: str)[source]
Bases:
BaseOperator- diff(level: TreeLevel, instance: YouchamaJsonDiffer, drill: bool) Tuple[bool, float][source]
- class jycm.operator.ExpectExistOperator(path_regex: str)[source]
Bases:
BaseOperator- diff(level: TreeLevel, instance: YouchamaJsonDiffer, drill: bool) Tuple[bool, float][source]
- class jycm.operator.FloatInRangeOperator(path_regex, interval_start, interval_end)[source]
Bases:
BaseOperator- diff(level: TreeLevel, instance: YouchamaJsonDiffer, drill: bool) Tuple[bool, float][source]
- class jycm.operator.IgnoreOperator(path_regex: str, *args, **kwargs)[source]
Bases:
BaseOperator- diff(level: TreeLevel, instance: YouchamaJsonDiffer, drill: bool) Tuple[bool, float][source]
- class jycm.operator.ListItemFieldMatchOperator(path_regex, field)[source]
Bases:
BaseOperator- diff(level: TreeLevel, instance: YouchamaJsonDiffer, drill: bool) Tuple[bool, float][source]
- jycm.operator.register_operator(operator_class: Type[BaseOperator])[source]
Module contents
jycm codes. .