Skip to content

Commit

Permalink
(tests.files)(#195) refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
snake-biscuits committed Aug 31, 2024
1 parent 2b655a1 commit 171660d
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 233 deletions.
88 changes: 36 additions & 52 deletions tests/archives/id_software/test_Pak.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,46 @@
import fnmatch
import os

import pytest

from bsp_tool.archives import id_software

from ... import files


paks = dict()
archive = files.archive_dirs()
if archive.steam_dir is not None or archive.gog_dir is not None:
# {"top_dir", {"game": {"mod": ["pak_dirs"]}}}
pak_dirs = {
archive.steam_dir: {
"Hexen 2": {
"Core Game": ["data1"]},
"Quake": {
"Alkaline": ["alk1.1", "alkaline", "alkaline_dk"],
"Arcane Dimensions": ["ad"],
"Copper": ["copper"], # Underdark Overbright
"Core Game": ["hipnotic", "Id1", "rogue"],
"Prototype Jam #3": ["sm220"]},
"Quake/rerelease": {
"Core Game": ["hipnotic", "id1", "rogue"],
"Dimension of the Past": ["dopa"],
"New": ["ctf", "mg1"]},
"Quake 2": {
"Core Game": ["baseq2", "ctf", "rogue", "xatrix", "zaero"]},
"Quake 2/rerelease": {
"Core Game": ["baseq2"]}},
archive.gog_dir: {
"Soldier of Fortune": {
"Core Game": ["base"]}}}
if None in pak_dirs: # skip top_dirs not in this ArchivistStash
pak_dirs.pop(None)
# NOTE: "mod" is to give clear names to each group of mod folders
# -- not part of the path
# NOTE: Daikatana uses a different .pak format
# TODO: Heretic II
# TODO: Quake64 in %USERPROFILE%

def paks_of(top_dir: str, game: str, pak_dir: str):
full_dir = os.path.join(top_dir, game, pak_dir)
pak_filenames = fnmatch.filter(os.listdir(full_dir), "*.pak")
pak_full_paths = [
os.path.join(full_dir, pak_filename)
for pak_filename in pak_filenames]
return list(zip(pak_filenames, pak_full_paths))

paks = {
f"{game} | {mod} ({pak_dir}) | {pak_filename}": pak_full_path
for top_dir, games in pak_dirs.items()
for game, mods in games.items()
for mod, pak_dirs in mods.items()
for pak_dir in pak_dirs
for pak_filename, pak_full_path in paks_of(top_dir, game, pak_dir)}
# TODO: if a game is not installed on this device, skip it
# TODO: Heretic II
# TODO: Quake64 in %USERPROFILE%
pak_dirs: files.LibraryGames
pak_dirs = {
"Steam": {
"Hexen 2": ["Hexen 2/data1"],
"Quake": ["Quake/Id1"],
"Quake (hipnotic)": ["Quake/hipnotic"],
"Quake (rogue)": ["Quake/rogue"],
"Alkaline": ["Quake/alkaline"],
"Alkaline (alk1.1)": ["Quake/alk1.1"],
"Alkaline (alkaline_dk)": ["Quake/alkaline_dk"],
"Arcane Dimensions": ["Quake/ad"],
"Underdark Overbright": ["Quake/copper"],
"Prototype Jam #3": ["Quake/sm220"],
"Quake Re-Release": ["Quake/rerelease/id1"],
"Quake Re-Release (ctf)": ["Quake/rerelease/ctf"],
"Quake Re-Release (hipnotic)": ["Quake/rerelease/hipnotic"],
"Quake Re-Release (Machine Games)": ["Quake/rerelease/mg1"],
"Quake Re-Release (rogie)": ["Quake/rerelease/rogue"],
"Quake: Dimension of the Past": ["Quake/Rerelease/dopa"],
"Quake 2": ["Quake 2/baseq2"],
"Quake 2 (ctf)": ["Quake 2/ctf"],
"Quake 2 (rogue)": ["Quake 2/rogue"],
"Quake 2 (xatrix)": ["Quake 2/xatrix"],
"Quake 2 (zaero)": ["Quake 2/zaero"],
"Quake 2 Re-Release": ["Quake 2/rerelease/baseq2"]},
"GoG": {
"Soldier of Fortune": ["Soldier of Fortune/base"]}}


library = files.game_library()
paks = {
f"{section} | {game} | {short_path}": full_path
for section, game, paths in library.scan(pak_dirs, "*.pak")
for short_path, full_path in paths}


@pytest.mark.parametrize("filename", paks.values(), ids=paks.keys())
Expand Down
21 changes: 11 additions & 10 deletions tests/archives/ion_storm/test_Dat.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import fnmatch
import os

import pytest

from bsp_tool.archives import ion_storm

from ... import files


dats = dict()
archive = files.archive_dirs()
if archive.steam_dir is not None:
ax_dir = os.path.join(archive.steam_dir, "Anachronox/anoxdata")
dats = {
f"Anachronox | {dat_filename}": os.path.join(ax_dir, dat_filename)
for dat_filename in fnmatch.filter(os.listdir(ax_dir), "*.dat")}
dat_dirs: files.LibraryGames
dat_dirs = {
"Steam": {
"Anachronox": ["Anachronox/anoxdata"]}}


library = files.game_library()
dats = {
f"{section} | {game} | {short_path}": full_path
for section, game, paths in library.scan(dat_dirs, "*.dat")
for short_path, full_path in paths}


@pytest.mark.parametrize("filename", dats.values(), ids=dats.keys())
Expand Down
21 changes: 11 additions & 10 deletions tests/archives/ion_storm/test_Pak.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import fnmatch
import os

import pytest

from bsp_tool.archives import ion_storm

from ... import files


paks = dict()
archive = files.archive_dirs()
if archive.steam_dir is not None:
dk_dir = os.path.join(archive.steam_dir, "Daikatana/data")
paks = {
f"Daikatana | {pak_filename}": os.path.join(dk_dir, pak_filename)
for pak_filename in fnmatch.filter(os.listdir(dk_dir), "*.pak")}
pak_dirs: files.LibraryGames
pak_dirs = {
"Steam": {
"Daikatana": ["Daikatana/data"]}}


library = files.game_library()
paks = {
f"{section} | {game} | {short_path}": full_path
for section, game, paths in library.scan(pak_dirs, "*.pak")
for short_path, full_path in paths}


@pytest.mark.parametrize("filename", paks.values(), ids=paks.keys())
Expand Down
21 changes: 11 additions & 10 deletions tests/archives/padus/test_Cdi.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import fnmatch
import os

import pytest

from bsp_tool.archives import padus

from ... import files


cdis = dict()
archive = files.archive_dirs()
if archive.dreamcast_dir is not None:
dc_dir = archive.dreamcast_dir
cdis = {
f"{cdi_filename}": os.path.join(dc_dir, cdi_filename)
for cdi_filename in fnmatch.filter(os.listdir(dc_dir), "*.cdi")}
cdi_dirs: files.LibraryGames
cdi_dirs = {
"Dreamcast": {
"Disc Images": [""]}} # not looking in subdirs


library = files.game_library()
cdis = {
f"{section} | {game} | {short_path}": full_path
for section, game, paths in library.scan(cdi_dirs, "*.cdi")
for short_path, full_path in paths}


@pytest.mark.parametrize("filename", cdis.values(), ids=cdis.keys())
Expand Down
20 changes: 12 additions & 8 deletions tests/archives/pi_studios/test_Bpk.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import os

import pytest

from bsp_tool.archives import pi_studios

from ... import files


bpks = dict()
archive = files.archive_dirs()
if archive.mod_dir is not None:
# NOTE: this may be the only publically existing Pi Studios .bpk
qaa_dir = "X360/QuakeArenaArcade/"
bpks["Quake Arcade Arena | pak0.bpk"] = os.path.join(archive.mod_dir, qaa_dir, "baseq3/pak0.bpk")
# NOTE: this may be the only publically existing Pi Studios .bpk
bpk_dirs: files.LibraryGames
bpk_dirs = {
"Xbox360": {
"Quake Arena Arcade": ["QuakeArenaArcade/baseq3/"]}}


library = files.game_library()
bpks = {
f"{section} | {game} | {short_path}": full_path
for section, game, paths in library.scan(bpk_dirs, "*.bpk")
for short_path, full_path in paths}


@pytest.mark.parametrize("filename", bpks.values(), ids=bpks.keys())
Expand Down
35 changes: 11 additions & 24 deletions tests/archives/respawn/test_RPak.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
import fnmatch
import os

import pytest

from bsp_tool.archives import respawn

from ... import files


rpak_dirs = dict()
archive = files.archive_dirs()
if archive.steam_dir is not None:
steam_games = {
"Apex Legends": "paks/Win64/",
"Titanfall2": "r2/paks/Win64/"}
rpak_dirs.update({
f"Steam | {game}": os.path.join(archive.steam_dir, game, rpak_dir)
for game, rpak_dir in steam_games.items()})


if archive.mod_dir is not None:
ps4_games = {
# "Titanfall2": "r2/paks/PS4/", # TODO: v2.0.11.0 rpaks
"Titanfall2_tech_test": "r2/paks/PS4/"}
rpak_dirs.update({
f"PS4 | {game}": os.path.join(archive.mod_dir, "PS4", game, rpak_dir)
for game, rpak_dir in ps4_games.items()})
rpak_dirs: files.LibraryGames
rpak_dirs = {
"Steam": {
"Apex Legends": ["Apex Legends/paks/Win64/"],
"Titanfall 2": ["Titanfall2/r2/paks/Win64/"]},
"PS4": {
"Titanfall 2 (Tech Test)": ["Titanfall2_tech_test/r2/paks/PS4/"]}}


library = files.game_library()
rpaks = {
f"{platform_game} | {rpak_filename}": os.path.join(rpak_dir, rpak_filename)
for platform_game, rpak_dir in rpak_dirs.items()
for rpak_filename in fnmatch.filter(os.listdir(rpak_dir), "*.rpak")}
f"{section} | {game} | {short_path}": full_path
for section, game, paths in library.scan(rpak_dirs, "*.rpak")
for short_path, full_path in paths}


