Merge branch 'fix-sawarnings' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m44s
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m44s
Reviewed-on: #7
This commit is contained in:
commit
a8b4bca79d
5 changed files with 27 additions and 12 deletions
|
|
@ -31,7 +31,8 @@ def include_object(obj, _name, type_, _reflected, _compare_to):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
engine = sa.create_engine(velofy_config.DATABASE_URI)
|
# Without a `pool`, the `connection` really closes after the migrations
|
||||||
|
engine = sa.create_engine(velofy_config.DATABASE_URI, poolclass=sa.pool.NullPool)
|
||||||
|
|
||||||
test_schema = f"_{velofy_config.CLEAN_SCHEMA}" if os.getenv("TESTING") else ""
|
test_schema = f"_{velofy_config.CLEAN_SCHEMA}" if os.getenv("TESTING") else ""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -409,7 +409,7 @@ env = [
|
||||||
]
|
]
|
||||||
|
|
||||||
filterwarnings = [
|
filterwarnings = [
|
||||||
"ignore:::patsy.*",
|
"error", # Turn all warnings into errors
|
||||||
]
|
]
|
||||||
|
|
||||||
markers = [
|
markers = [
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,9 @@ class Grid(meta.Base):
|
||||||
Returns:
|
Returns:
|
||||||
grid: including `grid.pixels` with the associated `city.addresses`
|
grid: including `grid.pixels` with the associated `city.addresses`
|
||||||
"""
|
"""
|
||||||
grid = cls(city=city, side_length=side_length)
|
grid = cls(side_length=side_length)
|
||||||
|
|
||||||
|
city.grids.append(grid)
|
||||||
|
|
||||||
# `Pixel`s grouped by `.n_x`-`.n_y` coordinates.
|
# `Pixel`s grouped by `.n_x`-`.n_y` coordinates.
|
||||||
pixels = {}
|
pixels = {}
|
||||||
|
|
@ -102,7 +104,9 @@ class Grid(meta.Base):
|
||||||
n_x, n_y = address.x // side_length, address.y // side_length
|
n_x, n_y = address.x // side_length, address.y // side_length
|
||||||
# ... and create a new `Pixel` object if necessary.
|
# ... and create a new `Pixel` object if necessary.
|
||||||
if (n_x, n_y) not in pixels:
|
if (n_x, n_y) not in pixels:
|
||||||
pixels[(n_x, n_y)] = db.Pixel(grid=grid, n_x=n_x, n_y=n_y)
|
pixels[(n_x, n_y)] = db.Pixel(n_x=n_x, n_y=n_y)
|
||||||
|
grid.pixels.append(pixels[(n_x, n_y)])
|
||||||
|
|
||||||
pixel = pixels[(n_x, n_y)]
|
pixel = pixels[(n_x, n_y)]
|
||||||
|
|
||||||
# Create an association between the `address` and `pixel`.
|
# Create an association between the `address` and `pixel`.
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ in the CLI layer need access to the database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import warnings
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
@ -92,7 +91,8 @@ def db_session(db_connection):
|
||||||
|
|
||||||
# Create a session bound to the same connection as the `transaction`.
|
# Create a session bound to the same connection as the `transaction`.
|
||||||
# Using any other session would not result in the roll back.
|
# Using any other session would not result in the roll back.
|
||||||
session = orm.sessionmaker()(bind=db_connection)
|
# Commits inside a test case then only release a savepoint.
|
||||||
|
session = orm.Session(bind=db_connection, join_transaction_mode="create_savepoint")
|
||||||
|
|
||||||
# Monkey patch the package's global `session` object,
|
# Monkey patch the package's global `session` object,
|
||||||
# which is used heavily in the code base.
|
# which is used heavily in the code base.
|
||||||
|
|
@ -104,8 +104,7 @@ def db_session(db_connection):
|
||||||
finally:
|
finally:
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
with warnings.catch_warnings(record=True):
|
transaction.rollback()
|
||||||
transaction.rollback()
|
|
||||||
|
|
||||||
|
|
||||||
# Import the fixtures from the `fake_data` sub-package.
|
# Import the fixtures from the `fake_data` sub-package.
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,11 @@ def make_address(city):
|
||||||
|
|
||||||
def func(**kwargs):
|
def func(**kwargs):
|
||||||
"""Create an `Address` object in the `city`."""
|
"""Create an `Address` object in the `city`."""
|
||||||
return factories.AddressFactory.build(city=city, **kwargs)
|
address = factories.AddressFactory.build(**kwargs)
|
||||||
|
|
||||||
|
city.addresses.append(address)
|
||||||
|
|
||||||
|
return address
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
@ -58,7 +62,11 @@ def make_restaurant(make_address):
|
||||||
if address is None:
|
if address is None:
|
||||||
address = make_address()
|
address = make_address()
|
||||||
|
|
||||||
return factories.RestaurantFactory.build(address=address, **kwargs)
|
restaurant = factories.RestaurantFactory.build(**kwargs)
|
||||||
|
|
||||||
|
address.restaurants.append(restaurant)
|
||||||
|
|
||||||
|
return restaurant
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
@ -93,15 +101,18 @@ def make_order(make_address, make_courier, make_customer, make_restaurant):
|
||||||
if courier is None:
|
if courier is None:
|
||||||
courier = make_courier()
|
courier = make_courier()
|
||||||
|
|
||||||
return factory_cls.build(
|
order = factory_cls.build(
|
||||||
customer=make_customer(), # assume a unique `Customer` per order
|
customer=make_customer(), # assume a unique `Customer` per order
|
||||||
restaurant=restaurant,
|
|
||||||
courier=courier,
|
courier=courier,
|
||||||
pickup_address=restaurant.address, # no `Address` history
|
pickup_address=restaurant.address, # no `Address` history
|
||||||
delivery_address=make_address(), # unique `Customer` => new `Address`
|
delivery_address=make_address(), # unique `Customer` => new `Address`
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
restaurant.orders.append(order)
|
||||||
|
|
||||||
|
return order
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue