Rename and turn SuiteInfo into a proper class

Signed-off-by: Niels Thykier <niels@thykier.net>
ubuntu/rebased
Niels Thykier 7 years ago
parent e63aa05708
commit b63ade583c

@ -192,7 +192,7 @@ from urllib.parse import quote
import apt_pkg
# Check the "check_field_name" reflection before removing an import here.
from britney2 import Suites, SuiteInfo, SourcePackage, BinaryPackageId, BinaryPackage
from britney2 import Suites, Suite, SourcePackage, BinaryPackageId, BinaryPackage
from britney2.consts import (SOURCE, SOURCEVER, ARCHITECTURE, CONFLICTS, DEPENDS, PROVIDES, MULTIARCH)
from britney2.excuse import Excuse
from britney2.hints import HintParser
@ -506,7 +506,7 @@ class Britney(object):
suffix = suite if suite in {'pu', 'tpu'} else ''
if hasattr(self.options, suite):
suite_path = getattr(self.options, suite)
suites.append(SuiteInfo(name=suite, path=suite_path, excuses_suffix=suffix))
suites.append(Suite(suite, suite_path, suite_short_name=suffix))
else:
if suite in {'testing', 'unstable'}: # pragma: no cover
self.logger.error("Mandatory configuration %s is not set in the config", suite.upper())

@ -1,10 +1,16 @@
from collections import namedtuple
SuiteInfo = namedtuple('SuiteInfo', [
'name',
'path',
'excuses_suffix',
])
class Suite(object):
def __init__(self, name, path, suite_short_name=None):
self.name = name
self.path = path
self.suite_short_name = suite_short_name if suite_short_name else ''
@property
def excuses_suffix(self):
return self.suite_short_name
class Suites(object):
@ -16,13 +22,13 @@ class Suites(object):
self.source_suites = source_suites
self._suites[target_suite.name] = target_suite
self._by_name_or_alias[target_suite.name] = target_suite
if target_suite.excuses_suffix:
self._by_name_or_alias[target_suite.excuses_suffix] = target_suite
if target_suite.suite_short_name:
self._by_name_or_alias[target_suite.suite_short_name] = target_suite
for suite in source_suites:
self._suites[suite.name] = suite
self._by_name_or_alias[suite.name] = suite
if suite.excuses_suffix:
self._by_name_or_alias[suite.excuses_suffix] = suite
if suite.suite_short_name:
self._by_name_or_alias[suite.suite_short_name] = suite
@property
def primary_source_suite(self):
@ -32,14 +38,23 @@ class Suites(object):
def by_name_or_alias(self):
return self._by_name_or_alias
@property
def additional_source_suites(self):
return self.source_suites[1:]
def __getitem__(self, item):
return self._suites[item]
def __len__(self):
return len(self.source_suites) + 1
def __contains__(self, item):
return item in self._suites
def __iter__(self):
yield from self._suites
# Sources first (as we will rely on this for loading data in the old live-data tests)
yield from self.source_suites
yield self.target_suite
class SourcePackage(object):

@ -1,7 +1,7 @@
import unittest
import os
from britney2 import Suites, SuiteInfo, SourcePackage
from britney2 import Suites, Suite, SourcePackage
from britney2.excuse import Excuse
from britney2.hints import HintParser
from britney2.policies.policy import AgePolicy, RCBugPolicy, PiupartsPolicy, PolicyVerdict
@ -19,8 +19,8 @@ def initialize_policy(test_name, policy_class, *args, **kwargs):
del kwargs['hints']
options = MockObject(state_dir=test_dir, verbose=0, default_urgency=DEFAULT_URGENCY, **kwargs)
suite_info = Suites(
SuiteInfo('testing', os.path.join(test_dir, 'testing'), ''),
[SuiteInfo('unstable', os.path.join(test_dir, 'unstable'), '')],
Suite('testing', os.path.join(test_dir, 'testing'), ''),
[Suite('unstable', os.path.join(test_dir, 'unstable'), '')],
)
policy = policy_class(options, suite_info, *args)
fake_britney = MockObject(log=lambda x, y='I': None)

Loading…
Cancel
Save