Skip to content

Commit

Permalink
detox
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbc committed Jan 8, 2024
1 parent 8909765 commit 5781a96
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest import mock

import pytest

# from pynamodb.attributes import UnicodeAttribute
# from pynamodb.models import Model

Expand All @@ -11,13 +12,11 @@
from moto import mock_dynamodb
from toshi_hazard_store import model

# @pytest.fixture(autouse=True)

@pytest.fixture()
def setenvvar(tmp_path):
# ref https://adamj.eu/tech/2020/10/13/how-to-mock-environment-variables-with-pytest/
envvars = {
"THS_SQLITE_FOLDER": str(tmp_path),
"THS_USE_SQLITE_ADAPTER": "TRUE"
}
envvars = {"THS_SQLITE_FOLDER": str(tmp_path), "THS_USE_SQLITE_ADAPTER": "TRUE"}
with mock.patch.dict(os.environ, envvars, clear=True):
yield # This is the magical bit which restore the environment after

Expand All @@ -29,6 +28,7 @@ def adapter_model():
yield model
model.drop_tables()


@pytest.fixture()
def get_one_meta():
with mock_dynamodb():
Expand All @@ -50,4 +50,4 @@ def get_one_meta():
src_lt=json.dumps(dict(sources=[1, 2])), # sources meta as DataFrame JSON
gsim_lt=json.dumps(dict(gsims=[1, 2])), # gmpe meta as DataFrame JSON
rlz_lt=json.dumps(dict(rlzs=[1, 2])), # realization meta as DataFrame JSON
)
)
8 changes: 3 additions & 5 deletions tests/test_pynamo_models_v3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import unittest

import pynamodb.exceptions
Expand All @@ -7,6 +6,7 @@

from toshi_hazard_store import model


def get_one_rlz():
imtvs = []
for t in ['PGA', 'SA(0.5)', 'SA(1.0)']:
Expand Down Expand Up @@ -35,13 +35,11 @@ def get_one_hazard_aggregate():
).set_location(location)



# MAKE this test both pynamo and sqlite
class TestPynamoMeta(object):

def test_table_exists(self, adapter_model):
assert adapter_model.OpenquakeRealization.exists() == True
assert adapter_model.ToshiOpenquakeMeta.exists() == True
assert adapter_model.OpenquakeRealization.exists()
assert adapter_model.ToshiOpenquakeMeta.exists()

def test_save_one_meta_object(self, get_one_meta):
obj = get_one_meta
Expand Down
5 changes: 1 addition & 4 deletions tests/v2/test_pynamo_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import pytest

class TestPynamoMeta(object):

def test_meta_table_exists(self, adapter_model):
assert adapter_model.ToshiOpenquakeMeta.exists() == True
assert adapter_model.ToshiOpenquakeMeta.exists()

def test_save_one_meta_object(self, get_one_meta):
obj = get_one_meta
Expand Down

0 comments on commit 5781a96

Please sign in to comment.