Skip to content

Commit

Permalink
Bump dpath and autopep8 dependencies
Browse files Browse the repository at this point in the history
Merge pull request #940 from openfisca/dependabot/pip/dpath-2.0.1
  • Loading branch information
Mauko Quiroga authored Feb 8, 2020
2 parents 189bcd9 + 759bd41 commit 7fe1e45
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 43 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 34.7.1 [#940](https://github.com/openfisca/openfisca-core/pull/940)

#### Technical changes

- Update dependencies: dpath, autopep8

## 34.7.0 [#943](https://github.com/openfisca/openfisca-core/pull/943)

#### Deprecations
Expand Down
4 changes: 2 additions & 2 deletions openfisca_core/simulation_builder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from typing import Dict, List, Iterable

import dpath
import dpath.util
import numpy as np
from copy import deepcopy

Expand Down Expand Up @@ -428,7 +428,7 @@ def raise_period_mismatch(self, entity, json, e):
# It is only raised when we consume the buffer. We thus don't know which exact key caused the error.
# We do a basic research to find the culprit path
culprit_path = next(
dpath.search(json, "*/{}/{}".format(e.variable_name, str(e.period)), yielded = True),
dpath.util.search(json, "*/{}/{}".format(e.variable_name, str(e.period)), yielded = True),
None)
if culprit_path:
path = [entity.plural] + culprit_path[0].split('/')
Expand Down
4 changes: 2 additions & 2 deletions openfisca_web_api/handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

import dpath
import dpath.util

from openfisca_core.simulation_builder import SimulationBuilder
from openfisca_core.indexed_enums import Enum
Expand Down Expand Up @@ -31,7 +31,7 @@ def calculate(tax_benefit_system, input_data):

dpath.util.new(computation_results, path, entity_result)

dpath.merge(input_data, computation_results)
dpath.util.merge(input_data, computation_results)

return input_data

Expand Down
30 changes: 15 additions & 15 deletions openfisca_web_api/loader/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import yaml
from copy import deepcopy

import dpath
import dpath.util

from openfisca_core.indexed_enums import Enum
from openfisca_web_api import handlers
Expand All @@ -18,18 +18,18 @@ def build_openAPI_specification(api_data):
file = open(OPEN_API_CONFIG_FILE, 'r')
spec = yaml.safe_load(file)
country_package_name = api_data['country_package_metadata']['name'].title()
dpath.new(spec, 'info/title', spec['info']['title'].replace("{COUNTRY_PACKAGE_NAME}", country_package_name))
dpath.new(spec, 'info/description', spec['info']['description'].replace("{COUNTRY_PACKAGE_NAME}", country_package_name))
dpath.new(spec, 'info/version', api_data['country_package_metadata']['version'])
dpath.util.new(spec, 'info/title', spec['info']['title'].replace("{COUNTRY_PACKAGE_NAME}", country_package_name))
dpath.util.new(spec, 'info/description', spec['info']['description'].replace("{COUNTRY_PACKAGE_NAME}", country_package_name))
dpath.util.new(spec, 'info/version', api_data['country_package_metadata']['version'])

for entity in tax_benefit_system.entities:
name = entity.key.title()
spec['definitions'][name] = get_entity_json_schema(entity, tax_benefit_system)

situation_schema = get_situation_json_schema(tax_benefit_system)
dpath.new(spec, 'definitions/SituationInput', situation_schema)
dpath.new(spec, 'definitions/SituationOutput', situation_schema.copy())
dpath.new(spec, 'definitions/Trace/properties/entitiesDescription/properties', {
dpath.util.new(spec, 'definitions/SituationInput', situation_schema)
dpath.util.new(spec, 'definitions/SituationOutput', situation_schema.copy())
dpath.util.new(spec, 'definitions/Trace/properties/entitiesDescription/properties', {
entity.plural: {'type': 'array', 'items': {"type": "string"}}
for entity in tax_benefit_system.entities
})
Expand All @@ -42,24 +42,24 @@ def build_openAPI_specification(api_data):
parameter_example = api_data['parameters'][parameter_path]
else:
parameter_example = next(iter(api_data['parameters'].values()))
dpath.new(spec, 'definitions/Parameter/example', parameter_example)
dpath.util.new(spec, 'definitions/Parameter/example', parameter_example)

if tax_benefit_system.open_api_config.get('variable_example'):
variable_example = api_data['variables'][tax_benefit_system.open_api_config['variable_example']]
else:
variable_example = next(iter(api_data['variables'].values()))
dpath.new(spec, 'definitions/Variable/example', variable_example)
dpath.util.new(spec, 'definitions/Variable/example', variable_example)

if tax_benefit_system.open_api_config.get('simulation_example'):
simulation_example = tax_benefit_system.open_api_config['simulation_example']
dpath.new(spec, 'definitions/SituationInput/example', simulation_example)
dpath.new(spec, 'definitions/SituationOutput/example', handlers.calculate(tax_benefit_system, deepcopy(simulation_example))) # calculate has side-effects
dpath.new(spec, 'definitions/Trace/example', handlers.trace(tax_benefit_system, simulation_example))
dpath.util.new(spec, 'definitions/SituationInput/example', simulation_example)
dpath.util.new(spec, 'definitions/SituationOutput/example', handlers.calculate(tax_benefit_system, deepcopy(simulation_example))) # calculate has side-effects
dpath.util.new(spec, 'definitions/Trace/example', handlers.trace(tax_benefit_system, simulation_example))
else:
message = "No simulation example has been defined for this tax and benefit system. If you are the maintainer of {}, you can define an example by following this documentation: https://openfisca.org/doc/openfisca-web-api/config-openapi.html".format(country_package_name)
dpath.new(spec, 'definitions/SituationInput/example', message)
dpath.new(spec, 'definitions/SituationOutput/example', message)
dpath.new(spec, 'definitions/Trace/example', message)
dpath.util.new(spec, 'definitions/SituationInput/example', message)
dpath.util.new(spec, 'definitions/SituationOutput/example', message)
dpath.util.new(spec, 'definitions/Trace/example', message)
return spec


Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# functional and integration breaks caused by external code updates.

general_requirements = [
'dpath == 1.5.0',
'dpath == 2.0.1',
'pytest >= 4.4.1, < 6.0.0', # For openfisca test
'numpy >= 1.11, < 1.18',
'psutil >= 5.4.7, < 6.0.0',
Expand All @@ -25,7 +25,7 @@
]

dev_requirements = [
'autopep8 >= 1.4.0, < 1.5.0',
'autopep8 >= 1.4.0, < 1.6.0',
'flake8 >= 3.7.0, < 3.8.0',
'flake8-bugbear >= 19.3.0, < 20.0.0',
'flake8-print >= 3.1.0, < 4.0.0',
Expand All @@ -37,7 +37,7 @@

setup(
name = 'OpenFisca-Core',
version = '34.7.0',
version = '34.7.1',
author = 'OpenFisca Team',
author_email = 'contact@openfisca.org',
classifiers = [
Expand Down
22 changes: 11 additions & 11 deletions tests/web_api/test_calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from copy import deepcopy

import pytest
import dpath
import dpath.util

from openfisca_country_template.situation_examples import couple

Expand Down Expand Up @@ -104,12 +104,12 @@ def test_basic_calculation():
response = post_json(simulation_json)
assert response.status_code == OK
response_json = json.loads(response.data.decode('utf-8'))
assert dpath.get(response_json, 'persons/bill/basic_income/2017-12') == 600 # Universal basic income
assert dpath.get(response_json, 'persons/bill/income_tax/2017-12') == 300 # 15% of the salary
assert dpath.get(response_json, 'persons/bill/age/2017-12') == 37 # 15% of the salary
assert dpath.get(response_json, 'persons/bob/basic_income/2017-12') == 600
assert dpath.get(response_json, 'persons/bob/social_security_contribution/2017-12') == 816 # From social_security_contribution.yaml test
assert dpath.get(response_json, 'households/first_household/housing_tax/2017') == 3000
assert dpath.util.get(response_json, 'persons/bill/basic_income/2017-12') == 600 # Universal basic income
assert dpath.util.get(response_json, 'persons/bill/income_tax/2017-12') == 300 # 15% of the salary
assert dpath.util.get(response_json, 'persons/bill/age/2017-12') == 37 # 15% of the salary
assert dpath.util.get(response_json, 'persons/bob/basic_income/2017-12') == 600
assert dpath.util.get(response_json, 'persons/bob/social_security_contribution/2017-12') == 816 # From social_security_contribution.yaml test
assert dpath.util.get(response_json, 'households/first_household/housing_tax/2017') == 3000


def test_enums_sending_identifier():
Expand All @@ -136,7 +136,7 @@ def test_enums_sending_identifier():
response = post_json(simulation_json)
assert response.status_code == OK
response_json = json.loads(response.data.decode('utf-8'))
assert dpath.get(response_json, 'households/_/housing_tax/2017') == 0
assert dpath.util.get(response_json, 'households/_/housing_tax/2017') == 0


def test_enum_output():
Expand All @@ -157,7 +157,7 @@ def test_enum_output():
response = post_json(simulation_json)
assert response.status_code == OK
response_json = json.loads(response.data.decode('utf-8'))
assert dpath.get(response_json, "households/_/housing_occupancy_status/2017-01") == "tenant"
assert dpath.util.get(response_json, "households/_/housing_occupancy_status/2017-01") == "tenant"


def test_enum_wrong_value():
Expand All @@ -179,7 +179,7 @@ def test_enum_wrong_value():
assert response.status_code == BAD_REQUEST
response_json = json.loads(response.data.decode('utf-8'))
message = "Possible values are ['owner', 'tenant', 'free_lodger', 'homeless']"
text = dpath.get(response_json, "households/_/housing_occupancy_status/2017-01")
text = dpath.util.get(response_json, "households/_/housing_occupancy_status/2017-01")
assert message in text


Expand All @@ -206,7 +206,7 @@ def test_encoding_variable_value():
assert response.status_code == BAD_REQUEST, response.data.decode('utf-8')
response_json = json.loads(response.data.decode('utf-8'))
message = "'Locataire ou sous-locataire d‘un logement loué vide non-HLM' is not a known value for 'housing_occupancy_status'. Possible values are "
text = dpath.get(response_json, 'households/_/housing_occupancy_status/2017-07')
text = dpath.util.get(response_json, 'households/_/housing_occupancy_status/2017-07')
assert message in text


Expand Down
20 changes: 10 additions & 10 deletions tests/web_api/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from http.client import OK

import dpath
import dpath.util
from . import subject


Expand Down Expand Up @@ -36,21 +36,21 @@ def test_paths():


def test_entity_definition():
assert 'parents' in dpath.get(body, 'definitions/Household/properties')
assert 'children' in dpath.get(body, 'definitions/Household/properties')
assert 'salary' in dpath.get(body, 'definitions/Person/properties')
assert 'rent' in dpath.get(body, 'definitions/Household/properties')
assert 'number' == dpath.get(body, 'definitions/Person/properties/salary/additionalProperties/type')
assert 'parents' in dpath.util.get(body, 'definitions/Household/properties')
assert 'children' in dpath.util.get(body, 'definitions/Household/properties')
assert 'salary' in dpath.util.get(body, 'definitions/Person/properties')
assert 'rent' in dpath.util.get(body, 'definitions/Household/properties')
assert 'number' == dpath.util.get(body, 'definitions/Person/properties/salary/additionalProperties/type')


def test_situation_definition():
situation_input = body['definitions']['SituationInput']
situation_output = body['definitions']['SituationOutput']
for situation in situation_input, situation_output:
assert 'households' in dpath.get(situation, '/properties')
assert 'persons' in dpath.get(situation, '/properties')
assert "#/definitions/Household" == dpath.get(situation, '/properties/households/additionalProperties/$ref')
assert "#/definitions/Person" == dpath.get(situation, '/properties/persons/additionalProperties/$ref')
assert 'households' in dpath.util.get(situation, '/properties')
assert 'persons' in dpath.util.get(situation, '/properties')
assert "#/definitions/Household" == dpath.util.get(situation, '/properties/households/additionalProperties/$ref')
assert "#/definitions/Person" == dpath.util.get(situation, '/properties/persons/additionalProperties/$ref')


def test_host():
Expand Down

0 comments on commit 7fe1e45

Please sign in to comment.