-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parse_timedelta acts exacty the same as previous library
- Loading branch information
Showing
5 changed files
with
78 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,56 @@ | ||
import pytest | ||
|
||
from kiota_abstractions.utils import parseTimeDeltaFromIsoFormat | ||
from kiota_abstractions.utils import parse_timedelta_from_iso_format | ||
|
||
|
||
def test_parseTimeDeltaFromIsoFormat_weeks(): | ||
result = parseTimeDeltaFromIsoFormat("P3W") | ||
def test_parse_timedelta_from_iso_format_weeks(): | ||
result = parse_timedelta_from_iso_format("P3W") | ||
assert result.days == 21 | ||
|
||
|
||
def test_parseTimeDeltaFromIsoFormat_days(): | ||
result = parseTimeDeltaFromIsoFormat("P3D") | ||
def test_parse_timedelta_from_iso_format_days(): | ||
result = parse_timedelta_from_iso_format("P3D") | ||
assert result.days == 3 | ||
|
||
|
||
def test_parseTimeDeltaFromIsoFormat_hours(): | ||
result = parseTimeDeltaFromIsoFormat("PT3H") | ||
def test_parse_timedelta_from_iso_format_hours(): | ||
result = parse_timedelta_from_iso_format("PT3H") | ||
assert result.seconds == 10800 | ||
|
||
|
||
def test_parseTimeDeltaFromIsoFormat_minutes(): | ||
result = parseTimeDeltaFromIsoFormat("PT3M") | ||
def test_parse_timedelta_from_iso_format_minutes(): | ||
result = parse_timedelta_from_iso_format("PT3M") | ||
assert result.seconds == 180 | ||
|
||
|
||
def test_parseTimeDeltaFromIsoFormat_seconds(): | ||
result = parseTimeDeltaFromIsoFormat("PT3S") | ||
def test_parse_timedelta_from_iso_format_seconds(): | ||
result = parse_timedelta_from_iso_format("PT3S") | ||
assert result.seconds == 3 | ||
|
||
|
||
def test_parseTimeDeltaFromIsoFormat_years(): | ||
result = parseTimeDeltaFromIsoFormat("P3Y") | ||
def test_parse_timedelta_from_iso_format_years(): | ||
result = parse_timedelta_from_iso_format("P3Y") | ||
assert result.days == 1095 | ||
|
||
|
||
def test_parseTimeDeltaFromIsoFormat_months(): | ||
result = parseTimeDeltaFromIsoFormat("P3M") | ||
def test_parse_timedelta_from_iso_format_months(): | ||
result = parse_timedelta_from_iso_format("P3M") | ||
assert result.days == 90 | ||
|
||
# This is "invalid" according to the ISO 8601 standard, but python also supports it | ||
|
||
def test_parse_timedelta_from_iso_format_days_and_time(): | ||
result = parse_timedelta_from_iso_format("P3DT3H3M3S") | ||
assert result.days == 3 | ||
assert result.seconds == 10983 | ||
|
||
def test_parseTimeDeltaFromIsoFormat_weeks_and_years(): | ||
result = parseTimeDeltaFromIsoFormat("P3Y3W") | ||
assert result.days == 1122 | ||
|
||
def test_parse_timedelta_from_iso_format_weeks_and_years(): | ||
# assert this raises a ValueError | ||
with pytest.raises(ValueError): | ||
parse_timedelta_from_iso_format("P3W3Y") | ||
|
||
def test_parseTimeDeltaFromIsoFormat_days_and_time(): | ||
result = parseTimeDeltaFromIsoFormat("P3DT3H3M3S") | ||
assert result.days == 3 | ||
assert result.seconds == 10983 | ||
|
||
def test_parse_timedelta_from_iso_format_years_and_weeks(): | ||
# assert this raises a ValueError | ||
with pytest.raises(ValueError): | ||
parse_timedelta_from_iso_format("P3Y3W") |
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