Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[flake8]
max-line-length = 88
extend-ignore = E203, E501, E721, W503
per-file-ignores =
*/types.py:F401
*/models_autogenerated.py:E501
*models_auto.py:E501
exclude =
.git,
__pycache__,
.venv,
build,
dist,
*.egg-info
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ To run tests:
poetry run pytest
```

To run flake8:

````bash
poetry run flake8 open_alchemy tests
```

Make your changes and raise a pull request.

## Compiling Docs
Expand Down
18 changes: 7 additions & 11 deletions examples/app/models_autogenerated.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ class TEmployee(typing.Protocol):
query: orm.Query

# Model properties
id: "sqlalchemy.Column[int]"
name: "sqlalchemy.Column[str]"
division: "sqlalchemy.Column[str]"
salary: "sqlalchemy.Column[typing.Optional[float]]"

def __init__(
self, id: int, name: str, division: str, salary: typing.Optional[float] = None
) -> None:
id: 'sqlalchemy.Column[int]'
name: 'sqlalchemy.Column[str]'
division: 'sqlalchemy.Column[str]'
salary: 'sqlalchemy.Column[typing.Optional[float]]'

def __init__(self, id: int, name: str, division: str, salary: typing.Optional[float] = None) -> None:
"""
Construct.

Expand All @@ -66,9 +64,7 @@ def __init__(
...

@classmethod
def from_dict(
cls, id: int, name: str, division: str, salary: typing.Optional[float] = None
) -> "TEmployee":
def from_dict(cls, id: int, name: str, division: str, salary: typing.Optional[float] = None) -> "TEmployee":
"""
Construct from a dictionary (eg. a POST payload).

Expand Down
4 changes: 2 additions & 2 deletions open_alchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import types as py_types
import typing

from sqlalchemy.ext import declarative
from sqlalchemy.orm import declarative_base

from open_alchemy import types as oa_types

