Example #1
0
 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'})
 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 }}'})
Example #3
0
 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'})
Example #4
0
 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'})
Example #5
0
 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'})
Example #6
0
 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'})
Example #7
0
 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'})
Example #8
0
    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"
            },
        )
    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'
        })
Example #10
0
 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"
     })
Example #11
0
    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)
Example #12
0
 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"
     })
Example #13
0
    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)
Example #14
0
 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'}"})
Example #15
0
    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'})
Example #16
0
 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'}"})
Example #17
0
    def test_regex_ending_anchors_dont_match(self):
        alias_format = r"foo (?P<issue_key>[A-Z][A-Z0-9]+-[0-9]+)\s*$"
        param_stream = "foo ASDF-1234 bar"
        parser = ActionAliasFormatParser(alias_format, param_stream)

        expected_msg = (
            r"""Command "foo ASDF-1234 bar" doesn't match format string """
            r'''"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)
Example #18
0
    def test_stream_is_none_no_default_values(self):
        alias_format = 'skip {{d}} more skip {{e}}.'
        param_stream = None
        parser = ActionAliasFormatParser(alias_format, param_stream)

        expected_msg = 'No value supplied and no default value found.'
        self.assertRaisesRegexp(ParseException, expected_msg,
                                parser.get_extracted_param_value)
    def test_stream_is_none_no_default_values(self):
        alias_format = 'skip {{d}} more skip {{e}}.'
        param_stream = None
        parser = ActionAliasFormatParser(alias_format, param_stream)

        expected_msg = 'Command "" doesn\'t match format string "skip {{d}} more skip {{e}}."'
        self.assertRaisesRegexp(ParseException, expected_msg,
                                parser.get_extracted_param_value)
    def test_command_doesnt_match_format_string(self):
        alias_format = 'foo bar ponies'
        param_stream = 'foo lulz ponies'
        parser = ActionAliasFormatParser(alias_format, param_stream)

        expected_msg = 'Command "foo lulz ponies" doesn\'t match format string "foo bar ponies"'
        self.assertRaisesRegexp(ParseException, expected_msg,
                                parser.get_extracted_param_value)
Example #21
0
 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'}",
         },
     )
Example #22
0
    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'})
    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'})
Example #24
0
    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"})
Example #25
0
 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'})
Example #26
0
    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'})
Example #27
0
 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, {})
Example #28
0
 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'})
Example #29
0
 def test_regex_ending_anchors(self):
     alias_format = r"foo (?P<issue_key>[A-Z][A-Z0-9]+-[0-9]+)\s*$"
     param_stream = "foo ASDF-1234"
     parser = ActionAliasFormatParser(alias_format, param_stream)
     extracted_values = parser.get_extracted_param_value()
     self.assertEqual(extracted_values, {"issue_key": "ASDF-1234"})
Example #30
0
    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"
        })
 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, {})
Example #32
0
 def test_regex_beginning_and_ending_anchors(self):
     alias_format = r'^\s*foo (?P<issue_key>[A-Z][A-Z0-9]+-[0-9]+) bar\s*$'
     param_stream = 'foo ASDF-1234 bar'
     parser = ActionAliasFormatParser(alias_format, param_stream)
     extracted_values = parser.get_extracted_param_value()
     self.assertEqual(extracted_values, {'issue_key': 'ASDF-1234'})
Example #33
0
 def test_spaced_parsing(self):
     alias_format = 'skip {{a}} more skip {{b}} and skip more.'
     param_stream = 'skip "a1 a2" more skip b1 and skip more.'
     parser = ActionAliasFormatParser(alias_format, param_stream)
     extracted_values = parser.get_extracted_param_value()
     self.assertEqual(extracted_values, {'a': 'a1 a2', 'b': 'b1'})
Example #34
0
    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'})
Example #35
0
 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"})
 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'})
Example #37
0
 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 }}'})
    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'
        })
Example #39
0
 def test_stream_is_none_with_all_default_values(self):
     alias_format = 'skip {{d=test1}} more skip {{e=test1}}.'
     param_stream = 'skip more skip'
     parser = ActionAliasFormatParser(alias_format, param_stream)
     extracted_values = parser.get_extracted_param_value()
     self.assertEqual(extracted_values, {'d': 'test1', 'e': 'test1'})
 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'})
Example #41
0
 def test_simple_parsing(self):
     alias_format = "skip {{a}} more skip {{b}} and skip more."
     param_stream = "skip a1 more skip b1 and skip more."
     parser = ActionAliasFormatParser(alias_format, param_stream)
     extracted_values = parser.get_extracted_param_value()
     self.assertEqual(extracted_values, {"a": "a1", "b": "b1"})
 def test_spaced_parsing(self):
     alias_format = 'skip {{a}} more skip {{b}} and skip more.'
     param_stream = 'skip "a1 a2" more skip b1 and skip more.'
     parser = ActionAliasFormatParser(alias_format, param_stream)
     extracted_values = parser.get_extracted_param_value()
     self.assertEqual(extracted_values, {'a': 'a1 a2', 'b': 'b1'})
Example #43
0
 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'})
 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'})
Example #45
0
 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'})
 def test_stream_is_none_with_all_default_values(self):
     alias_format = 'skip {{d=test1}} more skip {{e=test1}}.'
     param_stream = 'skip more skip'
     parser = ActionAliasFormatParser(alias_format, param_stream)
     extracted_values = parser.get_extracted_param_value()
     self.assertEqual(extracted_values, {'d': 'test1', 'e': 'test1'})
 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'})
Example #48
0
 def test_regex_beginning_and_ending_anchors(self):
     alias_format = r'^\s*foo (?P<issue_key>[A-Z][A-Z0-9]+-[0-9]+) bar\s*$'
     param_stream = 'foo ASDF-1234 bar'
     parser = ActionAliasFormatParser(alias_format, param_stream)
     extracted_values = parser.get_extracted_param_value()
     self.assertEqual(extracted_values, {'issue_key': 'ASDF-1234'})