Commit graph velofy/tests/db
Author SHA1 Message Date
2f1afd459f
Break multi-line comments before conjunctions 2026-12-03 10:13:13 +01:00
049a5f6f62
Remove periods from one-sentence comments 2026-12-03 10:04:43 +01:00
732a74be1c
Declare __all__ in all re-exporting packages
Then, the linters know the imports are re-exports and not unused.
2026-12-03 09:44:07 +01:00
bbd7d6a279
Store Path._directions as a JSON array
The column is of type `JSON`,
but the code stored a JSON-encoded string in it;
so, the data was encoded twice.

A later data migration converts the existing rows.
2026-12-02 09:03:49 +01:00
fc185fa3c0
Create the engine and the session on first use
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m47s
The global `db.session` is now a `scoped_session`,
like, for example, in Flask-SQLAlchemy.

Importing the package no longer creates an engine;
so, the placeholder for the tests is obsolete.

The `db_session` fixture replaces `db.session` with `monkeypatch`
such that it is reset after each test.

Tests without the fixture get a placeholder that fails loudly
instead of opening a real session,
which would block the `DROP SCHEMA` at the end of the test run.
2026-12-02 00:23:41 +01:00
9d98021b11
Request the db_session fixture
The test queries the database but relied on the
global `db.session` that the previous test had left behind.
2026-12-02 00:19:51 +01:00
2eb6b5769f
Query with select() in Pixel
`Session.query()` is the legacy API in SQLAlchemy 2.x.

The addresses with restaurants are now selected with a subquery in one statement.

The `_restaurants_mock` fixture mocks the new call chain.
2026-12-01 23:45:35 +01:00
53e1859ee8
Query with select() in Grid and Path
`Session.query()` is the legacy API in SQLAlchemy 2.x.

Unlike `Query`, `select()` does not deduplicate single entities from a `JOIN`;
so, `Grid.gridify()` calls `.unique()` explicitly.

The `addresses_mock` fixtures mock the new call chain.
2026-12-01 23:29:39 +01:00
c1f04c65aa
Count rows with select() in the tests
`Session.query()` is the legacy API in SQLAlchemy 2.x.
2026-12-01 23:17:57 +01:00
7d53abc057
Avoid lazy loads in .__repr__()
`ReplaySimulation`, `ReplayedOrder`, and `Forecast` accessed
relationships in their `.__repr__()`, which emits queries
or fails for detached instances.

They now use the foreign key columns.
2026-12-01 22:34:38 +01:00
f532aae588
Test grids with the same side length in different cities
Regression test for the removed `unique=True` on `Grid.side_length`.
2026-12-01 22:20:06 +01:00
8abc93987e
Generate the fake coordinates as floats
Also, remove the misleading comment in `Location`
2026-12-01 15:27:53 +01:00
784d5c8ca0
Enable "warn_unreachable"
Also, remove the dead `isinstance()` check in `Location.relate_to()`
2026-12-01 13:07:53 +01:00
0090145b65
Capitalize the explanations after "=>" 2026-11-30 23:27:31 +01:00
c56fe649b7
Enable RUF in ruff 2026-11-30 23:17:41 +01:00
ae2dc8db64
Enable EM in flake8 and ruff 2026-11-30 22:59:41 +01:00
5beb88559f
Enable FBT in flake8 and ruff 2026-11-30 22:43:35 +01:00
3bd7dd5772
Enable RET in flake8 and ruff 2026-11-30 22:06:42 +01:00
007998372f
Enable SIM in flake8 and ruff 2026-11-30 22:06:41 +01:00
07660ecff9
Import geopy.distance as geo_distance everywhere 2026-11-30 20:01:42 +01:00
d660f0cc4e
Import googlemaps as gm everywhere 2026-11-30 20:01:41 +01:00
aa1a7c796f
Register the shared fixtures via pytest_plugins
That is the documented way to share fixtures from other modules,
instead of importing them into tests/conftest.py
2026-11-30 15:03:27 +01:00
e30b3efbe8
Use the sa alias for sqlalchemy everywhere
`sa` is the common alias, also in SQLAlchemy's own documentation
2026-11-30 14:18:05 +01:00
607055d55a
Raise an error if Path._directions is not set ...
... instead of failing inside `json.loads()` on `None`
2026-11-30 12:50:31 +01:00
744d9a6353
Raise an error if an Order timestamp is not set
Like `Order.time_to_delivery` already does,
instead of failing with a `TypeError` on `None`
2026-11-30 12:43:33 +01:00
ee5a372b2b
Link new objects from the parent
Since SQLAlchemy 2.0, only the parent's end
cascades a new object into the session'
2026-11-30 10:40:27 +01:00
a24db98262
Enable PLR in ruff
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m43s
2026-11-28 04:57:25 +01:00
e451f03d0f
Add ruff to the "format" session
`ruff format` adds parentheses around multi-line lambda bodies
and removes blank lines after block openers,
both of which `black` accepts.

Lines with `# type:ignore` are shortened
because `black` counts pragma comments toward the line length
and `ruff` does not.
2026-11-28 04:44:52 +01:00
4a81403f15
Replace darglint with pydoclint 2026-11-28 04:06:53 +01:00
afe8b3ce90
Apply shared fixtures to whole test classes 2026-11-28 03:52:11 +01:00
882d3c98ba
Add flake8-unused-arguments
- Request fixtures only needed for their side effects
  via `@pytest.mark.usefixtures()` instead of as arguments
