Skip to content

Commit 05ce1d0

Browse files
committed
Format existing code with ruff
1 parent 555a00e commit 05ce1d0

File tree

3 files changed

+53
-34
lines changed

3 files changed

+53
-34
lines changed

pytest_sqlalchemy.py

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212

1313
@pytest.fixture(scope="session")
14-
def engine(request: FixtureRequest, sqlalchemy_connect_url: Optional[str], app_config: Optional[Dict[str, str]]) -> Engine:
14+
def engine(
15+
request: FixtureRequest,
16+
sqlalchemy_connect_url: Optional[str],
17+
app_config: Optional[Dict[str, str]],
18+
) -> Engine:
1519
"""Engine configuration.
1620
See http://docs.sqlalchemy.org/en/latest/core/engines.html
1721
for more details.
1822
1923
:sqlalchemy_connect_url: Connection URL to the database. E.g
20-
postgresql://scott:tiger@localhost:5432/mydatabase
24+
postgresql://scott:tiger@localhost:5432/mydatabase
2125
:app_config: Path to a ini config file containing the sqlalchemy.url
2226
config variable in the DEFAULT section.
2327
:returns: Engine instance
@@ -38,15 +42,17 @@ def engine(request: FixtureRequest, sqlalchemy_connect_url: Optional[str], app_c
3842
engine = create_engine(url) # override engine
3943

4044
def fin() -> None:
41-
print ("Disposing engine")
45+
print("Disposing engine")
4246
engine.dispose()
4347

4448
request.addfinalizer(fin)
4549
return engine
4650

4751

4852
@pytest.fixture(scope="session")
49-
def db_schema(request: FixtureRequest, engine: Engine, sqlalchemy_manage_db: bool, sqlalchemy_keep_db: bool) -> Optional[None]:
53+
def db_schema(
54+
request: FixtureRequest, engine: Engine, sqlalchemy_manage_db: bool, sqlalchemy_keep_db: bool
55+
) -> Optional[None]:
5056
if not sqlalchemy_manage_db:
5157
return
5258

@@ -58,8 +64,9 @@ def db_schema(request: FixtureRequest, engine: Engine, sqlalchemy_manage_db: boo
5864
sqlalchemy_utils.functions.create_database(engine.url)
5965

6066
if not sqlalchemy_keep_db:
67+
6168
def fin() -> None:
62-
print ("Tearing down DB")
69+
print("Tearing down DB")
6370
sqlalchemy_utils.functions.drop_database(engine.url)
6471

6572
request.addfinalizer(fin)
@@ -70,7 +77,7 @@ def connection(request: FixtureRequest, engine: Engine, db_schema: Optional[None
7077
connection = engine.connect()
7178

7279
def fin() -> None:
73-
print ("Closing connection")
80+
print("Closing connection")
7481
connection.close()
7582

7683
request.addfinalizer(fin)
@@ -84,7 +91,7 @@ def transaction(request: FixtureRequest, connection: Connection) -> Connection:
8491
transaction = connection.begin()
8592

8693
def fin() -> None:
87-
print ("Rollback")
94+
print("Rollback")
8895
transaction.rollback()
8996

9097
request.addfinalizer(fin)
@@ -94,6 +101,7 @@ def fin() -> None:
94101
@pytest.fixture()
95102
def dbsession(request: FixtureRequest, connection: Connection) -> Any:
96103
from sqlalchemy.orm import sessionmaker
104+
97105
return sessionmaker()(bind=connection)
98106

99107

@@ -136,22 +144,33 @@ def app_config(request: FixtureRequest) -> Optional[Mapping[str, str]]:
136144

137145

138146
def pytest_addoption(parser: Parser) -> None:
139-
parser.addoption("--sqlalchemy-connect-url", action="store",
140-
default=None,
141-
help="Name of the database to connect to")
142-
143-
parser.addoption("--sqlalchemy-config-file", action="store",
144-
default=None,
145-
help="Path to a config file containing the "
146-
"'sqlalchemy.url' variable in the DEFAULT section "
147-
"of a ini file to define the connect "
148-
"url.")
149-
150-
parser.addoption("--sqlalchemy-manage-db", action="store_true",
151-
default=None,
152-
help="Automatically creates and drops database")
153-
154-
parser.addoption("--sqlalchemy-keep-db", action="store_true",
155-
default=None,
156-
help="Do not delete database after test suite, "
157-
"allowing for its reuse.")
147+
parser.addoption(
148+
"--sqlalchemy-connect-url",
149+
action="store",
150+
default=None,
151+
help="Name of the database to connect to",
152+
)
153+
154+
parser.addoption(
155+
"--sqlalchemy-config-file",
156+
action="store",
157+
default=None,
158+
help="Path to a config file containing the "
159+
"'sqlalchemy.url' variable in the DEFAULT section "
160+
"of a ini file to define the connect "
161+
"url.",
162+
)
163+
164+
parser.addoption(
165+
"--sqlalchemy-manage-db",
166+
action="store_true",
167+
default=None,
168+
help="Automatically creates and drops database",
169+
)
170+
171+
parser.addoption(
172+
"--sqlalchemy-keep-db",
173+
action="store_true",
174+
default=None,
175+
help="Do not delete database after test suite, allowing for its reuse.",
176+
)

tests/examples/test_xdist.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from sqlalchemy.engine import Engine
22

3+
34
def test_one(engine: Engine) -> None:
45
db_name = str(engine.url.database) if engine.url.database is not None else ""
56
assert '_gw' in db_name
67

8+
79
def test_two(engine: Engine) -> None:
810
db_name = str(engine.url.database) if engine.url.database is not None else ""
911
assert '_gw' in db_name

tests/test_plugin.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ def test_dbsession_fixture(pytester: Pytester, db_url: str) -> None:
2828
def test_db_schema(pytester: Pytester, new_db_url: str) -> None:
2929
assert not database_exists(new_db_url)
3030
pytester.copy_example("tests/examples/test_db_schema.py")
31-
result = pytester.runpytest(
32-
'--sqlalchemy-connect-url', new_db_url, '--sqlalchemy-manage-db'
33-
)
31+
result = pytester.runpytest('--sqlalchemy-connect-url', new_db_url, '--sqlalchemy-manage-db')
3432
result.assert_outcomes(passed=1)
3533
assert not database_exists(new_db_url)
3634

@@ -39,9 +37,7 @@ def test_db_exists_no_keep_db(pytester: Pytester, db_url: str) -> None:
3937
if not database_exists(db_url):
4038
create_database(db_url)
4139
pytester.copy_example("tests/examples/test_db_schema.py")
42-
result = pytester.runpytest(
43-
'--sqlalchemy-connect-url', db_url, '--sqlalchemy-manage-db'
44-
)
40+
result = pytester.runpytest('--sqlalchemy-connect-url', db_url, '--sqlalchemy-manage-db')
4541
result.assert_outcomes(errors=1)
4642
assert "DB exists, remove it before proceeding" in result.stdout.str()
4743
assert database_exists(db_url)
@@ -95,14 +91,16 @@ def test_xdist_naming(pytester: Pytester, db_url: str, request: FixtureRequest)
9591
# Measuring coverage when running under xdist is pretty tricky:
9692
if running_under_coverage:
9793
pyproject_toml = Path(__file__).parent.parent / "pyproject.toml"
98-
pytester.makeconftest(dedent(f"""
94+
pytester.makeconftest(
95+
dedent(f"""
9996
import coverage, os, sys
10097
def pytest_configure(config):
10198
worker_id = os.environ.get("PYTEST_XDIST_WORKER")
10299
if worker_id is not None:
103100
os.environ["COVERAGE_PROCESS_START"] = "{pyproject_toml}"
104101
coverage.process_startup()
105-
"""))
102+
""")
103+
)
106104
pytester.copy_example("tests/examples/test_xdist.py")
107105
result = pytester.runpytest('-n', '2', '--sqlalchemy-connect-url', db_url)
108106
result.assert_outcomes(passed=2)

0 commit comments

Comments
 (0)