本文整理汇总了Python中st2common.models.utils.action_alias_utils.ActionAliasFormatParser类的典型用法代码示例。如果您正苦于以下问题:Python ActionAliasFormatParser类的具体用法?Python ActionAliasFormatParser怎么用?Python ActionAliasFormatParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ActionAliasFormatParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_param_spaces
def test_param_spaces(self):
alias_format = 's {{a}} more {{ b }} more {{ c=99 }} more {{ d = 99 }}'
param_stream = 's one more two more three more'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'one', 'b': 'two',
'c': 'three', 'd': '99'})
示例2: test_mixed_parsing
def test_mixed_parsing(self):
alias_format = 'skip {{a}} more skip {{b}}.'
param_stream = 'skip {"a": "b", "c": "d"} more skip x.'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': '{"a": "b", "c": "d"}',
'b': 'x'})
示例3: test_default_values
def test_default_values(self):
alias_format = 'acl {{a}} {{b}} {{c}} {{d=1}}'
param_stream = 'acl "a1 a2" "b1" "c1"'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'a1 a2', 'b': 'b1',
'c': 'c1', 'd': '1'})
示例4: test_regex_beginning_and_ending_anchors_dont_match
def test_regex_beginning_and_ending_anchors_dont_match(self):
alias_format = r'^\s*foo (?P<issue_key>[A-Z][A-Z0-9]+-[0-9]+)\s*$'
param_stream = 'bar ASDF-1234'
parser = ActionAliasFormatParser(alias_format, param_stream)
expected_msg = r'''Command "bar ASDF-1234" doesn't match format string '''\
r'''"^\s*foo (?P<issue_key>[A-Z][A-Z0-9]+-[0-9]+)\s*$"'''
with self.assertRaises(ParseException) as e:
parser.get_extracted_param_value()
self.assertEqual(e.msg, expected_msg)
示例5: test_all_the_things
def test_all_the_things(self):
# this is the most insane example I could come up with
alias_format = "{{ p0='http' }} g {{ p1=p }} a " + \
"{{ url }} {{ p2={'a':'b'} }} {{ p3={{ e.i }} }}"
param_stream = "g a http://google.com {{ execution.id }} p4='testing' p5={'a':'c'}"
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'p0': 'http', 'p1': 'p',
'url': 'http://google.com',
'p2': '{{ execution.id }}',
'p3': '{{ e.i }}',
'p4': 'testing', 'p5': "{'a':'c'}"})
示例6: test_enclosed_defaults
def test_enclosed_defaults(self):
alias_format = 'skip {{ a = value }} more'
param_stream = 'skip one more'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'one'})
alias_format = 'skip {{ a = value }} more'
param_stream = 'skip more'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'value'})
示例7: test_key_value_combinations
def test_key_value_combinations(self):
# one-word value, single extra pair
alias_format = 'testing {{ a }}'
param_stream = 'testing value b=value2'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'value',
'b': 'value2'})
# default value, single extra pair with quotes
alias_format = 'testing {{ a=new }}'
param_stream = 'testing b="another value"'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'new',
'b': 'another value'})
# multiple values and multiple extra pairs
alias_format = 'testing {{ b=abc }} {{ c=xyz }}'
param_stream = 'testing newvalue d={"1": "2"} e="long value"'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'b': 'newvalue',
'c': 'xyz',
'd': '{"1": "2"}',
'e': 'long value'})
示例8: test_end_string_parsing
def test_end_string_parsing(self):
alias_format = 'skip {{a}} more skip {{b}}'
param_stream = 'skip a1 more skip b1'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'a1', 'b': 'b1'})
示例9: test_arbitrary_pairs
def test_arbitrary_pairs(self):
# single-word param
alias_format = ''
param_stream = 'a=foobar1'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar1'})
# multi-word double-quoted param
alias_format = 'foo'
param_stream = 'foo a="foobar2 poonies bar"'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar2 poonies bar'})
# multi-word single-quoted param
alias_format = 'foo'
param_stream = 'foo a=\'foobar2 poonies bar\''
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar2 poonies bar'})
# JSON param
alias_format = 'foo'
param_stream = 'foo a={"foobar2": "poonies"}'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': '{"foobar2": "poonies"}'})
# Multiple mixed params
alias_format = ''
param_stream = 'a=foobar1 b="boobar2 3 4" c=\'coobar3 4\' d={"a": "b"}'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar1',
'b': 'boobar2 3 4',
'c': 'coobar3 4',
'd': '{"a": "b"}'})
# Params along with a "normal" alias format
alias_format = '{{ captain }} is my captain'
param_stream = 'Malcolm Reynolds is my captain weirdo="River Tam"'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'captain': 'Malcolm Reynolds',
'weirdo': 'River Tam'})
示例10: test_ending_parameters_matching
def test_ending_parameters_matching(self):
alias_format = 'foo bar'
param_stream = 'foo bar pony1=foo pony2=bar'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'pony1': 'foo', 'pony2': 'bar'})
示例11: test_empty_string
def test_empty_string(self):
alias_format = ''
param_stream = ''
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {})
示例12: test_stream_is_not_none_some_default_values
def test_stream_is_not_none_some_default_values(self):
alias_format = 'skip {{d=test}} more skip {{e=test}}'
param_stream = 'skip ponies more skip'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'d': 'ponies', 'e': 'test'})
示例13: test_template_defaults
def test_template_defaults(self):
alias_format = 'two by two hands of {{ color = {{ colors.default_color }} }}'
param_stream = 'two by two hands of'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'color': '{{ colors.default_color }}'})
示例14: test_spacing
def test_spacing(self):
alias_format = 'acl {{a=test}}'
param_stream = 'acl'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'test'})
示例15: test_default_key_value_param_parsing
def test_default_key_value_param_parsing(self):
# Empty string
alias_format = ''
param_stream = ''
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {})
# 1 key value pair provided in the param stream
alias_format = ''
param_stream = 'a=foobar1'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar1'})
alias_format = ''
param_stream = 'foo a=foobar2 poonies bar'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar2'})
# Multiple params provided
alias_format = ''
param_stream = 'a=foobar1 b=boobar2 c=coobar3'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar1', 'b': 'boobar2', 'c': 'coobar3'})
# Multiple params provided
alias_format = ''
param_stream = 'a=foobar4 b=boobar5 c=coobar6'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar4', 'b': 'boobar5', 'c': 'coobar6'})
# Multiple params provided
alias_format = ''
param_stream = 'mixed a=foobar1 some more b=boobar2 text c=coobar3 yeah'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar1', 'b': 'boobar2', 'c': 'coobar3'})
# Param with quotes, make sure they are stripped
alias_format = ''
param_stream = 'mixed a="foobar1"'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar1'})
# Param with quotes, make sure they are stripped
alias_format = ''
param_stream = 'mixed a="foobar test" ponies a'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar test'})
# Param with quotes, make sure they are stripped
alias_format = ''
param_stream = "mixed a='foobar1 ponies' test"
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar1 ponies'})
# Param with quotes, make sure they are stripped
alias_format = ''
param_stream = 'mixed a="foobar1"'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar1'})
# Mixed format and kv params
alias_format = 'somestuff {{a}} more stuff {{b}}'
param_stream = 'somestuff a=foobar more stuff coobar'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'foobar', 'b': 'coobar'})
alias_format = 'somestuff {{a}} more stuff {{b}}'
param_stream = 'somestuff ponies more stuff coobar'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'ponies', 'b': 'coobar'})
alias_format = 'somestuff {{a}} more stuff {{b}}'
param_stream = 'somestuff ponies more stuff coobar b=foo'
parser = ActionAliasFormatParser(alias_format, param_stream)
extracted_values = parser.get_extracted_param_value()
self.assertEqual(extracted_values, {'a': 'ponies', 'b': 'foo'})