Browse Source

Eliminate len() usage in tests

tags/20.3b1
Tzu-ping Chung 2 months ago
parent
commit
761433cee8
2 changed files with 5 additions and 6 deletions
  1. +4
    -5
      src/pip/_internal/resolution/resolvelib/found_candidates.py
  2. +1
    -1
      tests/unit/resolution_resolvelib/test_requirement.py

+ 4
- 5
src/pip/_internal/resolution/resolvelib/found_candidates.py View File

@@ -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):


+ 1
- 1
tests/unit/resolution_resolvelib/test_requirement.py View File

@@ -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):


Loading…
Cancel
Save