Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

### 35.3.5 [#997](https://github.com/openfisca/openfisca-core/pull/997)

#### Technical changes

- In tests, extract `CountryTaxBenefitSystem` to a fixture reusable by all the tests in the test suite.
- It allows for a better reusability of test scenarios available to new contributors.
- To mitigate possible performance issues, by default the fixture is initialised once per test module.

### 35.3.4 [#999](https://github.com/openfisca/openfisca-core/pull/999)

#### Technical improvements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pytest tests/core/test_parameters.py -k test_parameter_for_period

## Style

This repository adheres to a certain coding style, and we invite you to follow it for your contributions to be integrated promptly.
This repository adheres to a [certain coding style](STYLEGUIDE.md), and we invite you to follow it for your contributions to be integrated promptly.

Style checking is already run with `make test`. To run the style checker alone:

Expand Down
84 changes: 84 additions & 0 deletions STYLEGUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# OpenFisca's Python Style Guide

Arguments over code style and formatting are the bread and butter of most open-source projets out there, including OpenFisca.

To avoid this, we have a style guide, that is a set or arbitrary but consistent conventions about how code should be written, for contributors and maintainers alike.

## Notice

### About this style guide

The present style guide is a work in progress.

It largely follows [Python Foundation's](https://www.python.org/dev/peps/pep-0008/), [NumPy's](https://numpydoc.readthedocs.io/en/latest/format.html) and [Google's](https://google.github.io/styleguide/pyguide.html), but it has a lot of her own as well.

### Contributing

Please refer whenever possible to this style guide both for your contributions and your reviews.

If the style in question is not present and contentious, do not hesitate to include an addition to this guide within your proposal or review.

## Imports

1. In general, use import statements for entire namespaces and modules, rather than for classes and functions. Are exempt of this rule the `typing` module, NumPy's `typing` module, and `openfisca_core` module and submodules (but only in the case of class imports).

2. In general, use absolute import statements rather that relative ones. Are exempt of this rule the modules relative to a submodule of OpenFisca, in order to improve the delimitation of internal and external interfaces.

3. Always follow this order for your imports: system modules, third party modules, third party OpenFisca modules, external OpenFisca Core modules, internal OpenFisca Core modules.

For example given:

```
/openfisca_core/axes/__init__.py
/openfisca_core/axes/nothing.py
/openfisca_core/axes/something.py
```

Whenever possible we should expect:

```python
# /openfisca_core/axes/nothing.py
#
# Yes

import copy
from typing import List

import numpy
from numpy.typing import ArrayLike

from openfisca_country_template import entities

from openfisca_core import tools
from openfisca_core.variables import Variable

from . import Something

def do(this: List) -> ArrayLike:
that = copy.deepcopy(this)
array = numpy.ndarray(that)
return Something(entities.Person, Variable)
```

And avoid:

```python
# /openfisca_core/axes/nothing.py
#
# No

from openfisca_country_template.entities import Person
from openfisca_core import variables
from openfisca_core.tools import assert_near
from openfisca_core import axes

from numpy import ndarray
from copy import deepcopy
import typing
import numpy.typing

def do(this: typing.List) -> numpy.typing.ArrayLike:
that = deepcopy(this)
array = ndarray(that)
return axes.Something(Person, variables.Variable)
```
5 changes: 5 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pytest_plugins = [
"tests.fixtures.entities",
"tests.fixtures.simulations",
"tests.fixtures.taxbenefitsystems",
]
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-


from setuptools import setup, find_packages

Expand Down Expand Up @@ -37,7 +35,7 @@

setup(
name = 'OpenFisca-Core',
version = '35.3.4',
version = '35.3.5',
author = 'OpenFisca Team',
author_email = '[email protected]',
classifiers = [
Expand Down
Empty file added tests/__init__.py
Empty file.
13 changes: 6 additions & 7 deletions tests/core/parameter_validation/test_parameter_clone.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
from ..test_countries import tax_benefit_system

import os

from openfisca_core.parameters import ParameterNode

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
year = 2016

Expand All @@ -20,7 +19,7 @@ def test_clone():
assert id(clone.node1.param) != id(parameters.node1.param)


def test_clone_parameter():
def test_clone_parameter(tax_benefit_system):

param = tax_benefit_system.parameters.taxes.income_tax_rate
clone = param.clone()
Expand All @@ -32,7 +31,7 @@ def test_clone_parameter():
assert clone.values_list == param.values_list


def test_clone_parameter_node():
def test_clone_parameter_node(tax_benefit_system):
node = tax_benefit_system.parameters.taxes
clone = node.clone()

Expand All @@ -41,15 +40,15 @@ def test_clone_parameter_node():
assert clone.children['income_tax_rate'] is not node.children['income_tax_rate']


def test_clone_scale():
def test_clone_scale(tax_benefit_system):
scale = tax_benefit_system.parameters.taxes.social_security_contribution
clone = scale.clone()

assert clone.brackets[0] is not scale.brackets[0]
assert clone.brackets[0].rate is not scale.brackets[0].rate


def test_deep_edit():
def test_deep_edit(tax_benefit_system):
parameters = tax_benefit_system.parameters
clone = parameters.clone()

Expand Down
Loading