Debian Codegraph @

tests/functional/cyclepoint/00-time.t

raw
1 #!/usr/bin/env bash
2 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
3 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #-------------------------------------------------------------------------------
18 # basic jinja2 expansion test
19 . "$(dirname "$0")/test_header"
20 #-------------------------------------------------------------------------------
21 set_test_number 45
22 #-------------------------------------------------------------------------------
23 TEST_NAME=${TEST_NAME_BASE}-use-env-var
24 export CYLC_TASK_CYCLE_POINT=20100102T0300
25 run_ok "${TEST_NAME}.check-env" cylc cycle-point
26 run_ok "${TEST_NAME}.year-only" cylc cycle-point --print-year
27 cmp_ok "${TEST_NAME}.year-only.stdout" - << __OUT__
28 2010
29 __OUT__
30 run_ok "${TEST_NAME}.month-only" cylc cycle-point --print-month
31 cmp_ok "${TEST_NAME}.month-only.stdout" - << __OUT__
32 01
33 __OUT__
34 run_ok "${TEST_NAME}.day-only" cylc cycle-point --print-day
35 cmp_ok "${TEST_NAME}.day-only.stdout" - << __OUT__
36 02
37 __OUT__
38 run_ok "${TEST_NAME}.hour-only" cylc cycle-point --print-hour
39 cmp_ok "${TEST_NAME}.hour-only.stdout" - << __OUT__
40 03
41 __OUT__
42 #-------------------------------------------------------------------------------
43 TEST_NAME=${TEST_NAME_BASE}-offset-env-var
44 run_ok "${TEST_NAME}.year" cylc cycle-point --offset-years=10
45 cmp_ok "${TEST_NAME}.year.stdout" - << __OUT__
46 20200102T0300
47 __OUT__
48 run_ok "${TEST_NAME}.year-neg" cylc cycle-point --offset-years=-11
49 cmp_ok "${TEST_NAME}.year-neg.stdout" - << __OUT__
50 19990102T0300
51 __OUT__
52 run_ok "${TEST_NAME}.month" cylc cycle-point --offset-months=2
53 cmp_ok "${TEST_NAME}.month.stdout" - << __OUT__
54 20100302T0300
55 __OUT__
56 run_ok "${TEST_NAME}.month-neg" cylc cycle-point --offset-months=-1
57 cmp_ok "${TEST_NAME}.month-neg.stdout" - << __OUT__
58 20091202T0300
59 __OUT__
60 run_ok "${TEST_NAME}.day" cylc cycle-point --offset-days=10
61 cmp_ok "${TEST_NAME}.day.stdout" - << __OUT__
62 20100112T0300
63 __OUT__
64 run_ok "${TEST_NAME}.day-neg" cylc cycle-point --offset-days=-2
65 cmp_ok "${TEST_NAME}.day-neg.stdout" - << __OUT__
66 20091231T0300
67 __OUT__
68 run_ok "${TEST_NAME}.hour" cylc cycle-point --offset-hours=10
69 cmp_ok "${TEST_NAME}.hour.stdout" - << __OUT__
70 20100102T1300
71 __OUT__
72 run_ok "${TEST_NAME}.hour-neg" cylc cycle-point --offset-hours=-3
73 cmp_ok "${TEST_NAME}.hour-neg.stdout" - << __OUT__
74 20100102T0000
75 __OUT__
76 #-------------------------------------------------------------------------------
77 #Test with a supplied cycle time
78 # N.B. this also checks environment variable being by CLI options
79 TEST_NAME="${TEST_NAME_BASE}-print-supplied-ctime"
80 run_ok "${TEST_NAME}.full" cylc cycle-point '2011-01-01'
81 cmp_ok "${TEST_NAME}.full.stdout" - <<<'2011-01-01'
82 run_ok "${TEST_NAME}-offset-week" cylc cycle-point --offset=P1W '20160301T06Z'
83 cmp_ok "${TEST_NAME}-offset-week.stdout" - <<<'20160308T06Z'
84 #-------------------------------------------------------------------------------
85 unset CYLC_TASK_CYCLE_POINT
86 # Test --equal option
87 TEST_NAME="${TEST_NAME_BASE}-equal"
88 run_ok "${TEST_NAME}-true" cylc cycle-point 2000 --equal 2000
89 run_fail "${TEST_NAME}-true" cylc cycle-point 2000 --equal 2001
90 run_fail "${TEST_NAME}-invalid" cylc cycle-point 2000 --equal x
91
92 # Test --template option
93 TEST_NAME="${TEST_NAME_BASE}-template"
94 run_ok "${TEST_NAME}-pass" cylc cycle-point 2010-08 \
95 --offset-years=2 --template=foo-CCYY-MM.nc
96 cmp_ok "${TEST_NAME}-pass.stdout" <<< 'foo-2012-08.nc'
97 # invalid arg combo
98 run_fail "${TEST_NAME}-fail" cylc cycle-point 2000 --template=x --print-year
99 #-------------------------------------------------------------------------------
100 TEST_NAME="${TEST_NAME_BASE}-fail"
101 # no cycle point
102 run_fail "${TEST_NAME}-1" cylc cycle-point
103 # invalid cycle point
104 run_fail "${TEST_NAME}-2" cylc cycle-point x
105 # too many cycle points
106 run_fail "${TEST_NAME}-3" cylc cycle-point 2000 2000
107 # invalid offsets
108 run_ok "${TEST_NAME}-5" cylc cycle-point 2000 --offset-hours=1 # VALID
109 run_fail "${TEST_NAME}-6" cylc cycle-point 2000 --offset-hours=x # INVALID
110 run_fail "${TEST_NAME}-7" cylc cycle-point 2000 --offset-days=x
111 run_fail "${TEST_NAME}-8" cylc cycle-point 2000 --offset-months=x
112 run_fail "${TEST_NAME}-9" cylc cycle-point 2000 --offset-years=x
113 # invalid ISO offset
114 run_ok "${TEST_NAME}-10" cylc cycle-point 2000 --offset=P1Y # VALID
115 run_fail "${TEST_NAME}-11" cylc cycle-point 2000 --offset=PT1Y # INVALID