diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2020-11-25 10:41:03 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2021-01-07 19:20:11 +0100 |
commit | e50861e62f6cf695ba087ab161b3938be7c2b131 (patch) | |
tree | 631e235a811df8798680672884e828591e0d2093 /mesonbuild/mtest.py | |
parent | 304abaf9ee3fd3c2cfd092811f26117d231a6a28 (diff) | |
download | meson-e50861e62f6cf695ba087ab161b3938be7c2b131.zip meson-e50861e62f6cf695ba087ab161b3938be7c2b131.tar.gz meson-e50861e62f6cf695ba087ab161b3938be7c2b131.tar.bz2 |
mtest/TAPParser: use typing.NamedTuple
It is cleaner than collections.namedtuple. It also catches that "count()" is
a method on tuple, so rename the field to num_tests.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild/mtest.py')
-rw-r--r-- | mesonbuild/mtest.py | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index 8af37f0..22ab8e5 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -15,7 +15,7 @@ # A tool to run tests in many different ways. from pathlib import Path -from collections import deque, namedtuple +from collections import deque from copy import deepcopy import argparse import asyncio @@ -209,11 +209,26 @@ class TestResult(enum.Enum): TYPE_TAPResult = T.Union['TAPParser.Test', 'TAPParser.Error', 'TAPParser.Version', 'TAPParser.Plan', 'TAPParser.Bailout'] class TAPParser: - Plan = namedtuple('Plan', ['count', 'late', 'skipped', 'explanation']) - Bailout = namedtuple('Bailout', ['message']) - Test = namedtuple('Test', ['number', 'name', 'result', 'explanation']) - Error = namedtuple('Error', ['message']) - Version = namedtuple('Version', ['version']) + class Plan(T.NamedTuple): + num_tests: int + late: bool + skipped: bool + explanation: T.Optional[str] + + class Bailout(T.NamedTuple): + message: str + + class Test(T.NamedTuple): + number: int + name: str + result: TestResult + explanation: T.Optional[str] + + class Error(T.NamedTuple): + message: str + + class Version(T.NamedTuple): + version: int _MAIN = 1 _AFTER_TEST = 2 @@ -308,16 +323,16 @@ class TAPParser: if self.plan: yield self.Error('more than one plan found') else: - count = int(m.group(1)) - skipped = (count == 0) + num_tests = int(m.group(1)) + skipped = (num_tests == 0) if m.group(2): if m.group(2).upper().startswith('SKIP'): - if count > 0: + if num_tests > 0: yield self.Error('invalid SKIP directive for plan') skipped = True else: yield self.Error('invalid directive for plan') - self.plan = self.Plan(count=count, late=(self.num_tests > 0), + self.plan = self.Plan(num_tests=num_tests, late=(self.num_tests > 0), skipped=skipped, explanation=m.group(3)) yield self.plan return @@ -350,11 +365,11 @@ class TAPParser: if self.state == self._YAML: yield self.Error('YAML block not terminated (started on line {})'.format(self.yaml_lineno)) - if not self.bailed_out and self.plan and self.num_tests != self.plan.count: - if self.num_tests < self.plan.count: - yield self.Error('Too few tests run (expected {}, got {})'.format(self.plan.count, self.num_tests)) + if not self.bailed_out and self.plan and self.num_tests != self.plan.num_tests: + if self.num_tests < self.plan.num_tests: + yield self.Error('Too few tests run (expected {}, got {})'.format(self.plan.num_tests, self.num_tests)) else: - yield self.Error('Too many tests run (expected {}, got {})'.format(self.plan.count, self.num_tests)) + yield self.Error('Too many tests run (expected {}, got {})'.format(self.plan.num_tests, self.num_tests)) class TestLogger: def flush(self) -> None: |