This project creates and tests an SQLite database for managing ships and their components (weapons, hulls, and engines).
wargaming_task/
├── create_and_fill_db.py # Database creation and population script
├── conftest.py # pytest configuration and fixtures
├── test_ships.py # Test suite for ship components
├── wargaming.db # Generated SQLite database (created when script runs)
└── README.md # This file
The database consists of four tables:
ship(TEXT, PRIMARY KEY) - Ship identifierweapon(TEXT) - Foreign reference to weapons tablehull(TEXT) - Foreign reference to hulls tableengine(TEXT) - Foreign reference to engines table
weapon(TEXT, PRIMARY KEY) - Weapon identifierreload_speed(INTEGER) - Weapon reload speed (1-20)rotational_speed(INTEGER) - Weapon rotation speed (1-20)diameter(INTEGER) - Weapon diameter (1-20)power_volley(INTEGER) - Weapon power volley (1-20)count(INTEGER) - Weapon count (1-20)
hull(TEXT, PRIMARY KEY) - Hull identifierarmor(INTEGER) - Hull armor value (1-20)type(INTEGER) - Hull type (1-20)capacity(INTEGER) - Hull capacity (1-20)
engine(TEXT, PRIMARY KEY) - Engine identifierpower(INTEGER) - Engine power (1-20)type(INTEGER) - Engine type (1-20)
- Python 3.8+
- pytest (for running tests)
- Create and activate a virtual environment (optional but recommended):
python -m venv venv
.\venv\Scripts\Activate.ps1- Install dependencies:
pip install pytestRun the database creation script:
python create_and_fill_db.pyThis creates wargaming.db with default settings:
- 200 ships
- 20 weapons
- 5 hulls
- 6 engines
To specify a custom database path:
python create_and_fill_db.py path\to\custom.dbThe test suite validates ship components and verifies that randomization occurred between the original and randomized databases.
Activate virtual environment first:
.\venv\Scripts\Activate.ps1Run all tests:
pytest test_ships.py -vRun tests with output showing which components changed:
pytest test_ships.py -sRun tests for a specific ship:
pytest test_ships.py::test_component[Ship-99-engine] -v -sExpected result: All 601 tests should pass (600 component tests + 1 overall randomization test).
- Total tests: 601 tests
- 600 component tests (200 ships × 3 components per ship)
- 1 overall randomization verification test
- Components tested: weapon, hull, engine
- Test mechanism: Compares original database with a randomized copy
- Current configuration: Randomization is enabled
- Test output: Use
-sflag to see which components were randomized with before/after values
- Uses fixed seed (
RANDOM_SEED = 1337) for reproducibility - All numeric parameters are randomly generated between 1-20
- Ships are assigned random combinations of weapons, hulls, and engines
- Uses pytest with parametrization to generate tests dynamically
- Session-level fixtures create databases once for all tests
- Each test validates one ship component against the original
The conftest.py includes a _randomize_db() function that modifies the database in two modes:
- Mode A: Changes one component (weapon/hull/engine) per ship to a different random component
- Mode B: Modifies one random parameter in each component type (weapon, hull, engine) used by a ship
The randomization is active by default. For each ship, the system randomly chooses between Mode A or B.
To see which components were randomized:
pytest test_ships.py::test_component -sThis will display output like:
[CHANGED] Ship Ship-99 component 'engine':
Before: ('Engine-3', 14, 18)
After: ('Engine-3', 7, 3)
- Database uses
INSERT OR REPLACEfor idempotent operations - All tables use TEXT primary keys for component identifiers
- The script can be run multiple times - it will recreate the database each time