Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
benjello committed Sep 27, 2024
1 parent c3f8142 commit a057acb
Show file tree
Hide file tree
Showing 26 changed files with 290 additions and 297 deletions.
30 changes: 15 additions & 15 deletions notebooks/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@


def is_notebook(file_path):
return file_path[-6:] == ".ipynb"
return file_path[-6:] == '.ipynb'


def run(notebook_path):
'''
Execute a notebook.
If an error occurs, then save results in a new notebook
of the name, prefixed bt "executed_".
of the name, prefixed by `executed_`.
'''
notebook_directory = os.path.dirname(notebook_path)
notebook_filename = os.path.basename(notebook_path)
Expand All @@ -50,50 +50,50 @@ def run(notebook_path):

try:
# Execute all the cells in the notebook
ep = ExecutePreprocessor(timeout = 600, kernel_name = "python")
ep = ExecutePreprocessor(timeout = 600, kernel_name = 'python')
executed_notebook = ep.preprocess(
notebook,
{"metadata": {"path": notebook_directory}}
{'metadata': {'path': notebook_directory}}
)

except CellExecutionError:
executed_notebook = None
msg = 'Error executing the notebook "%s".\n\n' % notebook_filename
msg += 'See notebook "%s" for stack traceback.' % notebook_filename_out
msg = f'Error executing the notebook {notebook_filename}.\n\n'
msg += f'See notebook {notebook_filename_out} for stack traceback.'
log.error(msg)
raise

finally:
with open(notebook_filename_out, mode = "wt") as f:
with open(notebook_filename_out, mode = 'wt') as f:
write(notebook, f)
if executed_notebook is not None:
os.remove(notebook_filename_out)


# Check script target (file or directory) and test all notebooks
if __name__ == "__main__":
if __name__ == '__main__':
try:
target = sys.argv[1]

if os.path.isdir(target):
for file in os.listdir(target):
if is_notebook(file):
log.debug("> " + file)
log.debug('> ' + file)
run(os.path.join(target, file))
else:
if not is_notebook(target):
raise Exception("Expected an .ipynb file. Got: {}".format(target))
raise Exception(f'Expected an .ipynb file. Got: {target}')
run(target)

log.info("OK. No error detected in tested notebook(s).")
log.info('OK. No error detected in tested notebook(s).')
except BaseException as e:
if len(sys.argv) == 1:
log.error("Missing notebook or directory containing notebooks to test.")
log.warn("USAGE: python test_notebooks.py target")
log.warn("where 'target' is directory containing notebooks, or a .ipynb notebook file.")
log.error('Missing notebook or directory containing notebooks to test.')
log.warn('USAGE: python test_notebooks.py target')
log.warn('where `target` is directory containing notebooks, or a .ipynb notebook file.')

else:
log.debug(str(e.__class__.__name__) + ": ")
log.debug(str(e.__class__.__name__) + ': ')
if e.__class__ is CellExecutionError and e.from_cell_and_msg:
log.debug(e.from_cell_and_msg)
elif e.message:
Expand Down
1 change: 1 addition & 0 deletions openfisca_tunisia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
# The name CountryTaxBenefitSystem must not be changed, as all tools of the OpenFisca
# ecosystem expect a CountryTaxBenefitSystem class to be exposed
# in the __init__ module of a country package.

CountryTaxBenefitSystem = TunisiaTaxBenefitSystem
2 changes: 1 addition & 1 deletion openfisca_tunisia/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.


"""Conversion functions"""
'''Conversion functions'''


from openfisca_core.conv import *
Expand Down
12 changes: 6 additions & 6 deletions openfisca_tunisia/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@


Individu = build_entity(
key = "individu",
plural = "individus",
key = 'individu',
plural = 'individus',
label = 'Individu',
is_person = True
)

