-
Notifications
You must be signed in to change notification settings - Fork 3
Coding guidelines
DaceyTom2 edited this page Oct 20, 2020
·
20 revisions
Welcome to the openfisca-canada-dts Coding Guidelines wiki!
- Enums live with their variables, unless they are common throughout the project
- Class names camel case
- Enum in all caps
- Value human readable
- Enums used for the OF enum approach all include unknown as an option
- Enum is the standard approach for benefit finder over booleans and strings
Clarification: The IncomeStatus enum can live with the income_status variable in the same .py file because they are a 1 to 1 relationship. However, BooleanEnum should not live with cerb_is_eligible because many places will use the BooleanEnum
class IncomeStatus(Enum):
ALL_INCOME = "lost all income"
SOME_INCOME = "lost some income"
UNCHANGED_INCOME = "lost no income"
UNKNOWN = "unknown"
- Variables are named using snake case
- Top level eligibility variables are named is_eligible prefixed with benefit named followed by two underscores
- Regular variables should have specific and clear names for their purpose
class benefit_name__is_eligible(Variable):
class this_is_a_clear_variable_to_demonstrate_snake_case(Variable)
https://openfisca.org/doc/openfisca-python-api/variables.html
class benefit_name__is_eligible(Variable):
value_type = Enum
entity = Person
definition_period = MONTH
label = u"is person eligible for benefit"
reference = "tbd"
def formula(persons, period, parameters):
return persons('this_is_a_clear_variable_to_demonstrate_snake_case', period)
- Folders are named using snake case
- Folders are to follow an intuitive pattern to allow variables to be easily reused
-> benefit_eligiblity
---> emergency_relief
-----> cerb__is_eligible.py
-----> crb__is_eligibility.py
---> emplyoment
---> student
-> country
---> age
----->country_age.py
---> country_population
---> provinces
-----> province_population
-> person
---> age
-----> person_age.py
- Tests folder structure should mirror variables
- Unit tests are written in a specific way to utilise the OpenFisca framework using yaml
- Minimum 80% coverage
https://openfisca.org/doc/openfisca-python-api/openfisca_test.html
- name: "Example test"
period: 2020-09
absolute_error_margin: 0
input:
example_input: true
output:
example_output_is_eligible: true
To be defined...