Skip to content

Commit 238ce28

Browse files
authored
Add missing test cases for next()/previous() (#5777)
tests/u: add missing test cases for `next()`/`previous()` * xfail tests in response to bug discovery * #5777 (comment)
1 parent 050d30f commit 238ce28

File tree

1 file changed

+74
-117
lines changed

1 file changed

+74
-117
lines changed

tests/unit/cycling/test_iso8601.py

+74-117
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
import pytest
1817
from datetime import datetime
1918

19+
import pytest
20+
from pytest import param
21+
2022
from cylc.flow.cycling.iso8601 import (
2123
ISO8601Interval,
2224
ISO8601Point,
@@ -671,74 +673,52 @@ def test_simple(set_cycling_type):
671673
assert not sequence.is_on_sequence(ISO8601Point("20100809T0005"))
672674

673675

674-
def test_next_simple(set_cycling_type):
676+
@pytest.mark.parametrize(
677+
'value, expected', [
678+
('next(T2100Z)', '20100808T2100Z'),
679+
('next(T00)', '20100809T0000Z'),
680+
('next(T-15)', '20100808T1615Z'),
681+
('next(T-45)', '20100808T1545Z'),
682+
('next(-10)', '21100101T0000Z'),
683+
('next(-1008)', '21100801T0000Z'),
684+
('next(--10)', '20101001T0000Z'),
685+
('next(--0325)', '20110325T0000Z'),
686+
('next(---10)', '20100810T0000Z'),
687+
('next(---05T1200Z)', '20100905T1200Z'),
688+
param('next(--08-08)', '20110808T0000Z', marks=pytest.mark.xfail),
689+
('next(T15)', '20100809T1500Z'),
690+
('next(T-41)', '20100808T1541Z'),
691+
]
692+
)
693+
def test_next_simple(value: str, expected: str, set_cycling_type):
675694
"""Test the generation of CP using 'next' from single input."""
676695
set_cycling_type(ISO8601_CYCLING_TYPE, "Z")
677-
my_now = "20100808T1540Z"
678-
sequence = (
679-
"next(T2100Z)", # 20100808T2100Z
680-
"next(T00)", # 20100809T0000Z
681-
"next(T-15)", # 20100808T1615Z
682-
"next(T-45)", # 20100808T1545Z
683-
"next(-10)", # 21100101T0000Z
684-
"next(-1008)", # 21100801T0000Z
685-
"next(--10)", # 20101001T0000Z
686-
"next(--0325)", # 20110325T0000Z
687-
"next(---10)", # 20100810T0000Z
688-
"next(---05T1200Z)", # 20100905T1200Z
689-
)
696+
my_now = "2010-08-08T15:41Z"
697+
assert ingest_time(value, my_now) == expected
690698

691-
output = []
692699

693-
for point in sequence:
694-
output.append(ingest_time(point, my_now))
695-
assert output == [
696-
"20100808T2100Z",
697-
"20100809T0000Z",
698-
"20100808T1615Z",
699-
"20100808T1545Z",
700-
"21100101T0000Z",
701-
"21100801T0000Z",
702-
"20101001T0000Z",
703-
"20110325T0000Z",
704-
"20100810T0000Z",
705-
"20100905T1200Z",
700+
@pytest.mark.parametrize(
701+
'value, expected', [
702+
('previous(T2100Z)', '20100807T2100Z'),
703+
('previous(T00)', '20100808T0000Z'),
704+
('previous(T-15)', '20100808T1515Z'),
705+
('previous(T-45)', '20100808T1445Z'),
706+
('previous(-10)', '20100101T0000Z'),
707+
('previous(-1008)', '20100801T0000Z'),
708+
('previous(--10)', '20091001T0000Z'),
709+
('previous(--0325)', '20100325T0000Z'),
710+
('previous(---10)', '20100710T0000Z'),
711+
('previous(---05T1200Z)', '20100805T1200Z'),
712+
param('previous(--08-08)', '20100808T0000Z', marks=pytest.mark.xfail),
713+
('previous(T15)', '20100808T1500Z'),
714+
('previous(T-41)', '20100808T1441Z'),
706715
]
707-
708-
709-
def test_previous_simple(set_cycling_type):
716+
)
717+
def test_previous_simple(value: str, expected: str, set_cycling_type):
710718
"""Test the generation of CP using 'previous' from single input."""
711719
set_cycling_type(ISO8601_CYCLING_TYPE, "Z")
712-
my_now = "20100808T1540Z"
713-
sequence = (
714-
"previous(T2100Z)", # 20100807T2100Z
715-
"previous(T00)", # 20100808T0000Z
716-
"previous(T-15)", # 20100808T1515Z
717-
"previous(T-45)", # 20100808T1445Z
718-
"previous(-10)", # 20100101T0000Z
719-
"previous(-1008)", # 20100801T0000Z
720-
"previous(--10)", # 20091001T0000Z
721-
"previous(--0325)", # 20100325T0000Z
722-
"previous(---10)", # 20100710T0000Z
723-
"previous(---05T1200Z)", # 20100805T1200Z
724-
)
725-
726-
output = []
727-
728-
for point in sequence:
729-
output.append(ingest_time(point, my_now))
730-
assert output == [
731-
"20100807T2100Z",
732-
"20100808T0000Z",
733-
"20100808T1515Z",
734-
"20100808T1445Z",
735-
"20100101T0000Z",
736-
"20100801T0000Z",
737-
"20091001T0000Z",
738-
"20100325T0000Z",
739-
"20100710T0000Z",
740-
"20100805T1200Z",
741-
]
720+
my_now = "2010-08-08T15:41Z"
721+
assert ingest_time(value, my_now) == expected
742722

743723

744724
def test_sequence(set_cycling_type):
@@ -855,63 +835,40 @@ def test_weeks_days(set_cycling_type):
855835
]
856836

857837

858-
def test_cug(set_cycling_type):
859-
"""Test the offset CP examples in the Cylc user guide"""
838+
@pytest.mark.parametrize(
839+
'value, expected', [
840+
('next(T-00)', '20180314T1600Z'),
841+
('previous(T-00)', '20180314T1500Z'),
842+
('next(T-00; T-15; T-30; T-45)', '20180314T1515Z'),
843+
('previous(T-00; T-15; T-30; T-45)', '20180314T1500Z'),
844+
('next(T00)', '20180315T0000Z'),
845+
('previous(T00)', '20180314T0000Z'),
846+
('next(T06:30Z)', '20180315T0630Z'),
847+
('previous(T06:30) -P1D', '20180313T0630Z'),
848+
('next(T00; T06; T12; T18)', '20180314T1800Z'),
849+
('previous(T00; T06; T12; T18)', '20180314T1200Z'),
850+
('next(T00; T06; T12; T18)+P1W', '20180321T1800Z'),
851+
('PT1H', '20180314T1612Z'),
852+
('-P1M', '20180214T1512Z'),
853+
('next(-00)', '21000101T0000Z'),
854+
('previous(--01)', '20180101T0000Z'),
855+
('next(---01)', '20180401T0000Z'),
856+
('previous(--1225)', '20171225T0000Z'),
857+
('next(-2006)', '20200601T0000Z'),
858+
('previous(-W101)', '20180305T0000Z'),
859+
('next(-W-1; -W-3; -W-5)', '20180314T0000Z'),
860+
('next(-001; -091; -181; -271)', '20180401T0000Z'),
861+
('previous(-365T12Z)', '20171231T1200Z'),
862+
]
863+
)
864+
def test_user_guide_examples(value: str, expected: str, set_cycling_type):
865+
"""Test the offset CP examples in the Cylc user guide.
866+
867+
https://cylc.github.io/cylc-doc/stable/html/user-guide/writing-workflows/scheduling.html
868+
"""
860869
set_cycling_type(ISO8601_CYCLING_TYPE, "Z")
861870
my_now = "2018-03-14T15:12Z"
862-
sequence = (
863-
"next(T-00)", # 20180314T1600Z
864-
"previous(T-00)", # 20180314T1500Z
865-
"next(T-00; T-15; T-30; T-45)", # 20180314T1515Z
866-
"previous(T-00; T-15; T-30; T-45)", # 20180314T1500Z
867-
"next(T00)", # 20180315T0000Z
868-
"previous(T00)", # 20180314T0000Z
869-
"next(T06:30Z)", # 20180315T0630Z
870-
"previous(T06:30) -P1D", # 20180313T0630Z
871-
"next(T00; T06; T12; T18)", # 20180314T1800Z
872-
"previous(T00; T06; T12; T18)", # 20180314T1200Z
873-
"next(T00; T06; T12; T18)+P1W", # 20180321T1800Z
874-
"PT1H", # 20180314T1612Z
875-
"-P1M", # 20180214T1512Z
876-
"next(-00)", # 21000101T0000Z
877-
"previous(--01)", # 20180101T0000Z
878-
"next(---01)", # 20180401T0000Z
879-
"previous(--1225)", # 20171225T0000Z
880-
"next(-2006)", # 20200601T0000Z
881-
"previous(-W101)", # 20180305T0000Z
882-
"next(-W-1; -W-3; -W-5)", # 20180314T0000Z
883-
"next(-001; -091; -181; -271)", # 20180401T0000Z
884-
"previous(-365T12Z)", # 20171231T1200Z
885-
)
886-
887-
output = []
888-
889-
for point in sequence:
890-
output.append(ingest_time(point, my_now))
891-
assert output == [
892-
"20180314T1600Z",
893-
"20180314T1500Z",
894-
"20180314T1515Z",
895-
"20180314T1500Z",
896-
"20180315T0000Z",
897-
"20180314T0000Z",
898-
"20180315T0630Z",
899-
"20180313T0630Z",
900-
"20180314T1800Z",
901-
"20180314T1200Z",
902-
"20180321T1800Z",
903-
"20180314T1612Z",
904-
"20180214T1512Z",
905-
"21000101T0000Z",
906-
"20180101T0000Z",
907-
"20180401T0000Z",
908-
"20171225T0000Z",
909-
"20200601T0000Z",
910-
"20180305T0000Z",
911-
"20180314T0000Z",
912-
"20180401T0000Z",
913-
"20171231T1200Z",
914-
]
871+
assert ingest_time(value, my_now) == expected
915872

916873

917874
def test_next_simple_no_now(set_cycling_type):

0 commit comments

Comments
 (0)