Пример #1
0
def test_strip_and_unquote_list_cylc(strip_and_unquote_list):
    """Test strip_and_unquote_list using CylcConfigValidator."""
    validator = VDR()
    for values in strip_and_unquote_list:
        value = values[0]
        expected = values[1]
        output = validator.strip_and_unquote_list(keys=[], value=value)
        assert expected == output
Пример #2
0
 def test_strip_and_unquote_list_cylc(self):
     """Test strip_and_unquote_list using CylcConfigValidator."""
     validator = VDR()
     for values in get_test_strip_and_unquote_list():
         value = values[0]
         expected = values[1]
         output = validator.strip_and_unquote_list(keys=[], value=value)
         self.assertEqual(expected, output)
Пример #3
0
def test_coerce_interval():
    """Test coerce_interval."""
    validator = VDR()
    # The good
    for value, result in [('', None), ('P3D', DurationFloat(259200)),
                          ('PT10M10S', DurationFloat(610))]:
        assert validator.coerce_interval(value, ['whatever']) == result
    # The bad
    for value in ['None', '5 days', '20', '-12']:
        with pytest.raises(IllegalValueError):
            validator.coerce_interval(value, ['whatever'])
Пример #4
0
 def test_coerce_interval(self):
     """Test coerce_interval."""
     validator = VDR()
     # The good
     for value, result in [('', None), ('P3D', DurationFloat(259200)),
                           ('PT10M10S', DurationFloat(610))]:
         self.assertEqual(validator.coerce_interval(value, ['whatever']),
                          result)
     # The bad
     for value in ['None', '5 days', '20', '-12']:
         self.assertRaises(IllegalValueError, validator.coerce_interval,
                           value, ['whatever'])
Пример #5
0
def test_coerce_xtrigger():
    """Test coerce_xtrigger."""
    validator = VDR()
    # The good
    for value, result in [('foo(x="bar")', 'foo(x=bar)'),
                          ('foo(x, y, z="zebra")', 'foo(x, y, z=zebra)')]:
        assert (validator.coerce_xtrigger(
            value, ['whatever']).get_signature() == result)
    # The bad
    for value in ['', 'foo(', 'foo)', 'foo,bar']:
        with pytest.raises(IllegalValueError):
            validator.coerce_xtrigger(value, ['whatever'])
Пример #6
0
def test_coerce_cycle_point():
    """Test coerce_cycle_point."""
    validator = VDR()
    # The good
    for value, result in [('', None), ('3', '3'), ('2018', '2018'),
                          ('20181225T12Z', '20181225T12Z'),
                          ('2018-12-25T12:00+11:00', '2018-12-25T12:00+11:00')
                          ]:
        assert validator.coerce_cycle_point(value, ['whatever']) == result
    # The bad
    for value in ['None', ' Who cares? ', 'True', '1, 2', '20781340E10']:
        with pytest.raises(IllegalValueError):
            validator.coerce_cycle_point(value, ['whatever'])
Пример #7
0
 def test_coerce_xtrigger(self):
     """Test coerce_xtrigger."""
     validator = VDR()
     # The good
     for value, result in [('foo(x="bar")', 'foo(x=bar)'),
                           ('foo(x, y, z="zebra")', 'foo(x, y, z=zebra)')]:
         self.assertEqual(
             validator.coerce_xtrigger(value, ['whatever']).get_signature(),
             result)
     # The bad
     for value in ['', 'foo(', 'foo)', 'foo,bar']:
         self.assertRaises(IllegalValueError, validator.coerce_xtrigger,
                           value, ['whatever'])
Пример #8
0
def test_coerce_cycle_point_format():
    """Test coerce_cycle_point_format."""
    validator = VDR()
    # The good
    for value, result in [('', None), ('%Y%m%dT%H%M%z', '%Y%m%dT%H%M%z'),
                          ('CCYYMMDDThhmmZ', 'CCYYMMDDThhmmZ'),
                          ('XCCYYMMDDThhmmZ', 'XCCYYMMDDThhmmZ')]:
        assert (validator.coerce_cycle_point_format(value,
                                                    ['whatever']) == result)
    # The bad
    for value in ['%i%j', 'Y/M/D']:
        with pytest.raises(IllegalValueError):
            validator.coerce_cycle_point_format(value, ['whatever'])
Пример #9
0
def test_coerce_cycle_point_time_zone():
    """Test coerce_cycle_point_time_zone."""
    validator = VDR()
    # The good
    for value, result in [('', None), ('Z', 'Z'), ('+0000', '+0000'),
                          ('+0100', '+0100'), ('+1300', '+1300'),
                          ('-0630', '-0630')]:
        assert (validator.coerce_cycle_point_time_zone(value,
                                                       ['whatever']) == result)
    # The bad
    for value in ['None', 'Big Bang Time', 'Standard Galaxy Time']:
        with pytest.raises(IllegalValueError):
            validator.coerce_cycle_point_time_zone(value, ['whatever'])