FoyerFiscal = build_entity(
key = "foyer_fiscal",
plural = "foyers_fiscaux",
key = 'foyer_fiscal',
plural = 'foyers_fiscaux',
label = 'Déclaration d’impôts',
roles = [
{
Expand All @@ -28,8 +28,8 @@
)

Menage = build_entity(
key = "menage",
plural = "menages",
key = 'menage',
plural = 'menages',
label = 'Logement principal',
roles = [
{
Expand Down
7 changes: 2 additions & 5 deletions openfisca_tunisia/model/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
from datetime import date

from openfisca_core.model_api import *

from openfisca_tunisia.entities import FoyerFiscal, Individu, Menage
from openfisca_core.model_api import * # noqa F401
from openfisca_tunisia.entities import FoyerFiscal, Individu, Menage # noqa F401
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class age(Variable):
value_type = int
entity = Individu
label = "Âge (en années)"
label = 'Âge (en années)'
definition_period = YEAR
is_period_size_independent = True
set_input = set_input_dispatch_by_period
Expand All @@ -22,7 +22,7 @@ class age_en_mois(Variable):
default_value = -9999
unit = 'months'
entity = Individu
label = "Âge (en mois)"
label = 'Âge (en mois)'
is_period_size_independent = True
definition_period = MONTH

Expand Down Expand Up @@ -51,21 +51,21 @@ class date_naissance(Variable):
value_type = date
default_value = date(1970, 1, 1)
entity = Individu
label = "Date de naissance"
label = 'Date de naissance'
definition_period = ETERNITY


class male(Variable):
value_type = bool
entity = Individu
label = "Mâle"
label = 'Mâle'
definition_period = ETERNITY


class marie(Variable):
value_type = bool
entity = Individu
label = "Marié(e)"
label = 'Marié(e)'
definition_period = YEAR

def formula(individu, period):
Expand All @@ -76,7 +76,7 @@ def formula(individu, period):
class celibataire(Variable):
value_type = bool
entity = Individu
label = "Célibataire"
label = 'Célibataire'
definition_period = YEAR

def formula(individu, period):
Expand All @@ -87,7 +87,7 @@ def formula(individu, period):
class divorce(Variable):
value_type = bool
entity = Individu
label = "Divorcé(e)"
label = 'Divorcé(e)'
definition_period = YEAR

def formula(individu, period):
Expand All @@ -98,7 +98,7 @@ def formula(individu, period):
class veuf(Variable):
value_type = bool
entity = Individu
label = "Veuf(ve)"
label = 'Veuf(ve)'
definition_period = YEAR

def formula(individu, period):
Expand All @@ -110,25 +110,24 @@ class statut_marital(Variable):
value_type = int
default_value = 2
entity = Individu
label = "Statut marital"
label = 'Statut marital'
definition_period = ETERNITY


class invalide(Variable):
value_type = bool
label = "Invalide"
label = 'Invalide'
entity = Individu
definition_period = ETERNITY


class activite(Variable):
value_type = int
entity = Individu
label = "Activité"
label = 'Activité'
definition_period = ETERNITY



class boursier(Variable):
value_type = bool
entity = Individu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
class code_postal(Variable):
value_type = int
entity = Menage
label = "Localisation du logement (code postal)"
label = 'Localisation du logement (code postal)'
definition_period = ETERNITY


class loyer(Variable):
value_type = int
entity = Menage
label = "Loyer du logement"
label = 'Loyer du logement'
definition_period = YEAR


class statut_occupation_logement(Variable):
value_type = int
entity = Menage
Expand Down
12 changes: 6 additions & 6 deletions openfisca_tunisia/model/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class impots_directs(Variable):
value_type = float
entity = Individu
label = "Impôts directs"
label = 'Impôts directs'
definition_period = YEAR

def formula(individu, period):
Expand All @@ -19,14 +19,14 @@ def formula(individu, period):
class prestations_sociales(Variable):
value_type = int
entity = Individu
label = "Prestations sociales"
label = 'Prestations sociales'
definition_period = YEAR


class revenu_disponible(Variable):
value_type = float
entity = Menage
label = "Revenu disponible du ménage"
label = 'Revenu disponible du ménage'
definition_period = YEAR

def formula(menage, period):
Expand All @@ -37,7 +37,7 @@ def formula(menage, period):
class revenu_disponible_individuel(Variable):
value_type = float
entity = Individu
label = "Revenu disponible individuel"
label = 'Revenu disponible individuel'
definition_period = YEAR

def formula(individu, period):
Expand All @@ -53,7 +53,7 @@ def formula(individu, period):
class revenus_du_capital(Variable):
value_type = float
entity = Individu
label = "Revenus du capital"
label = 'Revenus du capital'
definition_period = YEAR

def formula(individu, period):
Expand All @@ -64,7 +64,7 @@ def formula(individu, period):
class revenus_du_travail(Variable):
value_type = float
entity = Individu
label = "Revenus du travail"
label = 'Revenus du travail'
definition_period = YEAR

def formula(individu, period):
Expand Down
Loading

0 comments on commit a057acb

Please sign in to comment.