- Remove fixtures that a test does not use at all
- Exempt abstract methods because their arguments define an interface
2026-11-28 03:48:50 +01:00
ea8f1a13e3
Use double quotes 2026-11-28 03:26:13 +01:00
7b32ffc599
Add flake8-docstrings 2026-11-28 03:26:12 +01:00
7f14c9c855
Add flake8-commas 2026-11-28 03:26:11 +01:00
137b3b1e03
Remove the config of flake8-expression-complexity 2026-11-28 03:26:10 +01:00
9fcb3c8c14
Remove all "WPS" codes 2026-11-28 03:25:20 +01:00
042256eb99
Switch to Python 3.13
All checks were successful
CI / Tests (Python 3.13) (push) Successful in 1m17s
The dependencies stay in the same series as on Python 3.8
where those support 3.13.

Only the unavoidable upgrades are taken:
 - `matplotlib` to v3.9
 - `numpy` to v2.1
 - `pandas` to v2.2
 - `scipy` (via statsmodels)

Required code changes:
- `numpy` v2.1 prints its scalars as `np.float64(...)`,
  which `psycopg2` then writes into the SQL
  => Adjust `Forecast.from_dataframe()` to convert the
     rounded values into plain `float`s
- Python 3.12 no longer accepts `float`s in `random.randint()`
  => The test factories now pass the seconds as `int`s

CI and `nox` use a `u`v-managed Python, which ships the C headers
needed to build `psycopg2` and `rpy2`.

`flake8` v4 does not run on Python 3.12+
and is upgraded in a future commit.
2026-11-25 11:30:33 +01:00
dbdce83067
Upgrade black 2026-11-25 10:30:47 +01:00
4855209392
Rename the urban_meal_delivery package into velofy 2026-11-23 18:06:53 +01:00
419c7e6bf6
Add tests for the Order ORM model
- so far, the check constraints were untested
  + the tests mirror the tests for the `ReplayedOrder` model
    with some variations
- shorten some import names
- fix some typos
2021-09-16 12:05:22 +02:00
e4e543bd40
Add ORM models for the simulation data
- add new ORM models `ReplaySimulation` and `ReplayedOrder`
  to store the data generated by the routing simulations
- add migrations script to create the corresponding database tables
  + create "replay_simulations" and "replayed_orders" tables
  + add missing check constraints to "orders" table
  + add unique constraint to "orders" table to enable compound key
  + drop unnecessary check constraints from the "orders" table
- add tests for the new ORM models
  + add `simulation`, `replayed_order`, `make_replay_order()`, and
    `pre_order` fixtures
  + add `ReplayedOrderFactor` faker class
- fix some typos
2021-09-16 11:58:55 +02:00
41f75f507d
Use a unified DATE constant for convenience 2021-09-16 11:53:40 +02:00
f0eb9d3b6f
There is no 'too complex function'
We check a function's cognitive complexity only with `mccabe` (=C901)
and not with WPS231 as the two overlap in most cases.
2021-09-15 14:51:56 +02:00
6091ad95c6
Fix failing tests due to randomization 2021-09-15 12:00:03 +02:00
f891fac3dc
Refactor tests.db.fake_data.factories into a package 2021-09-15 11:58:17 +02:00
2449492aba
Add Path.from_order() convenience method
Special case of `Path.from_addresses()` to create a single
`Path` object from an `Order.restaurant` to the `Customer`.
2021-09-13 09:57:25 +02:00
2d324b77eb
Rename DistanceMatrix into Path
- a `Path` is a better description for an instance of the model
- the `Location`s en route are renamed into `.waypoints`
- generic `assoc` is renamed into `path` in the test suite
2021-09-12 17:33:48 +02:00
1c19da2f70
Solve all issues detected by PyCharm
- as of September 2021, PyCharm is used to write some of the code
- PyCharm's built-in code styler, linter, and type checker issued
  some warnings that are resolved in this commit
  + spelling mistakes
  + all instance attributes must be specified explicitly
    in a class's __init__() method
    => use `functools.cached_property` for caching
  + make `tuple`s explicit with `(...)`
  + one test failed randomly although everything is ok
    => adjust the fixture's return value (stub for Google Directions API)
  + reformulate SQL so that PyCharm can understand the symbols
2021-09-12 16:51:12 +02:00
db715edd6d
Add constructor for the DistanceMatrix class
- `DistanceMatrix.from_addresses()` takes a variable number of
  `Address` objects and creates distance matrix entries for them
- as a base measure, the air distance between two `Address`
  objects is calculated
- in addition, an integration with the Google Maps Directions API is
  implemented that provides a more realistic measure of the distance
  and duration a rider on a bicycle would need to travel between two
  `Address` objects
- add a `Location.lat_lng` convenience property that provides the
  `.latitude` and `.longitude` of an `Address` as a 2-`tuple`
2021-09-12 16:51:10 +02:00
cc75307e5a
Add DistanceMatrix class
- the class stores the data of a distance matrix between all addresses
  + air distances
  + bicycle distances
- in addition, the "path" returned by the Google Directions API are
  also stored as a JSON serialized sequence of latitude-longitude pairs
- we assume a symmetric graph
2021-09-12 16:51:10 +02:00