Hello community, here is the log from the commit of package python-warlock for openSUSE:Factory checked in at 2019-09-27 14:49:19 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-warlock (Old) and /work/SRC/openSUSE:Factory/.python-warlock.new.2352 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-warlock" Fri Sep 27 14:49:19 2019 rev:17 rq:731437 version:1.3.3 Changes: -------- --- /work/SRC/openSUSE:Factory/python-warlock/python-warlock.changes 2019-05-27 08:38:26.203069773 +0200 +++ /work/SRC/openSUSE:Factory/.python-warlock.new.2352/python-warlock.changes 2019-09-27 14:49:20.584625181 +0200 @@ -1,0 +2,6 @@ +Tue Sep 17 04:46:39 UTC 2019 - John Vandenberg <[email protected]> + +- Re-activate test suite using GitHub tarball which includes + a setup.py + +------------------------------------------------------------------- @@ -4 +10 @@ -- Update to 1.3.2: +- Update to 1.3.3: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-warlock.spec ++++++ --- /var/tmp/diff_new_pack.LY2r4J/_old 2019-09-27 14:49:21.052623964 +0200 +++ /var/tmp/diff_new_pack.LY2r4J/_new 2019-09-27 14:49:21.056623953 +0200 @@ -24,7 +24,7 @@ License: Apache-2.0 Group: Development/Languages/Python URL: http://github.com/bcwaldon/warlock -Source: https://files.pythonhosted.org/packages/source/w/warlock/warlock-%{version}.tar.gz +Source: https://github.com/bcwaldon/warlock/archive/%{version}.tar.gz#/warlock-%{version}.tar.gz BuildRequires: %{python_module jsonpatch >= 0.7} BuildRequires: %{python_module jsonschema >= 0.10} BuildRequires: %{python_module pytest} @@ -39,10 +39,11 @@ %python_subpackages %description -Build self-validating python objects using JSON schemas +Build self-validating python objects using JSON schemas. %prep %setup -q -n warlock-%{version} +rm pytest.ini %build %python_build @@ -52,8 +53,7 @@ %python_expand %fdupes %{buildroot}%{$python_sitelib} %check -# tests are not distributed by upstream and github does not -# use setuptools anymore +%pytest %files %{python_files} %doc README.md ++++++ warlock-1.3.3.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/.coveragerc new/warlock-1.3.3/.coveragerc --- old/warlock-1.3.3/.coveragerc 1970-01-01 01:00:00.000000000 +0100 +++ new/warlock-1.3.3/.coveragerc 2019-05-20 12:07:50.000000000 +0200 @@ -0,0 +1,19 @@ +[run] +source = + warlock +omit = + tests/* + venv/* + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if __name__ == .__main__.: \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/.flake8 new/warlock-1.3.3/.flake8 --- old/warlock-1.3.3/.flake8 1970-01-01 01:00:00.000000000 +0100 +++ new/warlock-1.3.3/.flake8 2019-05-20 12:07:50.000000000 +0200 @@ -0,0 +1,9 @@ +[flake8] +ignore = E203, E266, E501, W503 +max-line-length = 88 +exclude = + .git + __pycache__ + locale/ + htmlcov/ +max-complexity = 10 \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/.gitignore new/warlock-1.3.3/.gitignore --- old/warlock-1.3.3/.gitignore 1970-01-01 01:00:00.000000000 +0100 +++ new/warlock-1.3.3/.gitignore 2019-05-20 12:07:50.000000000 +0200 @@ -0,0 +1,12 @@ +.venv +build/ +dist/ +warlock.egg-info/ +.tox/ +*.swp +*.pyc +.coverage +.pytest_cache/ +.python-version +htmlcov/ +.vscode/ \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/.travis.yml new/warlock-1.3.3/.travis.yml --- old/warlock-1.3.3/.travis.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/warlock-1.3.3/.travis.yml 2019-05-20 12:07:50.000000000 +0200 @@ -0,0 +1,41 @@ +dist: xenial +language: python +python: 3.7 +cache: pip + +env: +- TEST_CMD="pytest" + +install: + - pip install pytest pytest-cov + - if [[ $TRAVIS_PYTHON_VERSION == 3.7 ]] && [[ "$TEST_CMD" == pytest* ]]; then + pip install pytest pytest-cov coveralls; fi + - if [[ $TEST_CMD == black* ]]; then pip install black; fi + - if [[ $TEST_CMD == flake8* ]]; then pip install flake8 flake8-bugbear flake8-todo; fi + +script: +- python setup.py develop +- $TEST_CMD + +after_success: + - if [[ $TRAVIS_PYTHON_VERSION == 3.7 ]] && [[ "$TEST_CMD" == pytest* ]]; + then coveralls; fi + +matrix: + include: + - name: "black" + env: + - TEST_CMD="black --check --verbose ." + - name: "flake8" + env: + - TEST_CMD="flake8 warlock" + - name: "pytest-py2.7" + python: 2.7 + - name: "pytest-py3.4" + python: 3.4 + - name: "pytest-py3.5" + python: 3.5 + - name: "pytest-py3.6" + python: 3.6 + - name: "pytest-py3.7" + python: 3.7 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/CHANGELOG.md new/warlock-1.3.3/CHANGELOG.md --- old/warlock-1.3.3/CHANGELOG.md 1970-01-01 01:00:00.000000000 +0100 +++ new/warlock-1.3.3/CHANGELOG.md 2019-05-20 12:07:50.000000000 +0200 @@ -0,0 +1,65 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [1.3.3] - 2019-05-20 +### Fixed +- setup.py failing for Python 2.7. #41 + +### Added +- Test run of setup.py in develop mode for installing requirements, sanity check. Relates to #41 + +## [1.3.2] - 2019-05-20 +### Fixed +- README failed parsing in non utf-8 environments. Enforce encoding. #37 + +## [1.3.1] - 2019-05-19 +### Added +- Travis CI test support for Python 3.6, and 3.7 +- More project metadata to properly list on PyPi + +### Removed +- Travis CI test runs for Python 2.6, and 3.3 + +### Changed +- Requirement for jsonschema library extended to version `<4` +- Conform to Black codestyle +- Move unittests to `tests/` directory + +### Fixed +- README formatting (codeblocks showing correctly) + +## [1.3.0] - 2016-06-25 + +## [1.2.0] - 2015-10-12 + +## [1.1.0] - 2013-11-19 + +## [1.0.1] - 2013-06-28 + +## [1.0.0] - 2013-04-26 + +## [0.8.2] - 2013-03-25 + +## [0.8.1] - 2013-01-31 + +## [0.8.0] - 2013-01-21 + +## [0.7.0] - 2012-11-26 +[Unreleased]: https://github.com/bcwaldon/warlock/compare/v1.3.3...HEAD +[1.3.3]: https://github.com/bcwaldon/warlock/compare/v1.3.2...v1.3.3 +[1.3.2]: https://github.com/bcwaldon/warlock/compare/v1.3.1...v1.3.2 +[1.3.1]: https://github.com/bcwaldon/warlock/compare/v1.3.0...v1.3.1 +[1.3.0]: https://github.com/bcwaldon/warlock/compare/1.2.0...1.3.0 +[1.2.0]: https://github.com/bcwaldon/warlock/compare/1.1.0...1.2.0 +[1.1.0]: https://github.com/bcwaldon/warlock/compare/1.0.1...1.1.0 +[1.0.1]: https://github.com/bcwaldon/warlock/compare/1.0.0...1.0.1 +[1.0.0]: https://github.com/bcwaldon/warlock/compare/0.8.2...1.0.0 +[0.8.2]: https://github.com/bcwaldon/warlock/compare/0.8.1...0.8.2 +[0.8.1]: https://github.com/bcwaldon/warlock/compare/0.8.0...0.8.1 +[0.8.0]: https://github.com/bcwaldon/warlock/compare/0.7.0...0.8.0 +[0.7.0]: https://github.com/bcwaldon/warlock/releases/tag/0.7.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/CONTRIBUTING.md new/warlock-1.3.3/CONTRIBUTING.md --- old/warlock-1.3.3/CONTRIBUTING.md 1970-01-01 01:00:00.000000000 +0100 +++ new/warlock-1.3.3/CONTRIBUTING.md 2019-05-20 12:07:50.000000000 +0200 @@ -0,0 +1,7 @@ +# How to contribute + +Pull Requests are greatly welcome from everyone! Please make sure to fulfill the following criteria when proposing changes to Warlock: + +- Write unit tests, and run them through pytest; test coverage must not decrease +- Make sure to support Python 2.7 -- 3.7; Travis CI will check all non-EOL version of Python +- Run flake8 without warnings; including flake8-bugbear plugin diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/PKG-INFO new/warlock-1.3.3/PKG-INFO --- old/warlock-1.3.3/PKG-INFO 2019-05-20 12:10:52.000000000 +0200 +++ new/warlock-1.3.3/PKG-INFO 1970-01-01 01:00:00.000000000 +0100 @@ -1,105 +0,0 @@ -Metadata-Version: 2.1 -Name: warlock -Version: 1.3.3 -Summary: Python object model built on JSON schema and JSON patch. -Home-page: http://github.com/bcwaldon/warlock -Author: Brian Waldon -Author-email: [email protected] -Maintainer: Jan Willhaus -Maintainer-email: [email protected] -License: Apache-2.0 -Description: # Warlock — self-validating Python objects using JSON schema - - [][warlock] - [][warlock] - [][pypistats] - - [][ci-builds] - [][coveralls] - - ## Installation - - Warlock is [available on PyPI][warlock]: - - ```shell - pip install warlock - ``` - - ## Usage - - 1) Create your schema - - ```python - >>> schema = { - 'name': 'Country', - 'properties': { - 'name': {'type': 'string'}, - 'abbreviation': {'type': 'string'}, - 'population': {'type': 'integer'}, - }, - 'additionalProperties': False, - } - ``` - - 2) Create a model - - ```python - >>> import warlock - >>> Country = warlock.model_factory(schema) - ``` - - 3) Create an object using your model - - ```python - >>> sweden = Country(name='Sweden', abbreviation='SE') - ``` - - 4) Let the object validate itself - - ```python - >>> sweden.name = 5 - Traceback (most recent call last): - File "<stdin>", line 1, in <module> - File "warlock/core.py", line 53, in __setattr__ - raise InvalidOperation(msg) - warlock.core.InvalidOperation: Unable to set 'name' to '5' - - >>> sweden.overlord = 'Bears' - Traceback (most recent call last): - File "<stdin>", line 1, in <module> - File "warlock/core.py", line 53, in __setattr__ - raise InvalidOperation(msg) - warlock.core.InvalidOperation: Unable to set 'overlord' to 'Bears' - ``` - - 5) Generate a [JSON Patch document](http://tools.ietf.org/html/draft-ietf-appsawg-json-patch) to track changes - - ```python - >>> sweden.population=9453000 - >>> sweden.patch - '[{"path": "/population", "value": 9453000, "op": "add"}]' - ``` - - [warlock]: https://pypi.org/project/warlock/ - [pip]: https://pip.pypa.io/en/stable/ - [ci-builds]: https://travis-ci.org/bcwaldon/warlock - [coveralls]: https://coveralls.io/github/bcwaldon/warlock?branch=master - [pypistats]: https://pypistats.org/packages/warlock - -Keywords: JSON schema,JSON patch,model validation -Platform: UNKNOWN -Classifier: Development Status :: 5 - Production/Stable -Classifier: Intended Audience :: Developers -Classifier: Operating System :: MacOS :: MacOS X -Classifier: Operating System :: Microsoft :: Windows -Classifier: Operating System :: POSIX -Classifier: Programming Language :: Python -Classifier: Programming Language :: Python :: 2 -Classifier: Programming Language :: Python :: 2.7 -Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.4 -Classifier: Programming Language :: Python :: 3.5 -Classifier: Programming Language :: Python :: 3.6 -Classifier: Programming Language :: Python :: 3.7 -Classifier: Topic :: Software Development :: Libraries :: Python Modules -Description-Content-Type: text/markdown diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/pyproject.toml new/warlock-1.3.3/pyproject.toml --- old/warlock-1.3.3/pyproject.toml 1970-01-01 01:00:00.000000000 +0100 +++ new/warlock-1.3.3/pyproject.toml 2019-05-20 12:07:50.000000000 +0200 @@ -0,0 +1,11 @@ +[tool.black] +line-length = 88 +include = '\.pyi?$' +exclude = ''' +/( + | \.git + | \.venv + | venv + | __pycache__ +)/ +''' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/pytest.ini new/warlock-1.3.3/pytest.ini --- old/warlock-1.3.3/pytest.ini 1970-01-01 01:00:00.000000000 +0100 +++ new/warlock-1.3.3/pytest.ini 2019-05-20 12:07:50.000000000 +0200 @@ -0,0 +1,9 @@ +[pytest] +testpaths = tests +norecursedirs = .git venv __pycache__ +addopts = + --cov + --cov-config=.coveragerc + --cov-report html + --cov-report term + --verbose \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/setup.cfg new/warlock-1.3.3/setup.cfg --- old/warlock-1.3.3/setup.cfg 2019-05-20 12:10:52.000000000 +0200 +++ new/warlock-1.3.3/setup.cfg 2019-05-20 12:07:50.000000000 +0200 @@ -1,7 +1,2 @@ [bdist_wheel] universal = 1 - -[egg_info] -tag_build = -tag_date = 0 - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/tests/schemas/country.json new/warlock-1.3.3/tests/schemas/country.json --- old/warlock-1.3.3/tests/schemas/country.json 1970-01-01 01:00:00.000000000 +0100 +++ new/warlock-1.3.3/tests/schemas/country.json 2019-05-20 12:07:50.000000000 +0200 @@ -0,0 +1,10 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema", + "name": "Country", + "properties": { + "name": {"type": "string"}, + "population": {"type": "integer"}, + "overlord": { "$ref": "person.json#" } + }, + "additionalProperties": false +} \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/tests/schemas/person.json new/warlock-1.3.3/tests/schemas/person.json --- old/warlock-1.3.3/tests/schemas/person.json 1970-01-01 01:00:00.000000000 +0100 +++ new/warlock-1.3.3/tests/schemas/person.json 2019-05-20 12:07:50.000000000 +0200 @@ -0,0 +1,10 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema", + "name": "Person", + "type" : "object", + "properties": { + "title": { "type": "string" }, + "firstname": { "type": "string" }, + "lastname": { "type": "string" } + } +} \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/tests/test_core.py new/warlock-1.3.3/tests/test_core.py --- old/warlock-1.3.3/tests/test_core.py 1970-01-01 01:00:00.000000000 +0100 +++ new/warlock-1.3.3/tests/test_core.py 2019-05-20 12:07:50.000000000 +0200 @@ -0,0 +1,296 @@ +# Copyright 2012 Brian Waldon +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import copy +import unittest +import os + +import json + +import six + +import warlock + + +fixture = { + "name": "Country", + "properties": {"name": {"type": "string"}, "population": {"type": "integer"}}, + "additionalProperties": False, +} + + +complex_fixture = { + "name": "Mixmaster", + "properties": { + "sub": {"type": "object", "properties": {"foo": {"type": "string"}}} + }, +} + +parent_fixture = { + "name": "Parent", + "properties": { + "name": {"type": "string"}, + "children": {"type": "array", "items": [{"type": "object"}]}, + }, + "required": ["name", "children"], +} + +child_fixture = { + "name": "Child", + "properties": {"age": {"type": "integer"}, "mother": {"type": "object"}}, + "required": ["age", "mother"], +} + + +nameless_fixture = { + "properties": {"name": {"type": "string"}, "population": {"type": "integer"}}, + "additionalProperties": False, +} + + +class TestCore(unittest.TestCase): + def test_create_invalid_object(self): + Country = warlock.model_factory(fixture) + self.assertRaises(ValueError, Country, name=1) + + def test_class_name_from_unicode_schema_name(self): + fixture_copy = copy.deepcopy(fixture) + fixture_copy["name"] = six.text_type(fixture_copy["name"]) + # Can't set class.__name__ to a unicode object, ensure warlock + # does some magic to make it possible + warlock.model_factory(fixture_copy) + + def test_invalid_operations(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + + # Ensure a valid object was created + self.assertEqual(sweden.name, "Sweden") + self.assertEqual(sweden.population, 9379116) + + # Specific exceptions should be raised for invalid operations + self.assertRaises(AttributeError, getattr, sweden, "overlord") + exc = warlock.InvalidOperation + self.assertRaises(exc, setattr, sweden, "overlord", "Bears") + self.assertRaises(exc, setattr, sweden, "name", 5) + self.assertRaises(exc, setattr, sweden, "population", "N/A") + + def test_no_mask_arbitrary_properties(self): + fixture_copy = copy.deepcopy(fixture) + fixture_copy["additionalProperties"] = {"type": "string"} + Country = warlock.model_factory(fixture_copy) + + # We should still depend on the schema for validation + self.assertRaises(ValueError, Country, GDP=56956) + + # But arbitrary properties should be allowed if they check out + sweden = Country(overlord="Waldon") + sweden.abbreviation = "SE" + exc = warlock.InvalidOperation + self.assertRaises(exc, setattr, sweden, "abbreviation", 0) + + def test_items(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + self.assertEqual( + set(list(six.iteritems(sweden))), + set([("name", "Sweden"), ("population", 9379116)]), + ) + self.assertEqual( + set(sweden.items()), set([("name", "Sweden"), ("population", 9379116)]) + ) + + def test_update(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + exc = warlock.InvalidOperation + self.assertRaises(exc, sweden.update, {"population": "N/A"}) + self.assertRaises(exc, sweden.update, {"overloard": "Bears"}) + + def test_naming(self): + Country = warlock.model_factory(fixture) + self.assertEqual("Country", Country.__name__) + + Country2 = warlock.model_factory(fixture, name="Country2") + self.assertEqual("Country2", Country2.__name__) + + nameless = warlock.model_factory(nameless_fixture) + self.assertEqual("Model", nameless.__name__) + + nameless2 = warlock.model_factory(nameless_fixture, name="Country3") + self.assertEqual("Country3", nameless2.__name__) + + def test_deepcopy(self): + """Make sure we aren't leaking references.""" + Mixmaster = warlock.model_factory(complex_fixture) + mike = Mixmaster(sub={"foo": "mike"}) + + self.assertEquals("mike", mike.sub["foo"]) + + mike_1 = mike.copy() + mike_1["sub"]["foo"] = "james" + self.assertEquals("mike", mike.sub["foo"]) + + mike_2 = dict(six.iteritems(mike)) + mike_2["sub"]["foo"] = "james" + self.assertEquals("mike", mike.sub["foo"]) + + mike_2 = dict(mike.items()) + mike_2["sub"]["foo"] = "james" + self.assertEquals("mike", mike.sub["foo"]) + + mike_3_sub = list(six.itervalues(mike))[0] + mike_3_sub["foo"] = "james" + self.assertEquals("mike", mike.sub["foo"]) + + mike_3_sub = list(mike.values())[0] + mike_3_sub["foo"] = "james" + self.assertEquals("mike", mike.sub["foo"]) + + def test_forbidden_methods(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + exc = warlock.InvalidOperation + self.assertRaises(exc, sweden.clear) + self.assertRaises(exc, sweden.pop, 0) + self.assertRaises(exc, sweden.popitem) + + def test_dict_syntax(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + + sweden["name"] = "Finland" + self.assertEqual("Finland", sweden["name"]) + + del sweden["name"] + self.assertRaises(AttributeError, getattr, sweden, "name") + + def test_attr_syntax(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + + sweden.name = "Finland" + self.assertEqual("Finland", sweden.name) + + delattr(sweden, "name") + self.assertRaises(AttributeError, getattr, sweden, "name") + + def test_changes(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + self.assertEqual(sweden.changes, {}) + sweden["name"] = "Finland" + self.assertEqual(sweden.changes, {"name": "Finland"}) + sweden["name"] = "Norway" + self.assertEqual(sweden.changes, {"name": "Norway"}) + + def test_patch_no_changes(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + self.assertEqual(sweden.patch, "[]") + + def test_patch_alter_value(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + sweden["name"] = "Finland" + self.assertEqual( + json.loads(sweden.patch), + json.loads('[{"path": "/name", "value": "Finland", "op": "replace"}]'), + ) + + def test_patch_drop_attribute(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + del sweden["name"] + self.assertEqual( + json.loads(sweden.patch), json.loads('[{"path": "/name", "op": "remove"}]') + ) + + def test_patch_reduce_operations(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + + sweden["name"] = "Finland" + self.assertEqual( + json.loads(sweden.patch), + json.loads('[{"path": "/name", "value": "Finland", "op": "replace"}]'), + ) + + sweden["name"] = "Norway" + self.assertEqual( + json.loads(sweden.patch), + json.loads('[{"path": "/name", "value": "Norway", "op": "replace"}]'), + ) + + def test_patch_multiple_operations(self): + Country = warlock.model_factory(fixture) + sweden = Country(name="Sweden", population=9379116) + + sweden["name"] = "Finland" + sweden["population"] = 5387000 + + self.assertEqual(len(json.loads(sweden.patch)), 2) + + patches = json.loads( + '[{"path": "/name", "value": "Finland", "op": "replace"}, ' + '{"path": "/population", "value": 5387000, "op": "replace"}]' + ) + + for patch in json.loads(sweden.patch): + self.assertTrue(patch in patches) + + def test_resolver(self): + from jsonschema import RefResolver + + dirname = os.path.dirname(__file__) + schemas_path = "file://" + os.path.join(dirname, "schemas/") + resolver = RefResolver(schemas_path, None) + + country_schema_file = open(os.path.join(dirname, "schemas/") + "country.json") + person_schema_file = open(os.path.join(dirname, "schemas/") + "person.json") + + country_schema = json.load(country_schema_file) + person_schema = json.load(person_schema_file) + Country = warlock.model_factory(country_schema, resolver) + Person = warlock.model_factory(person_schema, resolver) + + england = Country( + name="England", + population=53865800, + overlord=Person(title="Queen", firstname="Elizabeth", lastname="Windsor"), + ) + expected = { + "name": "England", + "population": 53865800, + "overlord": { + "title": "Queen", + "lastname": "Windsor", + "firstname": "Elizabeth", + }, + } + self.assertEqual(england, expected) + + def test_recursive_models(self): + Parent = warlock.model_factory(parent_fixture) + Child = warlock.model_factory(child_fixture) + + mom = Parent(name="Abby", children=[]) + + teenager = Child(age=15, mother=mom) + toddler = Child(age=3, mother=mom) + + mom.children = [teenager, toddler] + + self.assertEqual(mom.children[0].age, 15) + self.assertEqual(mom.children[1].age, 3) Binary files old/warlock-1.3.3/warlock/__init__.pyc and new/warlock-1.3.3/warlock/__init__.pyc differ Binary files old/warlock-1.3.3/warlock/core.pyc and new/warlock-1.3.3/warlock/core.pyc differ Binary files old/warlock-1.3.3/warlock/exceptions.pyc and new/warlock-1.3.3/warlock/exceptions.pyc differ Binary files old/warlock-1.3.3/warlock/model.pyc and new/warlock-1.3.3/warlock/model.pyc differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/warlock.egg-info/PKG-INFO new/warlock-1.3.3/warlock.egg-info/PKG-INFO --- old/warlock-1.3.3/warlock.egg-info/PKG-INFO 2019-05-20 12:10:52.000000000 +0200 +++ new/warlock-1.3.3/warlock.egg-info/PKG-INFO 1970-01-01 01:00:00.000000000 +0100 @@ -1,105 +0,0 @@ -Metadata-Version: 2.1 -Name: warlock -Version: 1.3.3 -Summary: Python object model built on JSON schema and JSON patch. -Home-page: http://github.com/bcwaldon/warlock -Author: Brian Waldon -Author-email: [email protected] -Maintainer: Jan Willhaus -Maintainer-email: [email protected] -License: Apache-2.0 -Description: # Warlock — self-validating Python objects using JSON schema - - [][warlock] - [][warlock] - [][pypistats] - - [][ci-builds] - [][coveralls] - - ## Installation - - Warlock is [available on PyPI][warlock]: - - ```shell - pip install warlock - ``` - - ## Usage - - 1) Create your schema - - ```python - >>> schema = { - 'name': 'Country', - 'properties': { - 'name': {'type': 'string'}, - 'abbreviation': {'type': 'string'}, - 'population': {'type': 'integer'}, - }, - 'additionalProperties': False, - } - ``` - - 2) Create a model - - ```python - >>> import warlock - >>> Country = warlock.model_factory(schema) - ``` - - 3) Create an object using your model - - ```python - >>> sweden = Country(name='Sweden', abbreviation='SE') - ``` - - 4) Let the object validate itself - - ```python - >>> sweden.name = 5 - Traceback (most recent call last): - File "<stdin>", line 1, in <module> - File "warlock/core.py", line 53, in __setattr__ - raise InvalidOperation(msg) - warlock.core.InvalidOperation: Unable to set 'name' to '5' - - >>> sweden.overlord = 'Bears' - Traceback (most recent call last): - File "<stdin>", line 1, in <module> - File "warlock/core.py", line 53, in __setattr__ - raise InvalidOperation(msg) - warlock.core.InvalidOperation: Unable to set 'overlord' to 'Bears' - ``` - - 5) Generate a [JSON Patch document](http://tools.ietf.org/html/draft-ietf-appsawg-json-patch) to track changes - - ```python - >>> sweden.population=9453000 - >>> sweden.patch - '[{"path": "/population", "value": 9453000, "op": "add"}]' - ``` - - [warlock]: https://pypi.org/project/warlock/ - [pip]: https://pip.pypa.io/en/stable/ - [ci-builds]: https://travis-ci.org/bcwaldon/warlock - [coveralls]: https://coveralls.io/github/bcwaldon/warlock?branch=master - [pypistats]: https://pypistats.org/packages/warlock - -Keywords: JSON schema,JSON patch,model validation -Platform: UNKNOWN -Classifier: Development Status :: 5 - Production/Stable -Classifier: Intended Audience :: Developers -Classifier: Operating System :: MacOS :: MacOS X -Classifier: Operating System :: Microsoft :: Windows -Classifier: Operating System :: POSIX -Classifier: Programming Language :: Python -Classifier: Programming Language :: Python :: 2 -Classifier: Programming Language :: Python :: 2.7 -Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.4 -Classifier: Programming Language :: Python :: 3.5 -Classifier: Programming Language :: Python :: 3.6 -Classifier: Programming Language :: Python :: 3.7 -Classifier: Topic :: Software Development :: Libraries :: Python Modules -Description-Content-Type: text/markdown diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/warlock.egg-info/SOURCES.txt new/warlock-1.3.3/warlock.egg-info/SOURCES.txt --- old/warlock-1.3.3/warlock.egg-info/SOURCES.txt 2019-05-20 12:10:52.000000000 +0200 +++ new/warlock-1.3.3/warlock.egg-info/SOURCES.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1,19 +0,0 @@ -LICENSE -MANIFEST.in -README.md -requirements.txt -setup.cfg -setup.py -warlock/__init__.py -warlock/__init__.pyc -warlock/core.py -warlock/core.pyc -warlock/exceptions.py -warlock/exceptions.pyc -warlock/model.py -warlock/model.pyc -warlock.egg-info/PKG-INFO -warlock.egg-info/SOURCES.txt -warlock.egg-info/dependency_links.txt -warlock.egg-info/requires.txt -warlock.egg-info/top_level.txt \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/warlock.egg-info/dependency_links.txt new/warlock-1.3.3/warlock.egg-info/dependency_links.txt --- old/warlock-1.3.3/warlock.egg-info/dependency_links.txt 2019-05-20 12:10:52.000000000 +0200 +++ new/warlock-1.3.3/warlock.egg-info/dependency_links.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1 +0,0 @@ - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/warlock.egg-info/requires.txt new/warlock-1.3.3/warlock.egg-info/requires.txt --- old/warlock-1.3.3/warlock.egg-info/requires.txt 2019-05-20 12:10:52.000000000 +0200 +++ new/warlock-1.3.3/warlock.egg-info/requires.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1,3 +0,0 @@ -jsonschema<4,>=0.7 -jsonpatch<2,>=0.10 -six diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/warlock-1.3.3/warlock.egg-info/top_level.txt new/warlock-1.3.3/warlock.egg-info/top_level.txt --- old/warlock-1.3.3/warlock.egg-info/top_level.txt 2019-05-20 12:10:52.000000000 +0200 +++ new/warlock-1.3.3/warlock.egg-info/top_level.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1 +0,0 @@ -warlock