Expand Down Expand Up @@ -116,7 +116,7 @@ def _init_optional_base(
) -> BaseAndModelFactory:
"""Wrap init_model_factory with optional base."""
if base is None:
base = declarative.declarative_base()
base = declarative_base()
return (
base,
init_model_factory(
Expand Down
3,911 changes: 2,493 additions & 1,418 deletions poetry.lock

Large diffs are not rendered by default.

22 changes: 10 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
authors = ["David Andersson <anderssonpublic@gmail.com>"]
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Development Status :: 5 - Production/Stable",
Expand Down Expand Up @@ -34,19 +34,18 @@ openalchemy = "open_alchemy.cli:main"

[tool.poetry.dependencies]
Jinja2 = "^3"
SQLAlchemy = "^1.0"
jsonschema = "^3"
python = "^3.7"
sqlalchemy-stubs = ">=0.3,<0.5"
typing_extensions = {version = "^3.7.4", python = "<3.8"}
SQLAlchemy = "^2.0"
jsonschema = "^4"
python = "^3.10"
typing_extensions = "^4.6"

[tool.poetry.extras]
wheel = ["wheel"]
yaml = ["PyYAML"]

[tool.poetry.dev-dependencies]
Flask-SQLAlchemy = "^2"
PyYAML = "^5"
[tool.poetry.group.dev.dependencies]
Flask-SQLAlchemy = "^3"
PyYAML = "^6"
Sphinx = "^3"
alembic = "^1"
bandit = "^1"
Expand All @@ -62,7 +61,6 @@ pydocstyle = "^6"
pylint = "^2"
pytest = "^6"
pytest-cov = "^2"
pytest-flake8 = "^1"
pytest-flask = "^1"
pytest-flask-sqlalchemy = "^1"
pytest-randomly = "^3"
Expand Down
9 changes: 1 addition & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
universal = 1

[tool:pytest]
addopts = --cov=open_alchemy --cov=examples/app --cov-config=tests/.coveragerc --flake8 --strict --cov-report xml --cov-report term
addopts = --cov=open_alchemy --cov=examples/app --cov-config=tests/.coveragerc --strict-markers --cov-report xml --cov-report term
markers =
app
artifacts
Expand Down Expand Up @@ -30,13 +30,6 @@ markers =
cache
python_functions = test_*
mocked-sessions = examples.app.database.db.session
flake8-max-line-length = 88
flake8-ignore =
*/types.py:F401
*/models_autogenerated.py E501
*models_auto.py E501
* E721
* W503

[rstcheck]
ignore_messages=(No role entry for "samp")|(Duplicate implicit target name: )|(Hyperlink target .* is not referenced.)
6 changes: 3 additions & 3 deletions tests/examples/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import typing

import yaml
from sqlalchemy.ext import declarative
from sqlalchemy.orm import declarative_base

import open_alchemy

Expand Down Expand Up @@ -45,7 +45,7 @@ def create_model(*, filename: str, model_name: str, engine: typing.Any) -> typin
"""
spec = read_spec(filename=filename)
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
model = model_factory(name=model_name)
# Initialise database
Expand Down Expand Up @@ -99,7 +99,7 @@ def create_models(
"""
spec = read_spec(filename=filename)
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
models = tuple(map(lambda name: model_factory(name=name), model_names))
# Initialise database
Expand Down
4 changes: 3 additions & 1 deletion tests/examples/test_example_specs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test for examples."""

import pytest
from sqlalchemy import text

from open_alchemy import models

Expand Down Expand Up @@ -291,7 +292,8 @@ def test_table_args(engine, filename, model_name, sql, expected_contents):
helpers.create_model(filename=filename, model_name=model_name, engine=engine)

# Query schema
results_list = list(str(result) for result in engine.execute(sql))
with engine.connect() as conn:
results_list = list(str(result) for result in conn.execute(text(sql)))
results = "\n".join(results_list)

for expected_content in expected_contents:
Expand Down
6 changes: 3 additions & 3 deletions tests/open_alchemy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from urllib import request

import pytest
from sqlalchemy.ext import declarative
from sqlalchemy.orm import declarative_base

import open_alchemy
from open_alchemy import column_factory
Expand Down Expand Up @@ -91,9 +91,9 @@ def _mocked_init_model_factory(mocked_init_model_factory):

@pytest.fixture
def mocked_declarative_base(monkeypatch):
"""Monkeypatch declarative.declarative_base."""
"""Monkeypatch declarative_base."""
mock_declarative_base = mock.MagicMock()
monkeypatch.setattr(declarative, "declarative_base", mock_declarative_base)
monkeypatch.setattr(open_alchemy, "declarative_base", mock_declarative_base)
return mock_declarative_base


Expand Down
6 changes: 2 additions & 4 deletions tests/open_alchemy/facades/sqlalchemy/test_relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_construct_many_to_one():

assert returned_relationship.argument == "Parent"
assert returned_relationship.backref is None
assert returned_relationship.secondary is None


@pytest.mark.facade
Expand Down Expand Up @@ -91,8 +90,7 @@ def test_construct_many_to_one_kwargs():

returned_relationship = relationship.construct(artifacts=artifacts)

assert returned_relationship.order_by == "id"

assert returned_relationship.argument == "Parent"

@pytest.mark.facade
@pytest.mark.sqlalchemy
Expand Down Expand Up @@ -145,4 +143,4 @@ def test_construct_many_to_many():

returned_relationship = relationship.construct(artifacts=artifacts)

assert returned_relationship.secondary == "association"
assert returned_relationship.argument == "Parent"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Integration tests against database for inheritance."""

import pytest
from sqlalchemy.ext import declarative
from sqlalchemy.orm import declarative_base

import open_alchemy

Expand Down Expand Up @@ -62,7 +62,7 @@ def test_single(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
employee = model_factory(name="Employee")
manager = model_factory(name="Manager")
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_joined(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
employee = model_factory(name="Employee")
manager = model_factory(name="Manager")
Expand Down
24 changes: 12 additions & 12 deletions tests/open_alchemy/integration/test_database/test_relationship.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Integration tests against database for relationships."""

import pytest
from sqlalchemy.ext import declarative
from sqlalchemy.orm import declarative_base

import open_alchemy

Expand Down Expand Up @@ -39,7 +39,7 @@ def test_many_to_one(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
model = model_factory(name="Table")
ref_model = model_factory(name="RefTable")
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_many_to_one_backref(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
model = model_factory(name="Table")
ref_model = model_factory(name="RefTable")
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_many_to_one_relationship_fk(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
model = model_factory(name="Table")
ref_model = model_factory(name="RefTable")
Expand Down Expand Up @@ -224,7 +224,7 @@ def test_one_to_one(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
model = model_factory(name="Table")
ref_model = model_factory(name="RefTable")
Expand Down Expand Up @@ -280,7 +280,7 @@ def test_one_to_many(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
model = model_factory(name="Table")
ref_model = model_factory(name="RefTable")
Expand Down Expand Up @@ -356,7 +356,7 @@ def test_one_to_many_relationship_kwargs(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
model = model_factory(name="Table")
ref_model = model_factory(name="RefTable")
Expand Down Expand Up @@ -420,7 +420,7 @@ def test_one_to_many_relationship_other_order(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
ref_model = model_factory(name="RefTable")
model = model_factory(name="Table")
Expand Down Expand Up @@ -478,7 +478,7 @@ def test_many_to_many(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
model = model_factory(name="Table")
ref_model = model_factory(name="RefTable")
Expand Down Expand Up @@ -557,7 +557,7 @@ def test_many_to_many_pre_defined(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
model = model_factory(name="Table")
ref_model = model_factory(name="RefTable")
Expand Down Expand Up @@ -656,7 +656,7 @@ def test_ref_all_of(engine, sessionmaker, spec):
THEN the instance is returned when the session is queried for it.
"""
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
model = model_factory(name="Table")

Expand Down Expand Up @@ -725,7 +725,7 @@ def test_multiple(engine, sessionmaker):
}
}
# Creating model factory
base = declarative.declarative_base()
base = declarative_base()
model_factory = open_alchemy.init_model_factory(spec=spec, base=base)
model = model_factory(name="Table")
ref_model = model_factory(name="RefTable")
Expand Down
Loading