%global _empty_manifest_terminate_build 0 Name: python-jsoncomparison Version: 1.1.0 Release: 1 Summary: json compare utility License: MIT URL: https://pypi.org/project/jsoncomparison Source0: https://mirrors.nju.edu.cn/pypi/web/packages/eb/39/64adc3dabf4905c081c1127f94efbe6ff6f227fe095aec36751131043244/jsoncomparison-1.1.0.tar.gz BuildArch: noarch %description ## The JSON Comparison package [![Build Status](https://travis-ci.com/rugleb/JsonCompare.svg?branch=master)](https://travis-ci.com/rugleb/JsonCompare) [![codecov](https://codecov.io/gh/rugleb/JsonCompare/branch/master/graph/badge.svg)](https://codecov.io/gh/rugleb/JsonCompare) [![Python 3.6+](https://img.shields.io/badge/python-3.6+-green.svg)](https://www.python.org/downloads/release/python-360/) [![PyPI version](https://badge.fury.io/py/jsoncomparison.svg)](https://badge.fury.io/py/jsoncomparison) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) This package is designed to compare two objects with a JSON-like structure and data types. ### Install ``` pip install -U pip jsoncomparison ``` ### Usage First you need to define two variables: `expected` & `actual`. Think of them as the same variables that you use in tests. Expected - the original data object that you want to see. Actual - the given data object. Then we will transfer these objects to check and identify the difference between them: ```python from jsoncomparison import Compare, NO_DIFF expected = { "project": { "name": "jsoncomparison", "version": "0.1", "license": "MIT", "language": { "name": "python", "versions": [ 3.5, 3.6 ] } }, "os": "linux" } actual = { "project": { "name": "jsoncomparison", "version": 0.1, "license": "Apache 2.0", "language": { "name": "python", "versions": [ 3.6 ] } } } diff = Compare().check(expected, actual) assert diff != NO_DIFF ``` The `check` method returns a dictionary of differences between `expected` and `actual` objects: ```json { "project": { "version": { "_message": "Types not equal. Expected: , received: ", "_expected": "str", "_received": "float" }, "license": { "_message": "Values not equal. Expected: , received: ", "_expected": "MIT", "_received": "Apache 2.0" }, "language": { "versions": { "_length": { "_message": "Lengths not equal. Expected <2>, received: <1>", "_expected": 2, "_received": 1 }, "_content": { "0": { "_message": "Value not found. Expected <3.5>", "_expected": 3.5, "_received": null } } } } }, "os": { "_message": "Key does not exists. Expected: ", "_expected": "os", "_received": null } } ``` ### Configuration The default configuration can be overridden by passing the config dictionary to the Compare class constructor: ```python from jsoncomparison import Compare config = { "output": { "console": False, "file": { "allow_nan": True, "ensure_ascii": True, "indent": 4, "name": None, "skipkeys": True, }, }, "types": { "float": { "allow_round": 2, }, "list": { "check_length": True, } } } cmp = Compare(config) ``` ### Output By default, the configuration does not allow printing the comparison result to the console, but at the same time writes the results to a file. These settings can be changed in your class config: ```py config = { "output": { "console": True, "file": {} } } ``` ### Ignore rules What if you do not want to compare some values and keys of objects from your JSON? In this case, you can define exception rules and pass them to the class constructor. Let's go back to the example above: ```python from jsoncomparison import Compare, NO_DIFF expected = { # ... } actual = { # ... } rules = { "project": { "version": "*", "license": "*", "language": { "versions": { "_values": [ 3.5 ] } } }, "os": "*", } diff = Compare(rules=rules).check(expected, actual) assert diff == NO_DIFF ``` Now that we have added exceptions to the missing values, the comparison test has been successfully passed! ### Links You can see a more complex comparison example that I used to test the correct operation of an application: [link](https://github.com/rugleb/jsoncomparison/blob/master/tests/test_compare.py#L84). %package -n python3-jsoncomparison Summary: json compare utility Provides: python-jsoncomparison BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-jsoncomparison ## The JSON Comparison package [![Build Status](https://travis-ci.com/rugleb/JsonCompare.svg?branch=master)](https://travis-ci.com/rugleb/JsonCompare) [![codecov](https://codecov.io/gh/rugleb/JsonCompare/branch/master/graph/badge.svg)](https://codecov.io/gh/rugleb/JsonCompare) [![Python 3.6+](https://img.shields.io/badge/python-3.6+-green.svg)](https://www.python.org/downloads/release/python-360/) [![PyPI version](https://badge.fury.io/py/jsoncomparison.svg)](https://badge.fury.io/py/jsoncomparison) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) This package is designed to compare two objects with a JSON-like structure and data types. ### Install ``` pip install -U pip jsoncomparison ``` ### Usage First you need to define two variables: `expected` & `actual`. Think of them as the same variables that you use in tests. Expected - the original data object that you want to see. Actual - the given data object. Then we will transfer these objects to check and identify the difference between them: ```python from jsoncomparison import Compare, NO_DIFF expected = { "project": { "name": "jsoncomparison", "version": "0.1", "license": "MIT", "language": { "name": "python", "versions": [ 3.5, 3.6 ] } }, "os": "linux" } actual = { "project": { "name": "jsoncomparison", "version": 0.1, "license": "Apache 2.0", "language": { "name": "python", "versions": [ 3.6 ] } } } diff = Compare().check(expected, actual) assert diff != NO_DIFF ``` The `check` method returns a dictionary of differences between `expected` and `actual` objects: ```json { "project": { "version": { "_message": "Types not equal. Expected: , received: ", "_expected": "str", "_received": "float" }, "license": { "_message": "Values not equal. Expected: , received: ", "_expected": "MIT", "_received": "Apache 2.0" }, "language": { "versions": { "_length": { "_message": "Lengths not equal. Expected <2>, received: <1>", "_expected": 2, "_received": 1 }, "_content": { "0": { "_message": "Value not found. Expected <3.5>", "_expected": 3.5, "_received": null } } } } }, "os": { "_message": "Key does not exists. Expected: ", "_expected": "os", "_received": null } } ``` ### Configuration The default configuration can be overridden by passing the config dictionary to the Compare class constructor: ```python from jsoncomparison import Compare config = { "output": { "console": False, "file": { "allow_nan": True, "ensure_ascii": True, "indent": 4, "name": None, "skipkeys": True, }, }, "types": { "float": { "allow_round": 2, }, "list": { "check_length": True, } } } cmp = Compare(config) ``` ### Output By default, the configuration does not allow printing the comparison result to the console, but at the same time writes the results to a file. These settings can be changed in your class config: ```py config = { "output": { "console": True, "file": {} } } ``` ### Ignore rules What if you do not want to compare some values and keys of objects from your JSON? In this case, you can define exception rules and pass them to the class constructor. Let's go back to the example above: ```python from jsoncomparison import Compare, NO_DIFF expected = { # ... } actual = { # ... } rules = { "project": { "version": "*", "license": "*", "language": { "versions": { "_values": [ 3.5 ] } } }, "os": "*", } diff = Compare(rules=rules).check(expected, actual) assert diff == NO_DIFF ``` Now that we have added exceptions to the missing values, the comparison test has been successfully passed! ### Links You can see a more complex comparison example that I used to test the correct operation of an application: [link](https://github.com/rugleb/jsoncomparison/blob/master/tests/test_compare.py#L84). %package help Summary: Development documents and examples for jsoncomparison Provides: python3-jsoncomparison-doc %description help ## The JSON Comparison package [![Build Status](https://travis-ci.com/rugleb/JsonCompare.svg?branch=master)](https://travis-ci.com/rugleb/JsonCompare) [![codecov](https://codecov.io/gh/rugleb/JsonCompare/branch/master/graph/badge.svg)](https://codecov.io/gh/rugleb/JsonCompare) [![Python 3.6+](https://img.shields.io/badge/python-3.6+-green.svg)](https://www.python.org/downloads/release/python-360/) [![PyPI version](https://badge.fury.io/py/jsoncomparison.svg)](https://badge.fury.io/py/jsoncomparison) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) This package is designed to compare two objects with a JSON-like structure and data types. ### Install ``` pip install -U pip jsoncomparison ``` ### Usage First you need to define two variables: `expected` & `actual`. Think of them as the same variables that you use in tests. Expected - the original data object that you want to see. Actual - the given data object. Then we will transfer these objects to check and identify the difference between them: ```python from jsoncomparison import Compare, NO_DIFF expected = { "project": { "name": "jsoncomparison", "version": "0.1", "license": "MIT", "language": { "name": "python", "versions": [ 3.5, 3.6 ] } }, "os": "linux" } actual = { "project": { "name": "jsoncomparison", "version": 0.1, "license": "Apache 2.0", "language": { "name": "python", "versions": [ 3.6 ] } } } diff = Compare().check(expected, actual) assert diff != NO_DIFF ``` The `check` method returns a dictionary of differences between `expected` and `actual` objects: ```json { "project": { "version": { "_message": "Types not equal. Expected: , received: ", "_expected": "str", "_received": "float" }, "license": { "_message": "Values not equal. Expected: , received: ", "_expected": "MIT", "_received": "Apache 2.0" }, "language": { "versions": { "_length": { "_message": "Lengths not equal. Expected <2>, received: <1>", "_expected": 2, "_received": 1 }, "_content": { "0": { "_message": "Value not found. Expected <3.5>", "_expected": 3.5, "_received": null } } } } }, "os": { "_message": "Key does not exists. Expected: ", "_expected": "os", "_received": null } } ``` ### Configuration The default configuration can be overridden by passing the config dictionary to the Compare class constructor: ```python from jsoncomparison import Compare config = { "output": { "console": False, "file": { "allow_nan": True, "ensure_ascii": True, "indent": 4, "name": None, "skipkeys": True, }, }, "types": { "float": { "allow_round": 2, }, "list": { "check_length": True, } } } cmp = Compare(config) ``` ### Output By default, the configuration does not allow printing the comparison result to the console, but at the same time writes the results to a file. These settings can be changed in your class config: ```py config = { "output": { "console": True, "file": {} } } ``` ### Ignore rules What if you do not want to compare some values and keys of objects from your JSON? In this case, you can define exception rules and pass them to the class constructor. Let's go back to the example above: ```python from jsoncomparison import Compare, NO_DIFF expected = { # ... } actual = { # ... } rules = { "project": { "version": "*", "license": "*", "language": { "versions": { "_values": [ 3.5 ] } } }, "os": "*", } diff = Compare(rules=rules).check(expected, actual) assert diff == NO_DIFF ``` Now that we have added exceptions to the missing values, the comparison test has been successfully passed! ### Links You can see a more complex comparison example that I used to test the correct operation of an application: [link](https://github.com/rugleb/jsoncomparison/blob/master/tests/test_compare.py#L84). %prep %autosetup -n jsoncomparison-1.1.0 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-jsoncomparison -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Thu May 18 2023 Python_Bot - 1.1.0-1 - Package Spec generated