Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_iter_method_on_state_store #260

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [5.5.1]

### Added

* Added iter method on the state store to return the keys of the local state dict

## [5.5.0]

### Added
Expand Down
2 changes: 1 addition & 1 deletion cognite/extractorutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
Cognite extractor utils is a Python package that simplifies the development of new extractors.
"""

__version__ = "5.5.0"
__version__ = "5.5.1"
from .base import Extractor
6 changes: 5 additions & 1 deletion cognite/extractorutils/statestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
import threading
from abc import ABC, abstractmethod
from types import TracebackType
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union

from requests.exceptions import ConnectionError

Expand Down Expand Up @@ -309,6 +309,10 @@ def __contains__(self, external_id: str) -> bool:
def __len__(self) -> int:
return len(self._local_state)

def __iter__(self) -> Iterable[str]:
for key in self._local_state:
yield key


class RawStateStore(AbstractStateStore):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cognite-extractor-utils"
version = "5.5.0"
version = "5.5.1"
description = "Utilities for easier development of extractors for CDF"
authors = ["Mathias Lohne <mathias.lohne@cognite.com>"]
license = "Apache-2.0"
Expand Down
13 changes: 13 additions & 0 deletions tests/tests_unit/test_statestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ def test_get_state(self):

self.assertListEqual(state_store.get_state(["extId1", "extId3", "extId5"]), [(1, 5), (0, None), (None, None)])

def test_local_state_interaction(self):
state_store = NoStateStore()
state_store._local_state = {
"extId1": {"low": 1, "high": 5},
"extId2": {"low": None, "high": 4},
"extId3": {"low": 0},
"extId4": {"low": 3, "high": None},
}

self.assertTrue(len(state_store) == len(state_store._local_state))
for id in state_store:
self.assertTrue(id in state_store._local_state.keys())

@patch("cognite.client.CogniteClient")
def test_upload_queue_integration(self, MockCogniteClient):
state_store = NoStateStore()
Expand Down