@pytest.mark.parametrize("filename", rpaks.values(), ids=rpaks.keys())
Expand Down
91 changes: 41 additions & 50 deletions tests/archives/respawn/test_Vpk.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,51 @@
import fnmatch
import os

import pytest

from bsp_tool.archives import respawn

from ... import files


vpk_dirs = dict()
archive = files.archive_dirs()
if archive.steam_dir is not None:
steam_games = ["Titanfall", "Titanfall2"]
vpk_dirs.update({
game: os.path.join(archive.steam_dir, game, "vpk/")
for game in steam_games})

if archive.mod_dir is not None:
vpk_dirs.update({
"Titanfall (Beta)": os.path.join(archive.mod_dir, "Titanfall/beta/vpk/")})
apex_archive = [
["4feb19"],
["19mar19", "16apr19", "4jun19"],
["2jul19", "13aug19", "3sep19"],
# TODO: get season3 5nov19 & 3dec19 vpk/ folders from rexx
# -- ["1oct19", "5nov19", "3dec19"],
["1oct19"],
["4feb20", "3mar20", "7apr20"],
["12may20", "23jun20"],
["18aug20", "6oct20"],
["3nov20", "5jan21"],
["2feb21", "9mar21"],
["4may21", "29jun21"]]
# TODO: download season10 -> season17 vpk/ folders with steamcmd
# -- ["3aug21", "10aug21", "14sep21", "24sep21"],
# -- ["2nov21", "5nov21", "17nov21"],
# -- ["8feb22", "29mar22"],
# -- ["10may22", "21jun22"],
# -- ["9aug22", "20sep22", "14oct22"],
# -- ["1nov22", "10jan23"],
# -- ["14feb23", "28mar23"],
# -- ["9may23", "19jun23", "20jul23"]]
# NOTE: season18 onwards ships with no `.vpk`s
vpk_dirs.update({
f"Apex Legends | Season {i} | {patch}": os.path.join(archive.mod_dir, f"ApexLegends/season{i}/{patch}/vpk/")
for i, season in enumerate(apex_archive)
for patch in season})


