Skip to content

Commit

Permalink
Add unit test for renamer.new_name_for
Browse files Browse the repository at this point in the history
  • Loading branch information
acarapetis committed Jul 31, 2024
1 parent a1e2fef commit 3c3743f
Show file tree
Hide file tree
Showing 40 changed files with 89 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on:
push:
branches:
- "*"

jobs:
test:
strategy:
matrix:
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-22.04, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
cache: pip
- name: Install shroudstone
run: pip install -e .[test]
- name: Run tests
run: python -m pytest
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ dependencies = [
]
requires-python = "~=3.8"

[project.optional-dependencies]
test = [
"pytest>=8",
]

[project.urls]
Source = "https://github.com/acarapetis/shroudstone"

Expand Down
26 changes: 26 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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"),
)
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-02-03 07.48 L 00m10s Pox IvV PeacefulBot - Boneyard.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-02-13 11.25 L 04m16s Pox IvV PeacefulBot - JaggedMaw.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-02-22 05.42 L 10m31s Pox IvV justasloth - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-02-29 10.25 W 15m04s Pox IvV Frizy - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-02-29 10.53 L 02m13s Pox IvI 你们怎么办,只有天知道 - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-06 13.02 W 08m55s Pox IvV itsMerikh - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-06 13.12 L 12m29s Pox IvV 물망초 - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-06 13.24 W 14m49s Pox IvV ελευθερία - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-07 10.49 L 10m33s Pox IvV TOP - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-07 10.59 W 17m49s Pox IvV Sturgeon - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-07 11.20 W 03m39s Pox IvI thatguy - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-07 11.41 W 08m14s Pox IvI indyrem - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-07 12.02 W 12m13s Pox IvI SkWizZ_SSSylas - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-07 12.15 W 04m15s Pox IvI leviotus - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-07 12.21 L 15m13s Pox IvV albino - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-07 12.57 L 10m41s Pox IvV PrimeScout - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-10 06.05 W 06m29s Pox IvV Dutchy - BrokenCrown.SGReplay
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-10 06.12 W 03m39s Pox IvI Warm Milk - BrokenCrown.SGReplay
18 changes: 18 additions & 0 deletions tests/test_renamer.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 3c3743f

Please sign in to comment.