Skip to content

Commit

Permalink
fit to lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
FomalhautWeisszwerg committed Jan 25, 2024
1 parent 2dd62c1 commit b0519d1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ force_grid_wrap = 2
profile = "black"
py_version = 312
src_paths = ["src"]
skip_glob = ["tests/conftest.py", "build/*", "dist/*",]

[tool.pytest.ini_options]
pythonpath = [
Expand Down
8 changes: 2 additions & 6 deletions src/pytest_sqlalchemy_mock/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,11 @@ def session(connection):


@pytest.fixture(scope="function")
def mocked_session(
connection, sqlalchemy_declarative_base, sqlalchemy_mock_config
):
def mocked_session(connection, sqlalchemy_declarative_base, sqlalchemy_mock_config):
session: Session = sessionmaker()(bind=connection)

if sqlalchemy_declarative_base and sqlalchemy_mock_config:
ModelMocker(
session, sqlalchemy_declarative_base, sqlalchemy_mock_config
).create_all()
ModelMocker(session, sqlalchemy_declarative_base, sqlalchemy_mock_config).create_all()

yield session
session.close()
5 changes: 4 additions & 1 deletion src/pytest_sqlalchemy_mock/model_mocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import List, Tuple
from typing import (
List,
Tuple,
)

from sqlalchemy import Table
from sqlalchemy.orm import Session
Expand Down
21 changes: 15 additions & 6 deletions tests/db.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
from typing import List

from sqlalchemy import (Boolean, Column, DateTime, ForeignKey, Integer, String,
func)
from sqlalchemy.orm import Mapped, declarative_base, relationship
from sqlalchemy import (
Boolean,
Column,
DateTime,
ForeignKey,
Integer,
String,
func,
)
from sqlalchemy.orm import (
Mapped,
declarative_base,
relationship,
)
from sqlalchemy.testing.schema import Table

Base = declarative_base()
Expand All @@ -12,9 +23,7 @@
"user_department",
Base.metadata,
Column("user_id", Integer, ForeignKey("user.id"), primary_key=True),
Column(
"department_id", Integer, ForeignKey("department.id"), primary_key=True
),
Column("department_id", Integer, ForeignKey("department.id"), primary_key=True),
)


Expand Down
10 changes: 5 additions & 5 deletions tests/test_pytest_sqlalchemy_mock.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from sqlalchemy import text

from .data import MockData
from .db import Department, User
from .db import (
Department,
User,
)


def test_get_session(session):
Expand All @@ -13,10 +16,7 @@ def test_session_user_table(session):


def test_session_query_for_assocation_table(session):
assert (
session.execute(text("SELECT count(*) from user_department")).scalar()
== 0
)
assert session.execute(text("SELECT count(*) from user_department")).scalar() == 0


def test_mocked_session_user_table(mocked_session):
Expand Down

0 comments on commit b0519d1

Please sign in to comment.