diff --git a/src/pricehist/isocurrencies.py b/src/pricehist/isocurrencies.py index fadee06..f7079c4 100644 --- a/src/pricehist/isocurrencies.py +++ b/src/pricehist/isocurrencies.py @@ -90,13 +90,11 @@ def _parse(entry): except (IndexError, ValueError): minor_units = None - name_tags = entry.cssselect("CcyNm") - if name_tags: + name = None + is_fund = None + if name_tags := entry.cssselect("CcyNm"): name = name_tags[0].text is_fund = name_tags[0].attrib.get("IsFund", "").upper() in ["TRUE", "WAHR"] - else: - name = None - is_fund = None countries = [t.text for t in entry.cssselect("CtryNm")] diff --git a/tests/pricehist/test_isocurrencies.py b/tests/pricehist/test_isocurrencies.py new file mode 100644 index 0000000..5e79c97 --- /dev/null +++ b/tests/pricehist/test_isocurrencies.py @@ -0,0 +1,33 @@ +from datetime import datetime + +from pricehist import isocurrencies + + +def test_current(): + currency = isocurrencies.by_code()["EUR"] + assert currency.code == "EUR" + assert currency.number == 978 + assert currency.minor_units == 2 + assert currency.name == "Euro" + assert "GERMANY" in currency.countries + assert "FRANCE" in currency.countries + assert not currency.is_fund + assert not currency.historical + assert not currency.withdrawal_date + + +def test_historical(): + currency = isocurrencies.by_code()["DEM"] + assert currency.code == "DEM" + assert currency.number == 276 + assert currency.minor_units is None + assert currency.name == "Deutsche Mark" + assert "GERMANY" in currency.countries + assert not currency.is_fund + assert currency.historical + assert currency.withdrawal_date == "2002-03" + + +def test_data_dates(): + assert datetime.strptime(isocurrencies.current_data_date(), "%Y-%m-%d") + assert datetime.strptime(isocurrencies.historical_data_date(), "%Y-%m-%d")