From c3aa59355f2a03077660b85cdea12da644c00c3e Mon Sep 17 00:00:00 2001 From: hkey <81494947+hkey0@users.noreply.github.com> Date: Sun, 31 Dec 2023 04:08:09 +0300 Subject: [PATCH] Made more readable (pep8) (#10) * made more readable * made more readable * made more readable * made more readable --- src/sinker/sinker.py | 4 ++-- tests/test_bulk_action_generator.py | 10 ++++++---- tests/test_e2e.py | 24 ++++++++++++++++-------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/sinker/sinker.py b/src/sinker/sinker.py index d8e4a25..656e516 100644 --- a/src/sinker/sinker.py +++ b/src/sinker/sinker.py @@ -25,7 +25,7 @@ class Sinker: - def __init__(self, view, index): + def __init__(self, view: str, index: str): """ :param view: Postgres materialized view name :param index: Elasticsearch index name @@ -83,7 +83,7 @@ def recreate_index(self) -> None: settings=index_body["settings"], ) - def setup_pg(self): + def setup_pg(self) -> None: """ Creates materialized views with supporting functions and triggers, and sets the parent table that drives the materialized view diff --git a/tests/test_bulk_action_generator.py b/tests/test_bulk_action_generator.py index 6ee60a0..d3a5c32 100644 --- a/tests/test_bulk_action_generator.py +++ b/tests/test_bulk_action_generator.py @@ -4,20 +4,22 @@ @pytest.fixture -def bulk_action_generator(): +def bulk_action_generator() -> BulkActionGenerator: v2i = dict(foo_mv="foo_index") pt2i = dict(foo_table="foo_index") - return BulkActionGenerator(views_to_indices=v2i, parent_tables_to_indices=pt2i) + return BulkActionGenerator( + views_to_indices=v2i, + parent_tables_to_indices=pt2i) -def test_index_action(bulk_action_generator): +def test_index_action(bulk_action_generator: BulkActionGenerator) -> None: doc = '{"name" : "Foo Bar"}' slot_dict = dict(table="foo_mv", id="a-1") expected = {"_index": "foo_index", "_id": "a-1", "_source": doc} assert bulk_action_generator.index_action(doc, slot_dict) == expected -def test_delete_action(bulk_action_generator): +def test_delete_action(bulk_action_generator: BulkActionGenerator) -> None: slot_dict = dict(table="foo_table", id="a-1") expected = {"_op_type": "delete", "_index": "foo_index", "_id": "a-1"} assert bulk_action_generator.delete_action(slot_dict) == expected diff --git a/tests/test_e2e.py b/tests/test_e2e.py index e753606..f0b5fe7 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -34,20 +34,25 @@ def wait_for_pg_es(): def test_exception_propagation_during_refresh(wait_for_pg_es): runner = Runner() - # Update a record in Postgres but remove the materialized view so it errors when we iterate + # Update a record in Postgres but remove the materialized view so it + # errors when we iterate conn = psycopg.connect(autocommit=True) cur = conn.cursor() cur.execute("update public.person set name = 'Uh oh' where id = 'p-1'") cur.execute("drop materialized view sinker.person_mv") - # make sure the exception gets raised from the thread versus silently consuming it + # make sure the exception gets raised from the thread versus silently + # consuming it with pytest.raises(psycopg.errors.UndefinedTable): runner.iterate() def test_exception_propagation_during_setup(wait_for_pg_es, mocker): - # mock es.get_client() to raise an exception in the thread that sets up the sinker - mocker.patch("sinker.sinker.get_client", side_effect=elasticsearch.exceptions.ConnectionError('Boom!')) - # make sure the exception gets raised from the thread versus silently consuming it + # mock es.get_client() to raise an exception in the thread that sets up + # the sinker + mocker.patch("sinker.sinker.get_client", + side_effect=elasticsearch.exceptions.ConnectionError('Boom!')) + # make sure the exception gets raised from the thread versus silently + # consuming it with pytest.raises(elasticsearch.exceptions.ConnectionError): Runner() @@ -92,12 +97,14 @@ def test_end_to_end(wait_for_pg_es): assert doc["_source"] == expected # Update a record in Postgres - psycopg.connect(autocommit=True).execute("update public.person set name = 'Jane' where id = 'p-1'") + psycopg.connect(autocommit=True).execute( + "update public.person set name = 'Jane' where id = 'p-1'") runner.iterate() # Verify the update made it into the people index doc = es.get(index="people", id="p-1") assert doc["_source"]["name"] == "Jane" - # Verify the update made it into the courses index through person->student->enrollment->course. + # Verify the update made it into the courses index through + # person->student->enrollment->course. doc = es.get(index="courses", id="c-1") expected = { "name": "Reth", @@ -137,7 +144,8 @@ def test_end_to_end(wait_for_pg_es): # Verify the doc got deleted from Elasticsearch with pytest.raises(elasticsearch.NotFoundError): es.get(index="people", id="p-1") - # Verify the doc got deleted from Elasticsearch through person->student->enrollment->course. + # Verify the doc got deleted from Elasticsearch through + # person->student->enrollment->course. doc = es.get(index="courses", id="c-1") expected = { "name": "Reth",