From 2194efb20e098d7d3bcbfca19d377837f638da22 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Mon, 18 Nov 2024 19:13:39 +0000 Subject: [PATCH] linting --- aim/cli/main.py | 1 + aim/digifeeds/db_client.py | 4 ++-- docs/conf.py | 13 ++++++++++--- tests/conftest.py | 14 +++++++++----- tests/digifeeds/database/test_models.py | 14 +++++--------- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/aim/cli/main.py b/aim/cli/main.py index 4124886..8c6df0a 100644 --- a/aim/cli/main.py +++ b/aim/cli/main.py @@ -3,6 +3,7 @@ This hooks up the AIM CLI application. Nothing exciting happening here. """ + import typer import aim.cli.digifeeds as digifeeds diff --git a/aim/digifeeds/db_client.py b/aim/digifeeds/db_client.py index d6f4538..f08b0cd 100644 --- a/aim/digifeeds/db_client.py +++ b/aim/digifeeds/db_client.py @@ -70,12 +70,12 @@ def add_item_status(self, barcode: str, status: str): def get_items(self, limit: int = 50, in_zephir: bool | None = None): items = [] - url = self._url(f"items") + url = self._url("items") params = { "limit": limit, "offset": 0, } - if in_zephir != None: + if in_zephir is not None: params["in_zephir"] = in_zephir response = requests.get(url, params=params) diff --git a/docs/conf.py b/docs/conf.py index fe52415..739c0a9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,8 +14,15 @@ # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration -extensions = ["sphinx.ext.napoleon", "sphinx.ext.viewcode", "sphinx.ext.autosummary", - "sphinx.ext.autodoc", 'myst_parser', 'sphinxcontrib.mermaid', "sphinx_toolbox.more_autodoc.autonamedtuple"] +extensions = [ + "sphinx.ext.napoleon", + "sphinx.ext.viewcode", + "sphinx.ext.autosummary", + "sphinx.ext.autodoc", + "myst_parser", + "sphinxcontrib.mermaid", + "sphinx_toolbox.more_autodoc.autonamedtuple", +] autosummary_generate = True mermaid_d3_zoom = True @@ -33,5 +40,5 @@ html_theme_options = { "navigation_depth": 5, "collapse_navigation": False, - "titles_only": True + "titles_only": True, } diff --git a/tests/conftest.py b/tests/conftest.py index 8e71b08..99204f1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,8 +10,10 @@ engine = create_engine( S.test_database, - connect_args={ "check_same_thread": False,}, - poolclass=StaticPool + connect_args={ + "check_same_thread": False, + }, + poolclass=StaticPool, ) TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) @@ -25,10 +27,11 @@ session.close() connection.close() + # From: https://stackoverflow.com/questions/67255653/how-to-set-up-and-tear-down-a-database-between-tests-in-fastapi # These two event listeners are only needed for sqlite for proper # SAVEPOINT / nested transaction support. Other databases like postgres -# don't need them. +# don't need them. # From: https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl @sa.event.listens_for(engine, "connect") def do_connect(dbapi_connection, connection_record): @@ -42,6 +45,7 @@ def do_begin(conn): # emit our own BEGIN conn.exec_driver_sql("BEGIN") + # Handles rolling back the db after every test @pytest.fixture() def db_session(scope="module"): @@ -49,7 +53,6 @@ def db_session(scope="module"): transaction = connection.begin() session = TestingSessionLocal(bind=connection) - # Begin a nested transaction (using SAVEPOINT). nested = connection.begin_nested() @@ -68,6 +71,7 @@ def end_savepoint(session, transaction): transaction.rollback() connection.close() + # A fixture for the fastapi test client which depends on the # previous session fixture. Instead of creating a new session in the # dependency override as before, it uses the one provided by the @@ -79,4 +83,4 @@ def override_get_db(): app.dependency_overrides[get_db] = override_get_db yield TestClient(app) - del app.dependency_overrides[get_db] \ No newline at end of file + del app.dependency_overrides[get_db] diff --git a/tests/digifeeds/database/test_models.py b/tests/digifeeds/database/test_models.py index e6d183d..23769cc 100644 --- a/tests/digifeeds/database/test_models.py +++ b/tests/digifeeds/database/test_models.py @@ -1,5 +1,6 @@ from aim.digifeeds.database.models import Item, Status, ItemStatus + class TestItem: def test_item_valid(self, db_session): valid_item = Item(barcode="valid_barcode") @@ -15,19 +16,14 @@ def test_item_statuses(self, db_session): db_session.commit() status = db_session.query(Status).filter_by(name="in_zephir").first() db_session.refresh(item) - assert(len(item.statuses)) == 0 + assert (len(item.statuses)) == 0 - item_status = ItemStatus(item=item,status=status) + item_status = ItemStatus(item=item, status=status) db_session.add(item_status) db_session.commit() db_session.refresh(item) assert item.barcode == "valid_barcode" - assert(len(item.statuses)) == 1 - assert(item.statuses[0].created_at) + assert (len(item.statuses)) == 1 + assert item.statuses[0].created_at assert item.statuses[0].status_name == "in_zephir" - - - - - \ No newline at end of file