summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--swiftstory/cards.py10
-rw-r--r--tests/test_cards.py6
2 files changed, 8 insertions, 8 deletions
diff --git a/swiftstory/cards.py b/swiftstory/cards.py
index 96438cc..7f28919 100644
--- a/swiftstory/cards.py
+++ b/swiftstory/cards.py
@@ -2,18 +2,18 @@ import json
import os
from typing import List
-import pkg_resources
+from pkg_resources import resource_stream
class Cards:
@staticmethod
def get_white_cards(lang: str) -> List[str]:
''' Read the file containing the white cards and return a list of cards '''
- fh = pkg_resources.resource_stream(__name__, os.path.join("data/lang", lang, "cards/white.json"))
- return json.load(fh)
+ return json.load(resource_stream(__name__,
+ os.path.join("data/lang", lang, "cards/white.json")))
@staticmethod
def get_black_cards(lang: str) -> List[str]:
''' Read the file containing the black cards and return a list of cards '''
- fh = pkg_resources.resource_stream(__name__, os.path.join("data/lang", lang, "cards/black.json"))
- return json.load(fh)
+ return json.load(resource_stream(__name__,
+ os.path.join("data/lang", lang, "cards/black.json")))
diff --git a/tests/test_cards.py b/tests/test_cards.py
index 605984b..b0992b6 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.pkg_resources.resource_stream", mock_open(read_data=white_cards)):
+ with patch("swiftstory.cards.resource_stream", mock_open(read_data=white_cards)):
self.assertIn("White Card 2", Cards.get_white_cards("en"))
- with patch("swiftstory.cards.pkg_resources.resource_stream", mock_open(read_data=black_cards)):
+ with patch("swiftstory.cards.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.pkg_resources.resource_stream", side_effect=FileNotFoundError):
+ with patch("swiftstory.cards.resource_stream", side_effect=FileNotFoundError):
with self.assertRaises(FileNotFoundError):
Cards.get_white_cards("zz")
with self.assertRaises(FileNotFoundError):