Skip to content

Commit

Permalink
Remove redundant examples
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Jul 31, 2022
1 parent cc4c548 commit 26d25e9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 35 deletions.
36 changes: 2 additions & 34 deletions openfisca_core/periods/period_.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,42 +121,10 @@ class Period(tuple):
"""

def __repr__(self):
def __repr__(self) -> str:
return '{}({})'.format(self.__class__.__name__, super(Period, self).__repr__())

def __str__(self):
"""Transform period to a string.
Examples:
>>> str(Period(("year", Instant((2021, 1, 1)), 1)))
'2021'
>>> str(Period(("year", Instant((2021, 2, 1)), 1)))
'year:2021-02'
>>> str(Period(("month", Instant((2021, 2, 1)), 1)))
'2021-02'
>>> str(Period(("year", Instant((2021, 1, 1)), 2)))
'year:2021:2'
>>> str(Period(("month", Instant((2021, 1, 1)), 2)))
'month:2021-01:2'
>>> str(Period(("month", Instant((2021, 1, 1)), 12)))
'2021'
>>> str(Period(("year", Instant((2021, 3, 1)), 2)))
'year:2021-03:2'
>>> str(Period(("month", Instant((2021, 3, 1)), 2)))
'month:2021-03:2'
>>> str(Period(("month", Instant((2021, 3, 1)), 12)))
'year:2021-03'
"""

def __str__(self) -> str:
unit, start_instant, size = self
if unit == config.ETERNITY:
return 'ETERNITY'
Expand Down
2 changes: 1 addition & 1 deletion openfisca_core/periods/tests/period/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def test_str_with_months(date_unit, instant, size, expected):
[DateUnit.DAY, Instant((2022, 3, 1)), 3, "day:2022-03-01:3"],
])
def test_str_with_days(date_unit, instant, size, expected):
assert str(Period((date_unit, instant, size))) == expected
assert str(Period((date_unit, instant, size))) == expected
1 change: 1 addition & 0 deletions tests/core/test_periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# Years


def test_parsing_year():
assert period('2014') == Period((YEAR, first_jan, 1))

Expand Down

0 comments on commit 26d25e9

Please sign in to comment.