Skip to content

Commit

Permalink
test: fix num_entities in InMemoryRepos
Browse files Browse the repository at this point in the history
  • Loading branch information
kod-kristoff committed Mar 29, 2022
1 parent 3e24fa3 commit 7bb7e47
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions karp/tests/unit/lex/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _save(self, resource):
def _by_id(self, id_, *, version=None):
return self.resources.get(id_)

def _by_resource_id(self, resource_id, *, version=None):
def _by_resource_id(self, resource_id):
return next((res for res in self.resources.values() if res.resource_id == resource_id), None)

def __len__(self):
Expand All @@ -57,7 +57,7 @@ def resource_ids(self) -> typing.Iterable[str]:
return (res.resource_id for res in self.resources)

def num_entities(self) -> int:
return len(self.resources)
return sum( not res.discarded for res in self.resources.values() )


class InMemoryReadResourceRepository(ReadOnlyResourceRepository):
Expand Down Expand Up @@ -147,7 +147,7 @@ def all_entries(self) -> typing.Iterable[lex_entities.Entry]:
yield from self.entries

def num_entities(self) -> int:
return len(self.entries)
return sum( not e.discarded for e in self.entries.values() )


class InMemoryEntryUnitOfWork(
Expand Down Expand Up @@ -264,7 +264,7 @@ def __len__(self):
return len(self._storage)

def num_entities(self) -> int:
return len(self._storage)
return sum(not er.discarded for er in self._storage.values())


class InMemoryEntryUowRepositoryUnitOfWork(InMemoryUnitOfWork, lex_repositories.EntryUowRepositoryUnitOfWork):
Expand Down

0 comments on commit 7bb7e47

Please sign in to comment.