mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-01 00:27:20 -05:00
feat: list emulator files once as table rows
This commit is contained in:
1 parent
a1d094c8b3
commit
79ae046343
6 files changed
+45
-65
No files matched your search
@@ -119,7 +119,7 @@ class ASplitEmulatorListsItsCardsAsRows(unittest.TestCase):
|
||||
|
||||
class ALongEmulatorPageIsOneTable(unittest.TestCase):
|
||||
def test_rows_replace_the_index_and_the_cards(self):
|
||||
files = ([_archive(i) for i in range(gs.EMULATOR_TABLE_MIN - 10)]
|
||||
files = ([_archive(i) for i in range(gs.EMULATOR_TABLE_MIN)]
|
||||
+ [{"name": f"opt{i}.bin", "md5": f"{i:032x}"} for i in range(10)])
|
||||
page = gs.generate_emulator_page(
|
||||
"long", {"emulator": "Long", "type": "standalone", "files": files}, EMPTY_DB, None, set())
|
||||
|
||||
@@ -118,22 +118,20 @@ class RequiredFilesComeFirst(unittest.TestCase):
|
||||
page = _page("duckstation", _profile("duckstation"))
|
||||
self.assertGreater(len(re.findall(r"^## ", page, re.M)), 2)
|
||||
|
||||
def test_a_summary_table_above_the_cards(self):
|
||||
files = _files(gs.EMULATOR_SUMMARY_MIN - 1) + [
|
||||
def test_rows_carry_region_and_hash(self):
|
||||
files = _files(gs.EMULATOR_TABLE_MIN - 1) + [
|
||||
{"name": "req.bin", "required": True, "region": ["japan"], "md5": "ab" * 16}]
|
||||
page = _page("x", {"type": "standalone", "files": files})
|
||||
self.assertIn("| File | Region | Required | Hash |", page)
|
||||
row = next(line for line in page.splitlines() if "req.bin" in line and "| yes |" in line)
|
||||
self.assertIn("(#file-req-bin", row)
|
||||
self.assertIn("| Japan |", row)
|
||||
self.assertIn(f'MD5\u00a0<code title="{"ab" * 16}">{"ab" * 6}</code>', row)
|
||||
# The required row is the first one.
|
||||
table = page.index("| File | Region | Required | Hash |")
|
||||
self.assertLess(page.index("req.bin", table), page.index("f000.bin", table))
|
||||
required = page[page.index("## Required"):page.index("## Optional")]
|
||||
self.assertIn('id="file-req-bin', required)
|
||||
self.assertIn("Region: Japan", required)
|
||||
self.assertIn(f'MD5\u00a0<code title="{"ab" * 16}">{"ab" * 6}</code>', required)
|
||||
self.assertNotIn("f000.bin", required)
|
||||
|
||||
def test_no_table_for_a_few_cards(self):
|
||||
page = _page("x", {"type": "standalone", "files": _files(2)})
|
||||
self.assertNotIn("| File | Region | Required | Hash |", page)
|
||||
self.assertNotIn('class="rb-entries"', page)
|
||||
self.assertIn('class="rb-file-entry"', page)
|
||||
|
||||
def test_a_split_page_puts_required_on_the_first_part(self):
|
||||
count = gs.EMULATOR_CARDS_PER_PAGE * 2
|
||||
|
||||
@@ -102,12 +102,10 @@ class WhatTheAppShipsIsNoFileToGet(unittest.TestCase):
|
||||
section = self.page[self.page.index("## Required"):self.page.index("## Optional")]
|
||||
self.assertNotIn("Roboto-Regular.ttf", section)
|
||||
|
||||
def test_the_collection_counts_go_under_the_table(self):
|
||||
def test_the_collection_counts_go_under_the_summary(self):
|
||||
held = self.page.index("<p><small>In this collection:")
|
||||
table = self.page.index("| File |")
|
||||
self.assertLess(table, held)
|
||||
self.assertLess(held, self.page.index("## Required"))
|
||||
self.assertNotIn("in repo", self.page[self.page.index("## Files"):table])
|
||||
self.assertNotIn("in repo", self.page[self.page.index("## Files"):held])
|
||||
|
||||
def test_the_folder_is_the_apps_own(self):
|
||||
self.assertIn("| BIOS directory | `bios/`, inside the app's own data folder |", self.page)
|
||||
@@ -115,9 +113,8 @@ class WhatTheAppShipsIsNoFileToGet(unittest.TestCase):
|
||||
|
||||
class TheSummaryTableFitsItsContent(unittest.TestCase):
|
||||
def test_an_empty_region_column_goes(self):
|
||||
page = _page("aethersx2")
|
||||
table = next(line for line in page.splitlines() if line.startswith("| File |"))
|
||||
self.assertNotIn("Region", table)
|
||||
rows = gs._summary_table(_files(3, md5="ab" * 16), [0, 1, 2], lambda _i, s: s)
|
||||
self.assertNotIn("Region", rows[0])
|
||||
|
||||
def test_a_constant_required_column_goes(self):
|
||||
rows = gs._summary_table(_files(3, required=True), [0, 1, 2], lambda _i, s: s)
|
||||
@@ -138,14 +135,15 @@ class TheSummaryTableFitsItsContent(unittest.TestCase):
|
||||
|
||||
|
||||
class LongPagesFold(unittest.TestCase):
|
||||
def test_optional_cards_fold_below_the_table(self):
|
||||
files = _files(gs.EMULATOR_SUMMARY_MIN) + [{"name": "req.bin", "required": True}]
|
||||
def test_each_entry_is_listed_once_as_a_row(self):
|
||||
files = _files(gs.EMULATOR_TABLE_MIN) + [{"name": "req.bin", "required": True}]
|
||||
page = _page("x", {"type": "standalone", "files": files})
|
||||
self.assertNotIn("| File |", page)
|
||||
self.assertNotIn(f"<summary>{gs.EMULATOR_TABLE_MIN} files</summary>", page)
|
||||
self.assertEqual(page.count('<h3 id="file-'), len(files))
|
||||
required = page[page.index("## Required"):page.index("## Optional")]
|
||||
self.assertNotIn("<details", required)
|
||||
optional = page[page.index("## Optional"):]
|
||||
self.assertTrue(optional.split("\n", 3)[2].startswith("<details class=\"rb-details"))
|
||||
self.assertIn(f"<summary>{gs.EMULATOR_SUMMARY_MIN} files</summary>", optional)
|
||||
self.assertEqual(required.count('<h3 id="file-'), 1)
|
||||
self.assertIn('class="rb-entries"', required)
|
||||
|
||||
def test_a_few_cards_stay_open(self):
|
||||
page = _page("x", {"type": "standalone", "files": _files(2)})
|
||||
|
||||
@@ -134,14 +134,15 @@ class PartsKnowWhereTheySit(unittest.TestCase):
|
||||
class ARequiredFileSaysForWhichSystem(unittest.TestCase):
|
||||
def test_melonds_dsi_files(self):
|
||||
page = _pages("melonds")["melonds"]
|
||||
card = page[page.index('id="file-dsi-nand-bin"'):]
|
||||
card = card[:card.index("</h3>")]
|
||||
self.assertIn(">required for Nintendo DSi</span>", card)
|
||||
row = page[page.index('id="file-dsi-nand-bin"'):]
|
||||
row = row[:row.index("</tr>")]
|
||||
self.assertIn(">required for Nintendo DSi</span>", row)
|
||||
self.assertNotIn(">required</span>", page)
|
||||
|
||||
def test_one_system_says_required(self):
|
||||
# The section heading says it: the rows under it repeat nothing.
|
||||
page = _pages("aethersx2")["aethersx2"]
|
||||
self.assertIn(">required</span>", page)
|
||||
self.assertIn("## Required", page)
|
||||
self.assertNotIn("required for", page)
|
||||
|
||||
|
||||
|
||||
@@ -293,13 +293,17 @@ class _Head(HTMLParser):
|
||||
self._ld: list[str] | None = None
|
||||
self._label: list[str] | None = None
|
||||
self._tabs = False
|
||||
# A summary in the page body (a file row) is no sidebar group.
|
||||
self._main = False
|
||||
|
||||
def handle_starttag(self, tag: str, attrs: list) -> None:
|
||||
a = dict(attrs)
|
||||
if tag == "script" and a.get("type") == "application/ld+json":
|
||||
self._ld = []
|
||||
if tag == "summary":
|
||||
if tag == "summary" and self._main:
|
||||
self._label = []
|
||||
if tag == "nav" and a.get("aria-label") == "Main":
|
||||
self._main = True
|
||||
if tag == "nav" and a.get("aria-label") == "Sections":
|
||||
self._tabs = True
|
||||
elif self._tabs and tag == "a" and a.get("aria-current"):
|
||||
@@ -308,6 +312,7 @@ class _Head(HTMLParser):
|
||||
def handle_endtag(self, tag: str) -> None:
|
||||
if tag == "nav":
|
||||
self._tabs = False
|
||||
self._main = False
|
||||
if tag == "script" and self._ld is not None:
|
||||
self.ld.append(json.loads("".join(self._ld)))
|
||||
self._ld = None
|
||||
|
||||
Reference in new issue
Block a user