From 8684c8a9adc89c618545bd9232612ecdf9a95a3e Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: May 09 2020 00:27:40 +0000 Subject: result.py: pylint cleanups Includes ditching the TestInstance abstraction layer again, since I kinda gave up on supporting QATracker or any other system here. Signed-off-by: Adam Williamson --- diff --git a/src/wikitcms/result.py b/src/wikitcms/result.py index ea71b17..2e3bb40 100644 --- a/src/wikitcms/result.py +++ b/src/wikitcms/result.py @@ -113,6 +113,9 @@ def find_resultrows(text, section='', secid=0, statuses=None, transferred=True): the way through ResultRow to find_results() and behave as described there, for the Result objects in each ResultRow. """ + # oh shut up pylint what do you have against variables + # pylint: disable=too-many-locals + # identify all test case names, including old ones. modern ones # match QA:Testcase.*, but older ones sometimes have QA/TestCase. testcase_pattern = re.compile(r'(QA[:/]Test.+?)[\|\]\n]') @@ -172,7 +175,7 @@ def find_resultrows(text, section='', secid=0, statuses=None, transferred=True): return resultrows -class Result(object): +class Result(): """A class that represents a single test result. Note that a 'none' result, as you get if you just instantiate this class without arguments, is a thing, at least for wikitcms; when text @@ -185,16 +188,17 @@ class Result(object): Methods that parse existing results will use one of the class methods that returns a Result() with the appropriate attributes. - When one of those parsers produces an instance it will set the - attribute origtext to record the exact string parsed to produce - the instance. + When one of those parsers produces an instance it will pass + origtext to record the exact string parsed to produce the instance; + otherwise origtext should be left blank. transferred, if True, indicates the result is of the "previous (compose) run" type that is used to indicate where we think a result from a previous compose is valid for a later one. """ - def __init__( - self, status=None, user=None, bugs=None, comment='', bot=False): + # pylint: disable=too-many-instance-attributes + def __init__(self, status=None, user=None, bugs=None, comment='', bot=False, origtext=""): + # pylint: disable=too-many-arguments self.status = status self.user = user self.bugs = bugs @@ -204,6 +208,7 @@ class Result(object): self.bot = bot self.transferred = False self.comment_bugs = helpers.find_bugs(self.comment) + self.origtext = origtext def __str__(self): if not self.status: @@ -266,6 +271,7 @@ class Result(object): we need to find them and extract them first. We record the comment exactly as is. """ + # pylint: disable=too-many-locals template, comment = string.strip().split('}}', 1) comment = comment.strip() template = template.lstrip('{') @@ -307,8 +313,7 @@ class Result(object): if newbug.isdigit(): bugs[i] = newbug - res = cls(status, user, bugs, comment, bot) - res.origtext = string + res = cls(status, user, bugs, comment, bot, origtext=string) if user and "previous " in user: res.transferred = True return res @@ -348,72 +353,50 @@ class Result(object): comment = comment.strip() else: pass - res = cls(status, user, bugs, comment) - res.origtext = string + res = cls(status, user, bugs, comment, origtext=string) if user and "previous " in user: res.transferred = True return res -class TestInstance(object): - """Represents the broad concept of a 'test instance': that is, in - any test management system, the 'basic unit' of a single test for - which some results are expected to be reported. In 'Wikitcms', for - instance, this corresponds to a single row in a results table, and - that is what the ResultRow() subclass represents. A subclass for - QATracker would represent a single test in a build of a product. - - The 'testcase' is the basic identifier of a test instance. It will - not necessarily be unique, though - in any test management system - you may find multiple test instances for the same test case (in - different builds and different products). The concept of the - name derives from Wikitcms, where it is not uncommon for a set of - test instances to have the same 'testcase' but a different 'name', - which in that system is the link text: there will a column which - for each row contains [[testcase|name]], the testcase being the - same but the name being different. The concept doesn't seem - entirely specific to Wiki TCMS, though, so it's represented here. - Commonly the 'testcase' and 'name' will be the same, when each - instance within a set has a different 'testcase' the name should - be identical to the testcase. - - milestone is, roughly, the priority of the test: milestone is - slightly Fedora-specific language, a hangover from early wikitcms - versions which didn't consider other systems. For Fedora it will - be Alpha, Beta or Final, usually. For Ubuntu it may be - 'mandatory', 'optional' or possibly 'disabled'. - - results is required to be a dict of lists; the dict keys represent - the test's environments. If the test system does not have the - concept of environments, the dict can have a single key with some - sort of generic name (like 'Results'). The values must be lists of - instances of wikitcms.Result or a subclass of it. - """ - def __init__(self, testcase, milestone='', results=None): - self.testcase = testcase - self.name = testcase - self.milestone = milestone - if not results: - self.results = dict() - else: - self.results = results - -class ResultRow(TestInstance): +class ResultRow(): """Represents the 'test instance' concept for Wikitcms, where it - is a result row from the tables used to contain results. Some - Wikitcms-specific properties are encoded here. columns is the list - of columns in the table in which the result was found (this is - needed to figure out the environments for the results, as the envs - are represented by table columns, and to know which cell to edit - when modifying results). origtext is the text which was parsed to - produce the instance, if it was produced by the from_wiki_row() - class method which parses wiki text to produce instances. section - and secid are the wiki page section in which the table from which - the row came is located; though these are in a way attributes of - the page, this is really another case where an MW attribute is - just a way of encoding information about a *test*. The splitting - of result pages into sections is a way of sub-grouping tests in - each page. So it's appropriate to store those attributes here. + is a result row from the tables used to contain results. We think + of a "test instance" as the 'basic unit' of a single test for + which some results are expected to be reported. + + The 'testcase' is the basic identifier of a ResultRow. It will + not necessarily be unique, though - it is not uncommon for a set + of ResultRows to have the same 'testcase' but a different 'name', + which is the link text: there will a column which for each row + contains [[testcase|name]], the testcase being the same but the + name being different. Commonly the 'testcase' and 'name' will be + the same, when each instance within a set has a different + 'testcase' the name should be identical to the testcase. + + milestone is, roughly, the priority of the test: it will usually + be Basic, Beta or Final. + + results is required to be a dict of lists; the dict keys represent + the test's environments. The values must be lists of instances of + wikitcms.Result or a subclass of it. + + columns is the list of columns in the table in which the result + was found (this is needed to figure out the environments for the + results, as the envs are represented by table columns, and to know + which cell to edit when modifying results). + + origtext is the text which was parsed to produce the instance, if + it was produced by the from_wiki_row() class method which parses + wiki text to produce instances. + + section and secid are the wiki page section in which the table + from which the row came is located; though these are in a way + attributes of the page, this is really another case where an MW + attribute is just a way of encoding information about a *test*. + The splitting of result pages into sections is a way of sub- + grouping tests in each page. So it's appropriate to store those + attributes here. At present you typically get ResultRow instances by calling a ComposePage's get_resultrows() method, which runs its text through @@ -422,9 +405,17 @@ class ResultRow(TestInstance): method. This will always provide instances with a full set of the above-described attributes. """ + # pylint: disable=too-many-instance-attributes def __init__(self, testcase, columns, section='', secid=None, milestone='', origtext='', results=None): - super(ResultRow, self).__init__(testcase, milestone, results) + # pylint: disable=too-many-arguments + self.testcase = testcase + self.name = testcase + self.milestone = milestone + if not results: + self.results = dict() + else: + self.results = results self.columns = columns self.origtext = origtext self.section = section @@ -453,6 +444,7 @@ class ResultRow(TestInstance): """Instantiate a ResultRow from some wikitext and some info that is worked out from elsewhere in the page. """ + # pylint: disable=too-many-locals, too-many-arguments results = OrderedDict() # this is presumptuous, but holds up for every result page # tested so far; there may be some with whitespace, and