Eliminate len() usage in tests

This commit is contained in:
Tzu-ping Chung 2020-10-02 19:55:05 +08:00
bovenliggende 17d0086ea2
commit 761433cee8
2 gewijzigde bestanden met toevoegingen van 5 en 6 verwijderingen

Bestand weergeven

@ -83,13 +83,12 @@ class FoundCandidates(collections_abc.Sequence):
candidates = _insert_installed(self._installed, self._get_others())
return _deduplicated_by_version(candidates)
@lru_cache(maxsize=1)
def __len__(self):
# type: () -> int
# Implement to satisfy the ABC check and used in tests. This is not
# needed by the resolver, and should not be used by the provider either
# (for performance reasons).
return sum(1 for _ in self)
# Implemented to satisfy the ABC check. This is not needed by the
# resolver, and should not be used by the provider either (for
# performance reasons).
raise NotImplementedError("don't do this")
@lru_cache(maxsize=1)
def __bool__(self):

Bestand weergeven

@ -61,7 +61,7 @@ def test_new_resolver_correct_number_of_matches(test_cases, factory):
matches = factory.find_candidates(
[req], Constraint.empty(), prefers_installed=False,
)
assert len(list(matches)) == match_count
assert sum(1 for _ in matches) == match_count
def test_new_resolver_candidates_match_requirement(test_cases, factory):