Reference

Submodules

jycm.common module

jycm.helper module

jycm.helper.dump_html_output(left, right, diff_result, output, left_title='Left', right_title='Right')[source]
jycm.helper.make_ignore_order_func(ignore_order_path_regex_list)[source]
jycm.helper.make_json_path_key(path_list: List[str])[source]
jycm.helper.open_url(index_url)[source]
jycm.helper.render_to_html(left, right, diff_result, main_script_path='./index.js', left_title='Left', right_title='Right')[source]

jycm.jycm module

exception jycm.jycm.DiffLevelException[source]

Bases: Exception

The exception that will be threw from _diff function.

exception jycm.jycm.DifferentTypeException[source]

Bases: Exception

The 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: object

Pair of array items

class jycm.jycm.Record(event: str, level: TreeLevel, info: Dict)[source]

Bases: object

To 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

to_dict()[source]

Convert to dict

Returns

A dict

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: object

The 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_key()[source]

Get the key of this level

Returns

The unique key for this level

get_path()[source]

Get the path of this level

Returns

The left path of this level (matching will be concerned on left mainly)

get_type() type[source]

Get the type of this level

Returns

Return the type of this level. If left and right are of different type, then a exception will be threw.

to_dict()[source]

Convert TreeLevel to dict

Returns

A dict contains all info about this level.

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(level: TreeLevel, drill=False) float[source]
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_list_without_order(level: TreeLevel, drill=False) float[source]
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()[source]

Entry function to be called to diff

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.jycm.gather_serial_pair(target_index, indices, list_, container)[source]

Match parts between LCS index

Parameters
  • target_index – LCS index that being collected before

  • indices – all candidates index

  • list – list of values

  • container – reference of collector

Returns:

jycm.km_matcher module

class jycm.km_matcher.KMMatcher(weights)[source]

Bases: object

add_to_tree(x, prevx)[source]
do_augment(x, y)[source]
find_augment_path()[source]
solve(verbose=False)[source]
update_labels()[source]

jycm.operator module

class jycm.operator.BaseOperator(path_regex: str)[source]

Bases: object

diff(level: TreeLevel, instance, drill: bool) Tuple[bool, float][source]
match(level: TreeLevel) bool[source]
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.get_operator(name: str)[source]
jycm.operator.register_operator(operator_class: Type[BaseOperator])[source]

Module contents

jycm codes. .