def test_exclusions_extensive(self): """Test IntegerSequence methods for sequences with exclusions.""" point_0 = IntegerPoint(0) point_1 = IntegerPoint(1) point_2 = IntegerPoint(2) point_3 = IntegerPoint(3) point_4 = IntegerPoint(4) sequence = IntegerSequence('R/P1!3', 1, 5) self.assertFalse(sequence.is_on_sequence(point_3)) self.assertFalse(sequence.is_valid(point_3)) self.assertEqual(sequence.get_prev_point(point_3), point_2) self.assertEqual(sequence.get_prev_point(point_4), point_2) self.assertEqual(sequence.get_nearest_prev_point(point_3), point_2) self.assertEqual(sequence.get_nearest_prev_point(point_3), point_2) self.assertEqual(sequence.get_next_point(point_3), point_4) self.assertEqual(sequence.get_next_point(point_2), point_4) self.assertEqual(sequence.get_next_point_on_sequence(point_3), point_4) self.assertEqual(sequence.get_next_point_on_sequence(point_2), point_4) sequence = IntegerSequence('R/P1!1', 1, 5) self.assertEqual(sequence.get_first_point(point_1), point_2) self.assertEqual(sequence.get_first_point(point_0), point_2) self.assertEqual(sequence.get_start_point(), point_2) sequence = IntegerSequence('R/P1!5', 1, 5) self.assertEqual(sequence.get_stop_point(), point_4)
async def test_hold_point(hold_after_point: int, expected_held_task_ids: List[str], example_flow: Scheduler, db_select: Callable) -> None: """Test TaskPool.set_hold_point() and .release_hold_point()""" expected_held_task_ids = sorted(expected_held_task_ids) task_pool = example_flow.pool # Test hold task_pool.set_hold_point(IntegerPoint(hold_after_point)) assert ('holdcp', str(hold_after_point)) in db_select(example_flow, True, 'workflow_params') for itask in task_pool.get_all_tasks(): hold_expected = itask.identity in expected_held_task_ids assert itask.state.is_held is hold_expected assert get_task_ids(task_pool.tasks_to_hold) == expected_held_task_ids db_tasks_to_hold = db_select(example_flow, True, 'tasks_to_hold') assert get_task_ids(db_tasks_to_hold) == expected_held_task_ids # Test release task_pool.release_hold_point() assert db_select(example_flow, True, 'workflow_params', key='holdcp') == [] for itask in task_pool.get_all_tasks(): assert itask.state.is_held is False assert task_pool.tasks_to_hold == set() assert db_select(example_flow, True, 'tasks_to_hold') == []
def test_multiple_exclusions_extensive(self): """Tests IntegerSequence methods for sequences with multi-exclusions""" points = [IntegerPoint(i) for i in range(10)] sequence = IntegerSequence('R/P1!(2,3,7)', 1, 10) self.assertFalse(sequence.is_on_sequence(points[3])) self.assertFalse(sequence.is_valid(points[3])) self.assertEqual(sequence.get_prev_point(points[3]), points[1]) self.assertEqual(sequence.get_prev_point(points[4]), points[1]) self.assertEqual(sequence.get_nearest_prev_point(points[3]), points[1]) self.assertEqual(sequence.get_nearest_prev_point(points[4]), points[1]) self.assertEqual(sequence.get_next_point(points[3]), points[4]) self.assertEqual(sequence.get_next_point(points[2]), points[4]) self.assertEqual(sequence.get_next_point_on_sequence( points[3]), points[4]) self.assertEqual(sequence.get_next_point_on_sequence( points[6]), points[8]) sequence = IntegerSequence('R/P1!(1,3,4)', 1, 10) self.assertEqual(sequence.get_first_point(points[1]), points[2]) self.assertEqual(sequence.get_first_point(points[0]), points[2]) self.assertEqual(sequence.get_start_point(), points[2]) sequence = IntegerSequence('R/P1!(8,9,10)', 1, 10) self.assertEqual(sequence.get_stop_point(), points[7])
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import pytest from pytest import param from typing import Callable, Optional from unittest.mock import Mock from cylc.flow.cycling import PointBase from cylc.flow.cycling.integer import IntegerPoint from cylc.flow.cycling.iso8601 import ISO8601Point from cylc.flow.task_proxy import TaskProxy @pytest.mark.parametrize('itask_point, point_str, expected', [ param(IntegerPoint(5), '5', True, id="Integer, basic"), param(IntegerPoint(5), '*', True, id="Integer, glob"), param(IntegerPoint(5), None, True, id="None same as glob(*)"), param(ISO8601Point('2012'), '2012-01-01', True, id="ISO, basic"), param(ISO8601Point('2012'), '2012*', True, id="ISO, glob"), param(ISO8601Point('2012'), '2012-*', False, id="ISO, bad glob (must use short datetime format)") ]) def test_point_match(itask_point: PointBase, point_str: Optional[str], expected: bool, set_cycling_type: Callable) -> None: """Test TaskProxy.point_match().""" set_cycling_type(itask_point.TYPE) mock_itask = Mock(point=itask_point.standardise())