From 54ef6956a8370e275ea616945c6a1bb538f82121 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 16 Jun 2024 13:34:33 +0300 Subject: [PATCH] chore: Move tests outside main package --- .../commands/paikkala_load_demo_data.py | 10 ++++---- .../Sibeliustalo_paasali_paikkanumerointi.pdf | Bin .../tests => paikkala_tests}/__init__.py | 0 .../_generate_sibeliustalo_qualifiers.py | 0 .../tests => paikkala_tests}/conftest.py | 10 ++++---- .../tests => paikkala_tests}/demo_data.py | 22 ++++++++++-------- .../sibeliustalo-qualifiers.txt | 0 .../tests => paikkala_tests}/sibeliustalo.txt | 0 .../tests => paikkala_tests}/test_admin.py | 0 .../tests => paikkala_tests}/test_blocks.py | 0 .../test_demo_data.py | 0 .../tests => paikkala_tests}/test_paikkala.py | 4 +--- .../tests => paikkala_tests}/test_printing.py | 0 .../test_qualifiers.py | 0 .../tests => paikkala_tests}/test_ranges.py | 0 .../tests => paikkala_tests}/test_runs.py | 0 .../tests => paikkala_tests}/test_views.py | 0 .../tests => paikkala_tests}/test_workshop.py | 0 pyproject.toml | 5 +++- 19 files changed, 27 insertions(+), 24 deletions(-) rename {paikkala/tests => paikkala_tests}/Sibeliustalo_paasali_paikkanumerointi.pdf (100%) rename {paikkala/tests => paikkala_tests}/__init__.py (100%) rename {paikkala/tests => paikkala_tests}/_generate_sibeliustalo_qualifiers.py (100%) rename {paikkala/tests => paikkala_tests}/conftest.py (89%) rename {paikkala/tests => paikkala_tests}/demo_data.py (87%) rename {paikkala/tests => paikkala_tests}/sibeliustalo-qualifiers.txt (100%) rename {paikkala/tests => paikkala_tests}/sibeliustalo.txt (100%) rename {paikkala/tests => paikkala_tests}/test_admin.py (100%) rename {paikkala/tests => paikkala_tests}/test_blocks.py (100%) rename {paikkala/tests => paikkala_tests}/test_demo_data.py (100%) rename {paikkala/tests => paikkala_tests}/test_paikkala.py (98%) rename {paikkala/tests => paikkala_tests}/test_printing.py (100%) rename {paikkala/tests => paikkala_tests}/test_qualifiers.py (100%) rename {paikkala/tests => paikkala_tests}/test_ranges.py (100%) rename {paikkala/tests => paikkala_tests}/test_runs.py (100%) rename {paikkala/tests => paikkala_tests}/test_views.py (100%) rename {paikkala/tests => paikkala_tests}/test_workshop.py (100%) diff --git a/paikkala/management/commands/paikkala_load_demo_data.py b/paikkala/management/commands/paikkala_load_demo_data.py index 9900355..bf52c09 100644 --- a/paikkala/management/commands/paikkala_load_demo_data.py +++ b/paikkala/management/commands/paikkala_load_demo_data.py @@ -9,7 +9,7 @@ from paikkala.excs import NoCapacity from paikkala.models import Zone -from paikkala.tests.demo_data import ( +from paikkala_tests.demo_data import ( SIBELIUSTALO_DEFAULT_ROOM_NAME, create_jussi_program, import_sibeliustalo_zones, @@ -18,25 +18,25 @@ class Command(BaseCommand): def add_arguments(self, parser: ArgumentParser) -> None: - parser.add_argument('--yes', '-y', default=False, action='store_true') + parser.add_argument("--yes", "-y", default=False, action="store_true") @atomic def handle(self, yes: bool, **options: Any) -> None: if not yes: - self.stderr.write('this command requires the --yes parameter, as it will mess up your database') + self.stderr.write("this command requires the --yes parameter, as it will mess up your database") return sibeliustalo_zones = list(Zone.objects.filter(room__name=SIBELIUSTALO_DEFAULT_ROOM_NAME)) if not sibeliustalo_zones: sibeliustalo_zones = import_sibeliustalo_zones() room = sibeliustalo_zones[0].room program = room.program_set.first() or create_jussi_program(sibeliustalo_zones, room=room) - user = User.objects.create_user(f'random-demo-{get_random_string(12)}') + user = User.objects.create_user(f"random-demo-{get_random_string(12)}") prog_zones = list(program.zones) for _ in range(10): zone = random.choice(prog_zones) count = random.randint(1, 5) try: tickets = list(program.reserve(zone=zone, count=count, user=user)) - self.stdout.write(f'{user}: Reserved {len(tickets):d} tickets in {zone.name}') + self.stdout.write(f"{user}: Reserved {len(tickets):d} tickets in {zone.name}") except NoCapacity: break diff --git a/paikkala/tests/Sibeliustalo_paasali_paikkanumerointi.pdf b/paikkala_tests/Sibeliustalo_paasali_paikkanumerointi.pdf similarity index 100% rename from paikkala/tests/Sibeliustalo_paasali_paikkanumerointi.pdf rename to paikkala_tests/Sibeliustalo_paasali_paikkanumerointi.pdf diff --git a/paikkala/tests/__init__.py b/paikkala_tests/__init__.py similarity index 100% rename from paikkala/tests/__init__.py rename to paikkala_tests/__init__.py diff --git a/paikkala/tests/_generate_sibeliustalo_qualifiers.py b/paikkala_tests/_generate_sibeliustalo_qualifiers.py similarity index 100% rename from paikkala/tests/_generate_sibeliustalo_qualifiers.py rename to paikkala_tests/_generate_sibeliustalo_qualifiers.py diff --git a/paikkala/tests/conftest.py b/paikkala_tests/conftest.py similarity index 89% rename from paikkala/tests/conftest.py rename to paikkala_tests/conftest.py index ca79448..7273f4d 100644 --- a/paikkala/tests/conftest.py +++ b/paikkala_tests/conftest.py @@ -6,7 +6,7 @@ from django.utils.timezone import now from paikkala.models import Program, Room, Row, Zone -from paikkala.tests.demo_data import ( +from paikkala_tests.demo_data import ( create_jussi_program, create_scatter_program, create_workshop_program, @@ -54,14 +54,14 @@ def workshop_program(workshop_room, workshop_row): @pytest.fixture def lattia_program(): - room = Room.objects.create(name='huone') - zone = Zone.objects.create(name='lattia', room=room) - row = Row.objects.create(zone=zone, start_number=1, end_number=10, excluded_numbers='3,4,5') + room = Room.objects.create(name="huone") + zone = Zone.objects.create(name="lattia", room=room) + row = Row.objects.create(zone=zone, start_number=1, end_number=10, excluded_numbers="3,4,5") assert row.capacity == 7 t = now() program = Program.objects.create( room=zone.room, - name='program', + name="program", max_tickets=100, reservation_start=t, reservation_end=t + timedelta(days=1), diff --git a/paikkala/tests/demo_data.py b/paikkala_tests/demo_data.py similarity index 87% rename from paikkala/tests/demo_data.py rename to paikkala_tests/demo_data.py index dae4537..3b37c17 100644 --- a/paikkala/tests/demo_data.py +++ b/paikkala_tests/demo_data.py @@ -59,16 +59,18 @@ def create_scatter_program(zones: list[Zone], room=None): row: Row for row in zone.rows.all(): # Leave one seat per row - _ = list(row.reserve( - program=program, - count=row.capacity - 1, - user=None, - name='Señor Developer', - email='test@localhost', - phone=None, - attempt_sequential=False, - excluded_numbers=None, - )) + _ = list( + row.reserve( + program=program, + count=row.capacity - 1, + user=None, + name='Señor Developer', + email='test@localhost', + phone=None, + attempt_sequential=False, + excluded_numbers=None, + ) + ) status = zone.get_reservation_status(program) assert status.total_remaining == zone.rows.count() diff --git a/paikkala/tests/sibeliustalo-qualifiers.txt b/paikkala_tests/sibeliustalo-qualifiers.txt similarity index 100% rename from paikkala/tests/sibeliustalo-qualifiers.txt rename to paikkala_tests/sibeliustalo-qualifiers.txt diff --git a/paikkala/tests/sibeliustalo.txt b/paikkala_tests/sibeliustalo.txt similarity index 100% rename from paikkala/tests/sibeliustalo.txt rename to paikkala_tests/sibeliustalo.txt diff --git a/paikkala/tests/test_admin.py b/paikkala_tests/test_admin.py similarity index 100% rename from paikkala/tests/test_admin.py rename to paikkala_tests/test_admin.py diff --git a/paikkala/tests/test_blocks.py b/paikkala_tests/test_blocks.py similarity index 100% rename from paikkala/tests/test_blocks.py rename to paikkala_tests/test_blocks.py diff --git a/paikkala/tests/test_demo_data.py b/paikkala_tests/test_demo_data.py similarity index 100% rename from paikkala/tests/test_demo_data.py rename to paikkala_tests/test_demo_data.py diff --git a/paikkala/tests/test_paikkala.py b/paikkala_tests/test_paikkala.py similarity index 98% rename from paikkala/tests/test_paikkala.py rename to paikkala_tests/test_paikkala.py index 317b5a5..3add148 100644 --- a/paikkala/tests/test_paikkala.py +++ b/paikkala_tests/test_paikkala.py @@ -145,6 +145,4 @@ def test_automatic_max_tickets(jussi_program): def test_attempt_sequential(lattia_program, attempt_sequential): zone = lattia_program.zones[0] tickets = list(lattia_program.reserve(zone=zone, count=3, attempt_sequential=attempt_sequential)) - assert [t.number for t in tickets] == ( - [1, 2, 6] if not attempt_sequential else [6, 7, 8] - ) + assert [t.number for t in tickets] == ([1, 2, 6] if not attempt_sequential else [6, 7, 8]) diff --git a/paikkala/tests/test_printing.py b/paikkala_tests/test_printing.py similarity index 100% rename from paikkala/tests/test_printing.py rename to paikkala_tests/test_printing.py diff --git a/paikkala/tests/test_qualifiers.py b/paikkala_tests/test_qualifiers.py similarity index 100% rename from paikkala/tests/test_qualifiers.py rename to paikkala_tests/test_qualifiers.py diff --git a/paikkala/tests/test_ranges.py b/paikkala_tests/test_ranges.py similarity index 100% rename from paikkala/tests/test_ranges.py rename to paikkala_tests/test_ranges.py diff --git a/paikkala/tests/test_runs.py b/paikkala_tests/test_runs.py similarity index 100% rename from paikkala/tests/test_runs.py rename to paikkala_tests/test_runs.py diff --git a/paikkala/tests/test_views.py b/paikkala_tests/test_views.py similarity index 100% rename from paikkala/tests/test_views.py rename to paikkala_tests/test_views.py diff --git a/paikkala/tests/test_workshop.py b/paikkala_tests/test_workshop.py similarity index 100% rename from paikkala/tests/test_workshop.py rename to paikkala_tests/test_workshop.py diff --git a/pyproject.toml b/pyproject.toml index ada3233..e3aa12d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,10 +82,13 @@ max-complexity = 10 "ANN003", "ANN201", ] -"*/tests/*.py" = [ +"paikkala_tests/*.py" = [ "ANN", ] "*/migrations/*.py" = [ "ANN", "E501", ] + +[tool.ruff.format] +quote-style = "preserve"