diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..fc48c51 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,17 @@ +on: + push: + branches: + - "*" + +jobs: + test: + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.11 + cache: pip + - name: Install shroudstone + run: pip install -e .[test] + - name: Run tests + run: python -m pytest diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..76a19dc --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,26 @@ +from pathlib import Path +from typing import NamedTuple + +import pytest + +data_dir = Path(__file__).parent / "replays" + + +def pytest_addoption(parser): + parser.addoption("--update-golden", default=False, action="store_true") + + +class ReplayCase(NamedTuple): + replay_file: Path + summary_file: Path + expected_name_file: Path + + +@pytest.fixture(params=list(data_dir.glob("**/*.SGReplay"))) +def replay_case(request): + path = request.param + yield ReplayCase( + replay_file=path, + summary_file=path.with_suffix(".json"), + expected_name_file=path.with_suffix(".txt"), + ) diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.03-18.48.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.03-18.48.SGReplay new file mode 100644 index 0000000..c6200b6 Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.03-18.48.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.03-18.48.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.03-18.48.txt new file mode 100644 index 0000000..284e82d --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.03-18.48.txt @@ -0,0 +1 @@ +2024-02-03 07.48 L 00m10s Pox IvV PeacefulBot - Boneyard.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.13-22.25.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.13-22.25.SGReplay new file mode 100644 index 0000000..2ba40db Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.13-22.25.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.13-22.25.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.13-22.25.txt new file mode 100644 index 0000000..faa4fb1 --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL44821-2024.02.13-22.25.txt @@ -0,0 +1 @@ +2024-02-13 11.25 L 04m16s Pox IvV PeacefulBot - JaggedMaw.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.22-16.42.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.22-16.42.SGReplay new file mode 100644 index 0000000..21e5a91 Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.22-16.42.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.22-16.42.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.22-16.42.txt new file mode 100644 index 0000000..108c7d7 --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.22-16.42.txt @@ -0,0 +1 @@ +2024-02-22 05.42 L 10m31s Pox IvV justasloth - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.25.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.25.SGReplay new file mode 100644 index 0000000..acc75d1 Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.25.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.25.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.25.txt new file mode 100644 index 0000000..92056ec --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.25.txt @@ -0,0 +1 @@ +2024-02-29 10.25 W 15m04s Pox IvV Frizy - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.53.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.53.SGReplay new file mode 100644 index 0000000..8142dd5 Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.53.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.53.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.53.txt new file mode 100644 index 0000000..9e1ef5f --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.02.29-21.53.txt @@ -0,0 +1 @@ +2024-02-29 10.53 L 02m13s Pox IvI 你们怎么办,只有天知道 - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.02.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.02.SGReplay new file mode 100644 index 0000000..5f1952a Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.02.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.02.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.02.txt new file mode 100644 index 0000000..86af3be --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.02.txt @@ -0,0 +1 @@ +2024-03-06 13.02 W 08m55s Pox IvV itsMerikh - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.12.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.12.SGReplay new file mode 100644 index 0000000..d1ae2c6 Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.12.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.12.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.12.txt new file mode 100644 index 0000000..5d081fc --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.12.txt @@ -0,0 +1 @@ +2024-03-06 13.12 L 12m29s Pox IvV 물망초 - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.24.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.24.SGReplay new file mode 100644 index 0000000..13cf86b Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.24.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.24.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.24.txt new file mode 100644 index 0000000..f817f3c --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-00.24.txt @@ -0,0 +1 @@ +2024-03-06 13.24 W 14m49s Pox IvV ελευθερία - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.49.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.49.SGReplay new file mode 100644 index 0000000..3217246 Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.49.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.49.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.49.txt new file mode 100644 index 0000000..158c2c4 --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.49.txt @@ -0,0 +1 @@ +2024-03-07 10.49 L 10m33s Pox IvV TOP - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.59.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.59.SGReplay new file mode 100644 index 0000000..09ac8e7 Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.59.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.59.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.59.txt new file mode 100644 index 0000000..53ca34c --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-21.59.txt @@ -0,0 +1 @@ +2024-03-07 10.59 W 17m49s Pox IvV Sturgeon - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.20.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.20.SGReplay new file mode 100644 index 0000000..b0558b2 Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.20.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.20.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.20.txt new file mode 100644 index 0000000..a6b971d --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.20.txt @@ -0,0 +1 @@ +2024-03-07 11.20 W 03m39s Pox IvI thatguy - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.41.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.41.SGReplay new file mode 100644 index 0000000..cf228d2 Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.41.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.41.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.41.txt new file mode 100644 index 0000000..79c0156 --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-22.41.txt @@ -0,0 +1 @@ +2024-03-07 11.41 W 08m14s Pox IvI indyrem - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.02.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.02.SGReplay new file mode 100644 index 0000000..c93c601 Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.02.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.02.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.02.txt new file mode 100644 index 0000000..a516ee2 --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.02.txt @@ -0,0 +1 @@ +2024-03-07 12.02 W 12m13s Pox IvI SkWizZ_SSSylas - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.15.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.15.SGReplay new file mode 100644 index 0000000..df9f94f Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.15.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.15.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.15.txt new file mode 100644 index 0000000..44a0eea --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.15.txt @@ -0,0 +1 @@ +2024-03-07 12.15 W 04m15s Pox IvI leviotus - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.21.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.21.SGReplay new file mode 100644 index 0000000..bbfa75d Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.21.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.21.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.21.txt new file mode 100644 index 0000000..ebb4a82 --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.21.txt @@ -0,0 +1 @@ +2024-03-07 12.21 L 15m13s Pox IvV albino - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.57.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.57.SGReplay new file mode 100644 index 0000000..c0cfd83 Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.57.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.57.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.57.txt new file mode 100644 index 0000000..8758504 --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.07-23.57.txt @@ -0,0 +1 @@ +2024-03-07 12.57 L 10m41s Pox IvV PrimeScout - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.05.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.05.SGReplay new file mode 100644 index 0000000..30d180f Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.05.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.05.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.05.txt new file mode 100644 index 0000000..0d8724c --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.05.txt @@ -0,0 +1 @@ +2024-03-10 06.05 W 06m29s Pox IvV Dutchy - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.12.SGReplay b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.12.SGReplay new file mode 100644 index 0000000..00a059f Binary files /dev/null and b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.12.SGReplay differ diff --git a/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.12.txt b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.12.txt new file mode 100644 index 0000000..4a5d426 --- /dev/null +++ b/tests/replays/c6b4eb4e-4994-4e96-b098-3e1953a02033/CL45737-2024.03.10-17.12.txt @@ -0,0 +1 @@ +2024-03-10 06.12 W 03m39s Pox IvI Warm Milk - BrokenCrown.SGReplay \ No newline at end of file diff --git a/tests/test_renamer.py b/tests/test_renamer.py new file mode 100644 index 0000000..85a03bf --- /dev/null +++ b/tests/test_renamer.py @@ -0,0 +1,18 @@ +from shroudstone.renamer import Replay, new_name_for +from tests.conftest import ReplayCase + +f1v1 = "{time:%Y-%m-%d %H.%M} {result:.1} {duration} {us} {f1:.1}v{f2:.1} {them} - {map_name}.SGReplay" +fgeneric = ( + "{time:%Y-%m-%d %H.%M} {duration} {players_with_factions} - {map_name}.SGReplay" +) + + +def test_replay_renaming(replay_case: ReplayCase, request): + replay = Replay.from_path(replay_case.replay_file) + assert replay is not None + new_name = new_name_for(replay, format_1v1=f1v1, format_generic=fgeneric) + assert isinstance(new_name, str) + if request.config.getoption("--update-golden"): + replay_case.expected_name_file.write_text(new_name) + else: + assert new_name == replay_case.expected_name_file.read_text()