From d592880c4bc4c581d8847d96ff73bc319ca1fac2 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 26 Dec 2021 17:11:37 +0100 Subject: Make cards be part of the Python package data We now load the cards using pkg_resources. This is way better in many aspects: * we can install the package using pip without having issues loading cards * we don't need to chdir to / before running swiftstoryd * we don't need to rely on data_files which is deprecated. Signed-off-by: Olivier Gayot --- tests/test_cards.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/test_cards.py') diff --git a/tests/test_cards.py b/tests/test_cards.py index 73f42a0..605984b 100644 --- a/tests/test_cards.py +++ b/tests/test_cards.py @@ -13,13 +13,13 @@ class TestCards(unittest.TestCase): ]) black_cards = json.dumps(["Black Card 1", "Black Card 2"]) - with patch("swiftstory.cards.open", mock_open(read_data=white_cards)): + with patch("swiftstory.cards.pkg_resources.resource_stream", mock_open(read_data=white_cards)): self.assertIn("White Card 2", Cards.get_white_cards("en")) - with patch("swiftstory.cards.open", mock_open(read_data=black_cards)): + with patch("swiftstory.cards.pkg_resources.resource_stream", mock_open(read_data=black_cards)): self.assertIn("Black Card 1", Cards.get_black_cards("en")) def test_get_cards_unknown_language(self): - with patch("swiftstory.cards.open", side_effect=FileNotFoundError): + with patch("swiftstory.cards.pkg_resources.resource_stream", side_effect=FileNotFoundError): with self.assertRaises(FileNotFoundError): Cards.get_white_cards("zz") with self.assertRaises(FileNotFoundError): -- cgit v1.2.3