Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
- Added in initial unit tests for ROMParser and ROMChooser
  • Loading branch information
bbtufty committed May 23, 2024
1 parent b29f218 commit 9253f32
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ jobs:
pip install build
- name: Build package
run: python -m build
- name: Run pytest
run: |
pip install pytest
cd tests
pytest tests_romparser.py
pytest tests_romchooser.py
# build_executable:
# name: Build executable
Expand Down
8 changes: 8 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 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

0 comments on commit 9253f32

Please sign in to comment.