vpks = dict()
for game, vpk_dir in vpk_dirs.items():
if not os.path.exists(vpk_dir):
continue # coplandbentokom-9876 only has a small subset of the archive
for vpk_filename in fnmatch.filter(os.listdir(vpk_dir), "*_dir.vpk"):
full_path = os.path.join(vpk_dir, vpk_filename)
vpks[f"{game} | {vpk_filename}"] = full_path
vpk_dirs: files.LibraryGames
vpk_dirs = {
"Steam": {
"Titanfall": ["Titanfall/vpk/"],
"Titanfall 2": ["Titanfall2/vpk/"]},
"Mod": {
"Titanfall (beta)": ["Titanfall/beta/vpk/"]}}

apex_season_patches = [
["4feb19"],
["19mar19", "16apr19", "4jun19"],
["2jul19", "13aug19", "3sep19"],
["1oct19"], # TODO: get season3 5nov19 & 3dec19 vpk/ folders from rexx
["4feb20", "3mar20", "7apr20"],
["12may20", "23jun20"],
["18aug20", "6oct20"],
["3nov20", "5jan21"],
["2feb21", "9mar21"],
["4may21", "29jun21"]]
# TODO: download season10 -> season17 vpk/ folders with steamcmd
# -- ["3aug21", "10aug21", "14sep21", "24sep21"],
# -- ["2nov21", "5nov21", "17nov21"],
# -- ["8feb22", "29mar22"],
# -- ["10may22", "21jun22"],
# -- ["9aug22", "20sep22", "14oct22"],
# -- ["1nov22", "10jan23"],
# -- ["14feb23", "28mar23"],
# -- ["9may23", "19jun23", "20jul23"]]
# NOTE: season18 onwards ships with no `.vpk`s

vpk_dirs["Mod"].update({
f"Apex Legends | Season {i} | {patch}": f"ApexLegends/season{i}/{patch}/vpk/"
for i, season in enumerate(apex_season_patches)
for patch in season})


library = files.game_library()
vpks = {
f"{section} | {game} | {short_path}": full_path
for section, game, paths in library.scan(vpk_dirs, "*_dir.vpk")
for short_path, full_path in paths}


@pytest.mark.parametrize("filename", vpks.values(), ids=vpks.keys())
Expand Down
4 changes: 2 additions & 2 deletions tests/archives/utoplanet/test_Apk.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


apks = dict()
archivist = files.archivist_login()
if archivist == ("bikkie", "ITANI_WAYSOUND"):
librarian = files.library_card()
if librarian == ("bikkie", "ITANI_WAYSOUND"):
apk_dir = "C:/PlayGra/Merubasu/shadowland/"
apks = {
f"Merubasu | {apk_filename}": os.path.join(apk_dir, apk_filename)
Expand Down
Loading

0 comments on commit 171660d

Please sign in to comment.