Respond to review changes

pull/2099/head
tuxxy 2020-08-10 15:35:14 +02:00
parent fe04ef26ba
commit d033c0b318
4 changed files with 15 additions and 9 deletions

View File

@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import msgpack
from typing import Any, Callable, Iterable, NamedTuple, Optional, Union
from typing import Any, Callable, Iterable, NamedTuple, Union
class DBWriteError(Exception):
@ -47,8 +47,8 @@ class RecordField(NamedTuple):
will probably always want to provide a `decode`.
"""
field_type: Any
encode: Optional[Callable[[Any], bytes]] = lambda field: field
decode: Optional[Callable[[bytes], Any]] = lambda field: field
encode: Callable[[Any], bytes] = lambda field: field
decode: Callable[[bytes], Any] = lambda field: field
class DatastoreRecord:

View File

@ -18,7 +18,7 @@ import lmdb
import maya
from contextlib import contextmanager, suppress
from functools import partial
from typing import Any, Callable, List, NamedTuple, Optional, Union
from typing import Any, Callable, List, NamedTuple, Optional, Type, Union
from bytestring_splitter import BytestringSplitter
from nucypher.crypto.signing import Signature
@ -97,9 +97,9 @@ class Datastore:
@contextmanager
def describe(self,
record_type: 'DatastoreRecord',
record_type: Type['DatastoreRecord'],
record_id: Union[int, str],
writeable: bool=False) -> 'DatastoreRecord':
writeable: bool = False) -> Type['DatastoreRecord']:
"""
This method is used to perform CRUD operations on the datastore within
the safety of a context manager by returning an instance of the
@ -137,11 +137,11 @@ class Datastore:
@contextmanager
def query_by(self,
record_type: 'DatastoreRecord',
filter_func: Callable[[Union[Any, 'DatastoreRecord']], bool] = None,
record_type: Type['DatastoreRecord'],
filter_func: Optional[Callable[[Union[Any, Type['DatastoreRecord']]], bool]] = None,
filter_field: str = "",
writeable: bool = False,
) -> List['DatastoreRecord']:
) -> List[Type['DatastoreRecord']]:
"""
Performs a query on the datastore for the record by `record_type`.

View File

@ -45,6 +45,7 @@ from tests.constants import (
MOCK_PROVIDER_URI,
NUMBER_OF_MOCK_KEYSTORE_ACCOUNTS
)
from nucypher.datastore.datastore import Datastore # yikes TODO
from tests.fixtures import _make_testerchain, make_token_economics
from tests.mock.agents import MockContractAgency, MockContractAgent
from tests.mock.interfaces import MockBlockchain, mock_registry_source_manager
@ -65,6 +66,7 @@ class TestLMDBEnv:
This is necessary in testing environments because there may be too many
LMDB environments open at once.
"""
__test__ = False # Prohibit pytest from collecting this
LMDB_OPEN_FUNC = lmdb.open
@ -88,6 +90,10 @@ class TestLMDBEnv:
def JIT_lmdb_env(monkeypatch):
monkeypatch.setattr("lmdb.open", TestLMDBEnv)
@pytest.fixture(autouse=True)
def reduced_memory_page_lmdb(monkeypatch):
monkeypatch.setattr(Datastore, "LMDB_MAP_SIZE", 10_000_000)
@pytest.fixture(scope='function', autouse=True)
def mock_contract_agency(monkeypatch, module_mocker, token_economics):