|
| 1 | +import pendulum |
| 2 | + |
| 3 | + |
| 4 | +def test_week(): |
| 5 | + start_date = pendulum.datetime(2012, 1, 1) |
| 6 | + period = pendulum.period(start=start_date, end=start_date.add(weeks=1)) |
| 7 | + assert period.in_words() == "1 week" |
| 8 | + |
| 9 | + |
| 10 | +def test_week_and_day(): |
| 11 | + start_date = pendulum.datetime(2012, 1, 1) |
| 12 | + period = pendulum.period(start=start_date, end=start_date.add(weeks=1, days=1)) |
| 13 | + assert period.in_words() == "1 week 1 day" |
| 14 | + |
| 15 | + |
| 16 | +def test_all(): |
| 17 | + start_date = pendulum.datetime(2012, 1, 1) |
| 18 | + period = pendulum.period( |
| 19 | + start=start_date, |
| 20 | + end=start_date.add(years=1, months=1, days=1, seconds=1, microseconds=1), |
| 21 | + ) |
| 22 | + assert period.in_words() == "1 year 1 month 1 day 1 second" |
| 23 | + |
| 24 | + |
| 25 | +def test_in_french(): |
| 26 | + start_date = pendulum.datetime(2012, 1, 1) |
| 27 | + period = pendulum.period( |
| 28 | + start=start_date, |
| 29 | + end=start_date.add(years=1, months=1, days=1, seconds=1, microseconds=1), |
| 30 | + ) |
| 31 | + assert period.in_words(locale="fr") == "1 an 1 mois 1 jour 1 seconde" |
| 32 | + |
| 33 | + |
| 34 | +def test_singular_negative_values(): |
| 35 | + start_date = pendulum.datetime(2012, 1, 1) |
| 36 | + period = pendulum.period(start=start_date, end=start_date.subtract(days=1)) |
| 37 | + assert period.in_words() == "-1 day" |
| 38 | + |
| 39 | + |
| 40 | +def test_separator(): |
| 41 | + start_date = pendulum.datetime(2012, 1, 1) |
| 42 | + period = pendulum.period( |
| 43 | + start=start_date, |
| 44 | + end=start_date.add(years=1, months=1, days=1, seconds=1, microseconds=1), |
| 45 | + ) |
| 46 | + assert period.in_words(separator=", ") == "1 year, 1 month, 1 day, 1 second" |
| 47 | + |
| 48 | + |
| 49 | +def test_subseconds(): |
| 50 | + start_date = pendulum.datetime(2012, 1, 1) |
| 51 | + period = pendulum.period(start=start_date, end=start_date.add(microseconds=123456)) |
| 52 | + assert period.in_words() == "0.12 second" |
| 53 | + |
| 54 | + |
| 55 | +def test_subseconds_with_seconds(): |
| 56 | + start_date = pendulum.datetime(2012, 1, 1) |
| 57 | + period = pendulum.period( |
| 58 | + start=start_date, end=start_date.add(seconds=12, microseconds=123456) |
| 59 | + ) |
| 60 | + assert period.in_words() == "12 seconds" |
| 61 | + |
| 62 | + |
| 63 | +def test_zero_period(): |
| 64 | + start_date = pendulum.datetime(2012, 1, 1) |
| 65 | + period = pendulum.period(start=start_date, end=start_date) |
| 66 | + assert period.in_words() == "0 microseconds" |
0 commit comments