Skip to content

Replace parser

Replace parser #18

GitHub Actions / Test Results failed Jan 29, 2024 in 0s

2 fail, 50 pass in 4s

  5 files  ±0    5 suites  ±0   4s ⏱️ -1s
 52 tests ±0   50 ✅ ±0  0 💤 ±0   2 ❌ ±0 
260 runs  ±0  250 ✅ ±0  0 💤 ±0  10 ❌ ±0 

Results for commit c04b0c8. ± Comparison against earlier commit ff18cf4.

Annotations

Check warning on line 0 in tests.test_parser.TestParser

See this annotation in the file changed.

@github-actions github-actions / Test Results

All 5 runs failed: test_opts (tests.test_parser.TestParser)

junit-3.10/test-results-3.10.xml [took 0s]
junit-3.11/test-results-3.11.xml [took 0s]
junit-3.12/test-results-3.12.xml [took 0s]
junit-3.8/test-results-3.8.xml [took 0s]
junit-3.9/test-results-3.9.xml [took 0s]
Raw output
troi.parse_prompt.ParseError: Option 'easy' is not allowed for element stats
self = <tests.test_parser.TestParser testMethod=test_opts>

    def test_opts(self):
        pp = PromptParser()
        r = pp.parse("stats:(mr_monkey)::month")
        print(r[0])
        assert r[0] == {"entity": "stats", "values": ["mr_monkey"], "weight": 1, "opts": ["month"]}
>       r = pp.parse("stats:(mr_monkey)::month,easy")

tests/test_parser.py:98: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <troi.parse_prompt.PromptParser object at 0x7f95ec866970>
prompt = 'stats:(mr_monkey)::month,easy'

    def parse(self, prompt):
        """Parse an actual LB-radio prompt and return a list of [name, [values], weight, [opts]]"""
    
        prompt = self.clean_spaces.sub(" ", prompt).strip()
        block = self.parse_special_cases(prompt)
        blocks = []
        while True:
            name = ""
            for element in ELEMENTS:
                if block.startswith(element + ":"):
                    name = element
                    break
            if not name:
                raise ParseError("Unknown element '%s'" % block)
    
            block = block[len(name):]
            if block[0] == ':':
                block = block[1:]
    
            opts = []
            weight = None
            values = None
            text = ""
            parens = 0
            escaped = False
            for i in range(len(block)):
                if not escaped and block[i] == '\\':
                    escaped = True
                    continue
    
                if escaped:
                    if block[i] in ('(', ')', '\\'):
                        escaped = False
                        text += block[i]
                        continue
                    escaped = False
    
                if block[i] == '(':
                    if i > 0:
                        raise ParseError("() must start at the beginning of the value field.")
                    parens += 1
                    continue
    
                if block[i] == ')':
                    parens -= 1
                    if parens < 0:
                        raise ParseError("closing ) without matching opening ( near: '%s'." % block[i:])
                    continue
    
                if block[i] == ':' and parens == 0:
                    values, weight, opts = self.set_block_values(name, values, weight, opts, text, block)
                    text = ""
                    continue
    
                if block[i] == ' ' and parens == 0:
                    break
    
                text += block[i]
    
            # Now that we've parsed a block, do some sanity checking
            values, weight, opts = self.set_block_values(name, values, weight, opts, text, block)
            try:
                block = block[i + 1:]
            except UnboundLocalError:
                raise ParseError("incomplete prompt")
    
            if parens > 0:
                raise ParseError("Missing closing ).")
    
            if parens < 0:
                raise ParseError("Missing opening (.")
    
            for opt in opts:
                if opt not in ELEMENT_OPTIONS[name]:
>                   raise ParseError("Option '%s' is not allowed for element %s" % (opt, name))
E                   troi.parse_prompt.ParseError: Option 'easy' is not allowed for element stats

troi/parse_prompt.py:165: ParseError

Check warning on line 0 in tests.test_parser.TestParser

See this annotation in the file changed.

@github-actions github-actions / Test Results

All 5 runs failed: test_stats (tests.test_parser.TestParser)

junit-3.10/test-results-3.10.xml [took 0s]
junit-3.11/test-results-3.11.xml [took 0s]
junit-3.12/test-results-3.12.xml [took 0s]
junit-3.8/test-results-3.8.xml [took 0s]
junit-3.9/test-results-3.9.xml [took 0s]
Raw output
troi.parse_prompt.ParseError: Option 'nosim' is not allowed for element stats
self = <tests.test_parser.TestParser testMethod=test_stats>

    def test_stats(self):
        pp = PromptParser()
        r = pp.parse("stats:mr_monkey:1:year")
        assert r[0] == {"entity": "stats", "values": ["mr_monkey"], "weight": 1, "opts": ["year"]}
    
        r = pp.parse("stats:rob:1:week")
        assert r[0] == {"entity": "stats", "values": ["rob"], "weight": 1, "opts": ["week"]}
    
>       r = pp.parse("stats:(mr_monkey)::month,nosim")

tests/test_parser.py:128: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <troi.parse_prompt.PromptParser object at 0x7f95ec6cdd00>
prompt = 'stats:(mr_monkey)::month,nosim'

    def parse(self, prompt):
        """Parse an actual LB-radio prompt and return a list of [name, [values], weight, [opts]]"""
    
        prompt = self.clean_spaces.sub(" ", prompt).strip()
        block = self.parse_special_cases(prompt)
        blocks = []
        while True:
            name = ""
            for element in ELEMENTS:
                if block.startswith(element + ":"):
                    name = element
                    break
            if not name:
                raise ParseError("Unknown element '%s'" % block)
    
            block = block[len(name):]
            if block[0] == ':':
                block = block[1:]
    
            opts = []
            weight = None
            values = None
            text = ""
            parens = 0
            escaped = False
            for i in range(len(block)):
                if not escaped and block[i] == '\\':
                    escaped = True
                    continue
    
                if escaped:
                    if block[i] in ('(', ')', '\\'):
                        escaped = False
                        text += block[i]
                        continue
                    escaped = False
    
                if block[i] == '(':
                    if i > 0:
                        raise ParseError("() must start at the beginning of the value field.")
                    parens += 1
                    continue
    
                if block[i] == ')':
                    parens -= 1
                    if parens < 0:
                        raise ParseError("closing ) without matching opening ( near: '%s'." % block[i:])
                    continue
    
                if block[i] == ':' and parens == 0:
                    values, weight, opts = self.set_block_values(name, values, weight, opts, text, block)
                    text = ""
                    continue
    
                if block[i] == ' ' and parens == 0:
                    break
    
                text += block[i]
    
            # Now that we've parsed a block, do some sanity checking
            values, weight, opts = self.set_block_values(name, values, weight, opts, text, block)
            try:
                block = block[i + 1:]
            except UnboundLocalError:
                raise ParseError("incomplete prompt")
    
            if parens > 0:
                raise ParseError("Missing closing ).")
    
            if parens < 0:
                raise ParseError("Missing opening (.")
    
            for opt in opts:
                if opt not in ELEMENT_OPTIONS[name]:
>                   raise ParseError("Option '%s' is not allowed for element %s" % (opt, name))
E                   troi.parse_prompt.ParseError: Option 'nosim' is not allowed for element stats

troi/parse_prompt.py:165: ParseError