How to use _match_string method in lisa

Best Python code snippet using lisa_python

expectations_parser.py

Source:expectations_parser.py Github

copy

Full Screen

1# Copyright 2017 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import re5class ParseError(Exception):6 pass7class Expectation(object):8 def __init__(self, reason, test, conditions, results):9 """Constructor for expectations.10 Args:11 reason: String that indicates the reason for disabling.12 test: String indicating which test is being disabled.13 conditions: List of tags indicating which conditions to disable for.14 Conditions are combined using logical and. Example: ['Mac', 'Debug']15 results: List of outcomes for test. Example: ['Skip', 'Pass']16 """17 assert isinstance(reason, basestring) or reason is None18 self._reason = reason19 assert isinstance(test, basestring)20 self._test = test21 assert isinstance(conditions, list)22 self._conditions = conditions23 assert isinstance(results, list)24 self._results = results25 def __eq__(self, other):26 return (self.reason == other.reason and27 self.test == other.test and28 self.conditions == other.conditions and29 self.results == other.results)30 @property31 def reason(self):32 return self._reason33 @property34 def test(self):35 return self._test36 @property37 def conditions(self):38 return self._conditions39 @property40 def results(self):41 return self._results42class TestExpectationParser(object):43 """Parse expectations data in TA/DA format.44 This parser covers the 'tagged' test lists format in:45 bit.ly/chromium-test-list-format46 Takes raw expectations data as a string read from the TA/DA expectation file47 in the format:48 # This is an example expectation file.49 #50 # tags: Mac Mac10.10 Mac10.1151 # tags: Win Win852 crbug.com/123 [ Win ] benchmark/story [ Skip ]53 ...54 """55 TAG_TOKEN = '# tags:'56 _MATCH_STRING = r'^(?:(crbug.com/\d+) )?' # The bug field (optional).57 _MATCH_STRING += r'(?:\[ (.+) \] )?' # The label field (optional).58 _MATCH_STRING += r'(\S+) ' # The test path field.59 _MATCH_STRING += r'\[ ([^\[.]+) \]' # The expectation field.60 _MATCH_STRING += r'(\s+#.*)?$' # End comment (optional).61 MATCHER = re.compile(_MATCH_STRING)62 def __init__(self, raw_data):63 self._tags = []64 self._expectations = []65 self._ParseRawExpectationData(raw_data)66 def _ParseRawExpectationData(self, raw_data):67 for count, line in list(enumerate(raw_data.splitlines(), start=1)):68 # Handle metadata and comments.69 if line.startswith(self.TAG_TOKEN):70 for word in line[len(self.TAG_TOKEN):].split():71 # Expectations must be after all tags are declared.72 if self._expectations:73 raise ParseError('Tag found after first expectation.')74 self._tags.append(word)75 elif line.startswith('#') or not line:76 continue # Ignore, it is just a comment or empty.77 else:78 self._expectations.append(79 self._ParseExpectationLine(count, line, self._tags))80 def _ParseExpectationLine(self, line_number, line, tags):81 match = self.MATCHER.match(line)82 if not match:83 raise ParseError(84 'Expectation has invalid syntax on line %d: %s'85 % (line_number, line))86 # Unused group is optional trailing comment.87 reason, raw_conditions, test, results, _ = match.groups()88 conditions = [c for c in raw_conditions.split()] if raw_conditions else []89 for c in conditions:90 if c not in tags:91 raise ParseError(92 'Condition %s not found in expectations tag data. Line %d'93 % (c, line_number))94 return Expectation(reason, test, conditions, [r for r in results.split()])95 @property96 def expectations(self):97 return self._expectations98 @property99 def tags(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful