From 3a8f72a56ac3b39977418ba3b9ac40ce03bcb290 Mon Sep 17 00:00:00 2001 From: Guillaume Collic Date: Tue, 30 Jul 2019 00:02:18 +0200 Subject: [PATCH] Fix cards list order for accents in expansion card (#264) --- src/domdiv/main.py | 3 ++- tests/carddb_tests.py | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/domdiv/main.py b/src/domdiv/main.py index 8c168da..e4849e0 100644 --- a/src/domdiv/main.py +++ b/src/domdiv/main.py @@ -1655,7 +1655,8 @@ def filter_sort_cards(cards, options): "name": c.name.strip().replace(" ", " "), "randomizer": c.randomizer, "count": 1, - "sort": "%03d%s" % (order, c.name.strip()), + "sort": "%03d%s" + % (order, CardSorter.strip_accents(c.name.strip())), } for set_tag, set_values in Card.sets.items(): diff --git a/tests/carddb_tests.py b/tests/carddb_tests.py index 93ddbff..c122f3c 100644 --- a/tests/carddb_tests.py +++ b/tests/carddb_tests.py @@ -3,6 +3,7 @@ import subprocess import shutil import os import contextlib +import unicodedata import pytest @@ -147,7 +148,7 @@ def test_expansion(): # --expansions, that we can have multiple # items with a single flag, that * syntax # works, that we can use either the - # cardset tag or name, and that capitalziation + # cardset tag or name, and that capitalization # doesn't matter options = main.parse_opts( [ @@ -175,7 +176,7 @@ def test_exclude_expansion(): # --exclude-expansions, that we can have multiple # items with a single flag, that * syntax # works, that we can use either the - # cardset tag or name, and that capitalziation + # cardset tag or name, and that capitalization # doesn't matter options = main.parse_opts( [ @@ -200,3 +201,35 @@ def test_exclude_expansion(): "dominion 2nd edition upgrade", "intrigue 1st edition", } + + +def test_expansion_description_card_order(): + # test that the expansions cards lists cards + # in alphabetical order, like they are printed, + # and that accents don't matter + options = main.parse_opts( + [ + "--expansions", + "Hinterlands", + "--expansion-dividers", + "--language", + "fr", + "--only-type-any", + "Expansion", + ] + ) + options = main.clean_opts(options) + options.data_path = "." + cards = main.read_card_data(options) + cards = main.filter_sort_cards(cards, options) + card_names = [c.strip() for c in cards[0].description.split("|")] + # The 26 french card names of the Hinterlands expansion should be sorted as if no accent + assert len(card_names) == 26 + assert card_names == sorted( + card_names, + key=lambda s: "".join( + c + for c in unicodedata.normalize("NFD", s) + if unicodedata.category(c) != "Mn" + ), + )