| 1 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 2 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 |
# |
| 4 |
# This program is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 3 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
import unittest |
| 18 |
|
| 19 |
from cylc.flow.task_id import TaskID |
| 20 |
|
| 21 |
|
| 22 |
class TestTaskId(unittest.TestCase): |
| 23 |
|
| 24 |
def test_get(self): |
| 25 |
self.assertEqual("a.1", TaskID.get("a", 1)) |
| 26 |
self.assertEqual("a._1", TaskID.get("a", "_1")) |
| 27 |
self.assertEqual( |
| 28 |
"WTASK.20101010T101010", TaskID.get("WTASK", "20101010T101010")) |
| 29 |
|
| 30 |
def test_split(self): |
| 31 |
self.assertEqual(["a", '1'], TaskID.split("a.1")) |
| 32 |
self.assertEqual(["a", '_1'], TaskID.split("a._1")) |
| 33 |
self.assertEqual( |
| 34 |
["WTAS", '20101010T101010'], TaskID.split("WTAS.20101010T101010")) |
| 35 |
|
| 36 |
def test_is_valid_name(self): |
| 37 |
for name in [ |
| 38 |
"abc", "123", "____", "_", "a_b", "a_1", "1_b", "ABC" |
| 39 |
]: |
| 40 |
self.assertTrue(TaskID.is_valid_name(name)) |
| 41 |
for name in [ |
| 42 |
"a.1", None, "%abc", "", " " |
| 43 |
]: |
| 44 |
self.assertFalse(TaskID.is_valid_name(name)) |
| 45 |
|
| 46 |
def test_is_valid_id(self): |
| 47 |
for id1 in [ |
| 48 |
"a.1", "_.098098439535$#%#@!#~" |
| 49 |
]: |
| 50 |
self.assertTrue(TaskID.is_valid_id(id1)) |
| 51 |
for id2 in [ |
| 52 |
"abc", "123", "____", "_", "a_b", "a_1", "1_b", "ABC", "a.A A" |
| 53 |
]: |
| 54 |
self.assertFalse(TaskID.is_valid_id(id2)) |
| 55 |
|
| 56 |
def test_is_valid_id_2(self): |
| 57 |
# TBD: a.A A is invalid for valid_id, but valid for valid_id_2? |
| 58 |
# TBD: a/a.a is OK? |
| 59 |
for id1 in [ |
| 60 |
"a.1", "_.098098439535$#%#@!#~", "a/1", "_/098098439535$#%#@!#~", |
| 61 |
"a.A A", "a/a.a" |
| 62 |
]: |
| 63 |
self.assertTrue(TaskID.is_valid_id_2(id1)) |
| 64 |
for id2 in [ |
| 65 |
"abc", "123", "____", "_", "a_b", "a_1", "1_b", "ABC" |
| 66 |
]: |
| 67 |
self.assertFalse(TaskID.is_valid_id_2(id2)) |