Пример #10
0
 def test_coerce_cycle_point(self):
     """Test coerce_cycle_point."""
     validator = VDR()
     # The good
     for value, result in [('', None), ('3', '3'), ('2018', '2018'),
                           ('20181225T12Z', '20181225T12Z'),
                           ('2018-12-25T12:00+11:00',
                            '2018-12-25T12:00+11:00')]:
         self.assertEqual(validator.coerce_cycle_point(value, ['whatever']),
                          result)
     # The bad
     for value in ['None', ' Who cares? ', 'True', '1, 2', '20781340E10']:
         self.assertRaises(IllegalValueError, validator.coerce_cycle_point,
                           value, ['whatever'])
Пример #11
0
def test_coerce_cycle_point_format():
    """Test coerce_cycle_point_format."""
    validator = VDR()
    # The good
    for value, result in [('', None), ('%Y%m%dT%H%M%z', '%Y%m%dT%H%M%z'),
                          ('CCYYMMDDThhmmZ', 'CCYYMMDDThhmmZ'),
                          ('XCCYYMMDDThhmmZ', 'XCCYYMMDDThhmmZ')]:
        assert (validator.coerce_cycle_point_format(value,
                                                    ['whatever']) == result)
    # The bad
    # '/' and ':' not allowed in cylc cycle points (they are used in paths).
    for value in ['%i%j', 'Y/M/D', '%Y-%m-%dT%H:%MZ']:
        with pytest.raises(IllegalValueError):
            validator.coerce_cycle_point_format(value, ['whatever'])
Пример #12
0
def test_coerce_parameter_list():
    """Test coerce_parameter_list."""
    validator = VDR()
    # The good
    for value, result in [
        ('', []), ('planet', ['planet']),
        ('planet, star, galaxy', ['planet', 'star', 'galaxy']),
        ('1..5, 21..25', [1, 2, 3, 4, 5, 21, 22, 23, 24, 25]),
        ('-15, -10, -5, -1..1', [-15, -10, -5, -1, 0, 1])
    ]:
        assert validator.coerce_parameter_list(value, ['whatever']) == result
    # The bad
    for value in ['foo/bar', 'p1, 1..10', '2..3, 4, p']:
        with pytest.raises(IllegalValueError):
            validator.coerce_parameter_list(value, ['whatever'])
Пример #13
0
 def test_coerce_cycle_point_format(self):
     """Test coerce_cycle_point_format."""
     validator = VDR()
     # The good
     for value, result in [('', None), ('%Y%m%dT%H%M%z', '%Y%m%dT%H%M%z'),
                           ('CCYYMMDDThhmmZ', 'CCYYMMDDThhmmZ'),
                           ('XCCYYMMDDThhmmZ', 'XCCYYMMDDThhmmZ')]:
         self.assertEqual(
             validator.coerce_cycle_point_format(value, ['whatever']),
             result)
     # The bad
     for value in ['%i%j', 'Y/M/D']:
         self.assertRaises(IllegalValueError,
                           validator.coerce_cycle_point_format, value,
                           ['whatever'])
Пример #14
0
 def test_coerce_interval(self):
     """Test coerce_interval."""
     validator = VDR()
     # The good
     for value, result in [
             ('', None),
             ('P3D', DurationFloat(259200)),
             ('PT10M10S', DurationFloat(610))]:
         self.assertEqual(
             validator.coerce_interval(value, ['whatever']), result)
     # The bad
     for value in ['None', '5 days', '20', '-12']:
         self.assertRaises(
             IllegalValueError,
             validator.coerce_interval, value, ['whatever'])
Пример #15
0
 def test_coerce_cycle_point_time_zone(self):
     """Test coerce_cycle_point_time_zone."""
     validator = VDR()
     # The good
     for value, result in [('', None), ('Z', 'Z'), ('+0000', '+0000'),
                           ('+0100', '+0100'), ('+1300', '+1300'),
                           ('-0630', '-0630')]:
         self.assertEqual(
             validator.coerce_cycle_point_time_zone(value, ['whatever']),
             result)
     # The bad
     for value in ['None', 'Big Bang Time', 'Standard Galaxy Time']:
         self.assertRaises(IllegalValueError,
                           validator.coerce_cycle_point_time_zone, value,
                           ['whatever'])
Пример #16
0
 def test_coerce_xtrigger(self):
     """Test coerce_xtrigger."""
     validator = VDR()
     # The good
     for value, result in [
             ('foo(x="bar")', 'foo(x=bar)'),
             ('foo(x, y, z="zebra")', 'foo(x, y, z=zebra)')]:
         self.assertEqual(
             validator.coerce_xtrigger(value, ['whatever']).get_signature(),
             result)
     # The bad
     for value in [
             '', 'foo(', 'foo)', 'foo,bar']:
         self.assertRaises(
             IllegalValueError,
             validator.coerce_xtrigger, value, ['whatever'])
Пример #17
0
 def test_coerce_cycle_point_format(self):
     """Test coerce_cycle_point_format."""
     validator = VDR()
     # The good
     for value, result in [
             ('', None),
             ('%Y%m%dT%H%M%z', '%Y%m%dT%H%M%z'),
             ('CCYYMMDDThhmmZ', 'CCYYMMDDThhmmZ'),
             ('XCCYYMMDDThhmmZ', 'XCCYYMMDDThhmmZ')]:
         self.assertEqual(
             validator.coerce_cycle_point_format(value, ['whatever']),
             result)
     # The bad
     for value in ['%i%j', 'Y/M/D']:
         self.assertRaises(
             IllegalValueError,
             validator.coerce_cycle_point_format, value, ['whatever'])
Пример #18
0
def test_coerce_interval_list():
    """Test coerce_interval_list."""
    validator = VDR()
    # The good
    for value, results in [
            ('', []),
            ('P3D', [DurationFloat(259200)]),
            ('P3D, PT10M10S', [DurationFloat(259200), DurationFloat(610)]),
            ('25*PT30M,10*PT1H',
             [DurationFloat(1800)] * 25 + [DurationFloat(3600)] * 10)]:
        items = validator.coerce_interval_list(value, ['whatever'])
        for item, result in zip(items, results):
            assert pytest.approx(item, result)
    # The bad
    for value in ['None', '5 days', '20', 'PT10S, -12']:
        with pytest.raises(IllegalValueError):
            validator.coerce_interval_list(value, ['whatever'])
Пример #19
0
 def test_coerce_parameter_list(self):
     """Test coerce_parameter_list."""
     validator = VDR()
     # The good
     for value, result in [
             ('', []),
             ('planet', ['planet']),
             ('planet, star, galaxy', ['planet', 'star', 'galaxy']),
             ('1..5, 21..25', [1, 2, 3, 4, 5, 21, 22, 23, 24, 25]),
             ('-15, -10, -5, -1..1', [-15, -10, -5, -1, 0, 1])]:
         self.assertEqual(
             validator.coerce_parameter_list(value, ['whatever']), result)
     # The bad
     for value in ['foo/bar', 'p1, 1..10', '2..3, 4, p']:
         self.assertRaises(
             IllegalValueError,
             validator.coerce_parameter_list, value, ['whatever'])
Пример #20
0
 def test_coerce_interval_list(self):
     """Test coerce_interval_list."""
     validator = VDR()
     # The good
     for value, results in [
             ('', []),
             ('P3D', [DurationFloat(259200)]),
             ('P3D, PT10M10S', [DurationFloat(259200), DurationFloat(610)]),
             ('25*PT30M,10*PT1H',
              [DurationFloat(1800)] * 25 + [DurationFloat(3600)] * 10)]:
         items = validator.coerce_interval_list(value, ['whatever'])
         for item, result in zip(items, results):
             self.assertAlmostEqual(item, result)
     # The bad
     for value in ['None', '5 days', '20', 'PT10S, -12']:
         self.assertRaises(
             IllegalValueError,
             validator.coerce_interval_list, value, ['whatever'])
Пример #21
0
 def test_coerce_cycle_point(self):
     """Test coerce_cycle_point."""
     validator = VDR()
     # The good
     for value, result in [
             ('', None),
             ('3', '3'),
             ('2018', '2018'),
             ('20181225T12Z', '20181225T12Z'),
             ('2018-12-25T12:00+11:00', '2018-12-25T12:00+11:00')]:
         self.assertEqual(
             validator.coerce_cycle_point(value, ['whatever']), result)
     # The bad
     for value in [
             'None', ' Who cares? ', 'True', '1, 2', '20781340E10']:
         self.assertRaises(
             IllegalValueError,
             validator.coerce_cycle_point, value, ['whatever'])
Пример #22
0
 def test_coerce_cycle_point_time_zone(self):
     """Test coerce_cycle_point_time_zone."""
     validator = VDR()
     # The good
     for value, result in [
             ('', None),
             ('Z', 'Z'),
             ('+0000', '+0000'),
             ('+0100', '+0100'),
             ('+1300', '+1300'),
             ('-0630', '-0630')]:
         self.assertEqual(
             validator.coerce_cycle_point_time_zone(value, ['whatever']),
             result)
     # The bad
     for value in ['None', 'Big Bang Time', 'Standard Galaxy Time']:
         self.assertRaises(
             IllegalValueError,
             validator.coerce_cycle_point_time_zone, value, ['whatever'])
Пример #23
0
def test_coerce_interval_list__bad(value: str):
    with pytest.raises(IllegalValueError):
        VDR.coerce_interval_list(value, ['whatever'])
Пример #24
0
def test_coerce_interval_list(value: str, expected: List[DurationFloat]):
    """Test coerce_interval_list."""
    assert VDR.coerce_interval_list(value, ['whatever']) == approx(expected)