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)
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
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'])
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'])
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'])
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'])
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'])
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'])
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'])
def test_type_help_examples(): types = {**ParsecValidator.V_TYPE_HELP, **VDR.V_TYPE_HELP} validator = VDR() for vdr, info in types.items(): coercer = validator.coercers[vdr] if len(info) > 2: for example in info[2]: try: coercer(example, [None]) except Exception: raise Exception( f'Example "{example}" failed for type "{vdr}"')
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'])
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'])
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'])
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'])
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'])
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'])