Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests #22

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:
matrix:
# Versions listed at https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json
python-version: [
"3.9",
"3.10",
"3.11",
"3.12",
]
Expand All @@ -35,6 +33,14 @@ jobs:
pip install build
- name: Build package
run: python -m build
- name: Run pytest
run: |
pip install -e .
pip install pytest
cd tests
pytest tests_romparser.py
pytest tests_romchooser.py


# build_executable:
# name: Build executable
Expand Down
13 changes: 13 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
0.0.7 (Unreleased)
==================

Features
--------

Tests
~~~~~

- Added in initial unit tests for ROMParser and ROMChooser

Fixes
-----

Expand All @@ -9,6 +17,11 @@ ROMParser

- ROMParser will now correctly parse multiple regions/languages

General
~~~~~~~

- Due to changes to the re module, ROMSearch requires python>=3.11

0.0.6 (2024-05-23)
==================

Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = "romsearch"
version = "0.0.6"
description = "One Stop ROM Shop"
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.11"
license = {file = "LICENSE"}

authors = [
Expand All @@ -25,8 +25,6 @@ classifiers = [

"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
Expand Down
58 changes: 58 additions & 0 deletions tests/test_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
dirs:
raw_dir: '.'
rom_dir: '.'
dat_dir: '.'
parsed_dat_dir: '.'
dupe_dir: '.'
log_dir: '.'
cache_dir: '.'

platforms:
- Nintendo - Super Nintendo Entertainment System

region_preferences:
- USA

language_preferences:
- English

include_games:
SNES:
- "Chrono Trigger"

romsearch:
method: "filter_then_download"
run_romdownloader: true
run_datparser: true
run_dupeparser: true
run_romchooser: true
run_rommover: false
dry_run: false

romdownloader:
dry_run: false
remote_name: 'rclone_remote'
sync_all: false

dupeparser:
use_dat: true
use_retool: true

gamefinder:
filter_dupes: true

romparser:
use_dat: false
use_retool: false
use_filename: true

romchooser:
dry_run: false
use_best_version: true
allow_multiple_regions: false
filter_regions: true
filter_languages: true
bool_filters: "all_but_games"

discord:
webhook_url: "https://discord.com/api/webhooks/discord_url"
29 changes: 29 additions & 0 deletions tests/tests_romchooser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from romsearch import ROMParser, ROMChooser

TEST_NAME = "Example Game (USA) (En,De,Fr)"


def test_romchooser_version():
"""Put a number of versions through and check ROMChooser gets the right one"""

test_case = {
TEST_NAME: {"priority": 1},
f"{TEST_NAME} (v1.00)": {"priority": 1},
f"{TEST_NAME} (v2.00)": {"priority": 1},
}

rp = ROMParser(config_file="test_config.yml",
platform="Nintendo - Super Nintendo Entertainment System",
game="Example Game",
)
rom_dict = rp.run(test_case)

rc = ROMChooser(config_file="test_config.yml",
platform="Nintendo - Super Nintendo Entertainment System",
game="Example Game",
)
rom_dict = rc.run(rom_dict)

roms_found = [r for r in rom_dict]

assert roms_found == ["Example Game (USA) (En,De,Fr) (v2.00)"]
35 changes: 35 additions & 0 deletions tests/tests_romparser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from romsearch import ROMParser

TEST_NAME = "Example Game (USA) (En,De,Fr)"


def test_romparser_regions():
"""Put a filename into ROMParser and check it returns the right regions"""

expected_regions = ["USA"]

test_case = {TEST_NAME: {"priority": 1}}

rp = ROMParser(config_file="test_config.yml",
platform="Nintendo - Super Nintendo Entertainment System",
game="Example Game",
)
roms_parsed = rp.run(test_case)

assert roms_parsed[TEST_NAME]["regions"] == expected_regions


def test_romparser_languages():
"""Put a filename into ROMParser and check it returns the right languages"""

expected_languages = ["English", "French", "German"]

test_case = {TEST_NAME: {"priority": 1}}

rp = ROMParser(config_file="test_config.yml",
platform="Nintendo - Super Nintendo Entertainment System",
game="Example Game",
)
roms_parsed = rp.run(test_case)

assert roms_parsed[TEST_NAME]["languages"] == expected_languages