-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26d25e9
commit affbebf
Showing
6 changed files
with
68 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
|
||
from openfisca_core import periods | ||
from openfisca_core.periods import Instant, Period | ||
|
||
|
||
@pytest.mark.parametrize("date_unit, instant, size, expected", [ | ||
[periods.DAY, Instant((2022, 12, 31)), 1, 1], | ||
[periods.DAY, Instant((2022, 12, 31)), 3, 3], | ||
[periods.MONTH, Instant((2022, 12, 1)), 1, 31], | ||
[periods.MONTH, Instant((2012, 2, 3)), 1, 29], | ||
[periods.MONTH, Instant((2022, 1, 3)), 3, 31 + 28 + 31], | ||
[periods.MONTH, Instant((2012, 1, 3)), 3, 31 + 29 + 31], | ||
[periods.YEAR, Instant((2022, 12, 1)), 1, 365], | ||
[periods.YEAR, Instant((2012, 1, 1)), 1, 366], | ||
[periods.YEAR, Instant((2022, 1, 1)), 2, 730], | ||
]) | ||
def test_day_size_in_days(date_unit, instant, size, expected): | ||
period = Period((date_unit, instant, size)) | ||
assert period.size_in_days == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
import pytest | ||
|
||
from openfisca_core.periods import DateUnit, Instant, Period | ||
from openfisca_core import periods | ||
from openfisca_core.periods import Instant, Period | ||
|
||
|
||
@pytest.mark.parametrize("date_unit, instant, size, expected", [ | ||
[DateUnit.YEAR, Instant((2022, 1, 1)), 1, "2022"], | ||
[DateUnit.MONTH, Instant((2022, 1, 1)), 12, "2022"], | ||
[DateUnit.YEAR, Instant((2022, 3, 1)), 1, "year:2022-03"], | ||
[DateUnit.MONTH, Instant((2022, 3, 1)), 12, "year:2022-03"], | ||
[DateUnit.YEAR, Instant((2022, 1, 1)), 3, "year:2022:3"], | ||
[DateUnit.YEAR, Instant((2022, 1, 3)), 3, "year:2022:3"], | ||
[periods.YEAR, Instant((2022, 1, 1)), 1, "2022"], | ||
[periods.MONTH, Instant((2022, 1, 1)), 12, "2022"], | ||
[periods.YEAR, Instant((2022, 3, 1)), 1, "year:2022-03"], | ||
[periods.MONTH, Instant((2022, 3, 1)), 12, "year:2022-03"], | ||
[periods.YEAR, Instant((2022, 1, 1)), 3, "year:2022:3"], | ||
[periods.YEAR, Instant((2022, 1, 3)), 3, "year:2022:3"], | ||
]) | ||
def test_str_with_years(date_unit, instant, size, expected): | ||
assert str(Period((date_unit, instant, size))) == expected | ||
|
||
|
||
@pytest.mark.parametrize("date_unit, instant, size, expected", [ | ||
[DateUnit.MONTH, Instant((2022, 1, 1)), 1, "2022-01"], | ||
[DateUnit.MONTH, Instant((2022, 1, 1)), 3, "month:2022-01:3"], | ||
[DateUnit.MONTH, Instant((2022, 3, 1)), 3, "month:2022-03:3"], | ||
[periods.MONTH, Instant((2022, 1, 1)), 1, "2022-01"], | ||
[periods.MONTH, Instant((2022, 1, 1)), 3, "month:2022-01:3"], | ||
[periods.MONTH, Instant((2022, 3, 1)), 3, "month:2022-03:3"], | ||
]) | ||
def test_str_with_months(date_unit, instant, size, expected): | ||
assert str(Period((date_unit, instant, size))) == expected | ||
|
||
|
||
@pytest.mark.parametrize("date_unit, instant, size, expected", [ | ||
[DateUnit.DAY, Instant((2022, 1, 1)), 1, "2022-01-01"], | ||
[DateUnit.DAY, Instant((2022, 1, 1)), 3, "day:2022-01-01:3"], | ||
[DateUnit.DAY, Instant((2022, 3, 1)), 3, "day:2022-03-01:3"], | ||
[periods.DAY, Instant((2022, 1, 1)), 1, "2022-01-01"], | ||
[periods.DAY, Instant((2022, 1, 1)), 3, "day:2022-01-01:3"], | ||
[periods.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters