Skip to content

Commit

Permalink
Commodities category merged into the others category (#5)
Browse files Browse the repository at this point in the history
* Commodities category merged into the others category
  • Loading branch information
duketemon committed Apr 30, 2023
1 parent 454ea4a commit 463a978
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 111 deletions.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ Comprehensive Python package for managing currency codes across different types
The package provides currency codes for different types of assets. Such as
- fiat (US dollar, UAE Dirham, ...)
- crypto (Bitcoin, Solana, ...)
- commodity (Palladium, Gold, ...)
- others (WIR Franc, CFP Franc, ...)
- others (Palladium, Gold, WIR Franc, CFP Franc, ...)

## Sources
- [Coinmarketcap website](https://coinmarketcap.com) for crypto
Expand Down Expand Up @@ -86,14 +85,6 @@ from currency_codes import get_crypto_currencies, Currency
crypto_currencies: list[Currency] = get_crypto_currencies()
```

### Get the list of commodity currencies
If you want to get information only about commodity currencies, you can use `get_commodity_currencies` function
```python
from currency_codes import get_commodity_currencies, Currency

commodity_currencies: list[Currency] = get_commodity_currencies()
```

### Get the list of other currencies
If you want to get information only about other currencies, you can use `get_other_currencies` function
```python
Expand Down
1 change: 0 additions & 1 deletion currency_codes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from currency_codes.assets.commodity import get_commodity_currencies
from currency_codes.assets.crypto import get_crypto_currencies
from currency_codes.assets.fiat import get_fiat_currencies
from currency_codes.assets.other import get_other_currencies
Expand Down
21 changes: 0 additions & 21 deletions currency_codes/assets/commodity.py

This file was deleted.

4 changes: 4 additions & 0 deletions currency_codes/assets/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def get_other_currencies() -> List[Currency]:


_other_currencies: List[Currency] = [
Currency(name="Palladium", code="XPD", numeric_code="964", minor_units=None),
Currency(name="Platinum", code="XPT", numeric_code="962", minor_units=None),
Currency(name="Gold", code="XAU", numeric_code="959", minor_units=None),
Currency(name="Silver", code="XAG", numeric_code="961", minor_units=None),
Currency(name="Sucre", code="XSU", numeric_code="994", minor_units=None),
Currency(name="CFP Franc", code="XPF", numeric_code="953", minor_units=0),
Currency(name="CFA Franc BEAC", code="XAF", numeric_code="950", minor_units=0),
Expand Down
4 changes: 1 addition & 3 deletions currency_codes/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import List

from currency_codes.assets.commodity import get_commodity_currencies
from currency_codes.assets.crypto import get_crypto_currencies
from currency_codes.assets.fiat import get_fiat_currencies
from currency_codes.assets.other import get_other_currencies
Expand All @@ -17,9 +16,8 @@ def get_all_currencies() -> List[Currency]:

fiat = get_fiat_currencies()
crypto = get_crypto_currencies()
commodity = get_commodity_currencies()
other = get_other_currencies()
return fiat + crypto + commodity + other
return fiat + crypto + other


def get_currency_by_code(code: str, case_sensitive: bool = False) -> Currency:
Expand Down
5 changes: 2 additions & 3 deletions currency_codes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ class Currency:
Args:
name (str): currency name
code (str): three-letter code
None if a currency never went public
numeric_code (str): three-digit numeric code
None for cryptos
minor_units (int): shows the relationship between the minor unit and the currency itself
None for commodities
"""

name: str
code: str
code: Optional[str]
numeric_code: Optional[str]
minor_units: Optional[int]
17 changes: 0 additions & 17 deletions tests/assets/test_commodity.py

This file was deleted.

8 changes: 0 additions & 8 deletions tests/assets/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ def test_when_no_code_duplicates_found_for_fiats(fiat_currencies) -> None:
assert_no_code_duplicates_found(fiat_currencies)


def test_when_no_code_duplicates_found_for_commodities(commodity_currencies) -> None:
assert_no_code_duplicates_found(commodity_currencies)


def assert_no_numeric_code_duplicates_found(currencies: Iterable[Currency]) -> None:
codes = set()
for currency in currencies:
Expand All @@ -31,7 +27,3 @@ def assert_no_numeric_code_duplicates_found(currencies: Iterable[Currency]) -> N

def test_when_no_numeric_code_duplicates_found_for_fiats(fiat_currencies) -> None:
assert_no_numeric_code_duplicates_found(fiat_currencies)


def test_when_no_numeric_code_duplicates_found_for_commodities(commodity_currencies) -> None:
assert_no_numeric_code_duplicates_found(commodity_currencies)
2 changes: 1 addition & 1 deletion tests/assets/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def test_get_other_currencies() -> None:

# Then
assert isinstance(currencies, Iterable)
assert len(currencies) == 19
assert len(currencies) == 23
6 changes: 0 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest

from currency_codes.assets.commodity import get_commodity_currencies
from currency_codes.assets.crypto import get_crypto_currencies
from currency_codes.assets.fiat import get_fiat_currencies
from currency_codes.assets.other import get_other_currencies
Expand All @@ -19,11 +18,6 @@ def crypto_currencies() -> Iterable[Currency]:
return get_crypto_currencies()


@pytest.fixture
def commodity_currencies() -> Iterable[Currency]:
return get_commodity_currencies()


@pytest.fixture
def other_currencies() -> Iterable[Currency]:
return get_other_currencies()
51 changes: 10 additions & 41 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@
("Chilean Peso", "CLP", "152", 0),
)

commodity_test_cases = (
# name, code, numeric_code
("Palladium", "XPD", "964"),
("Platinum", "XPT", "962"),
("Gold", "XAU", "959"),
("Silver", "XAG", "961"),
)

other_test_cases = (
# name, code, numeric_code
("Palladium", "XPD", "964", None),
("Silver", "XAG", "961", None),
("Uruguay Peso en Unidades Indexadas (UI)", "UYI", "940", 0),
("WIR Euro", "CHE", "947", 2),
("Unidad de Fomento", "CLF", "990", 4),
Expand Down Expand Up @@ -106,22 +101,6 @@ def test_get_currency_by_code_when_currency_is_fiat(name, code, numeric_code, mi
assert currency.minor_units == minor_units


@pytest.mark.parametrize(
ids=(c[0] for c in commodity_test_cases),
argvalues=commodity_test_cases,
argnames="name, code, numeric_code",
)
def test_get_currency_by_code_when_currency_is_commodity(name, code, numeric_code) -> None:
# When
currency = get_currency_by_code(code)

# Then
assert currency.name == name
assert currency.code == code
assert currency.numeric_code == numeric_code
assert currency.minor_units is None


@pytest.mark.parametrize(
ids=(c[0] for c in other_test_cases),
argvalues=other_test_cases,
Expand All @@ -137,7 +116,10 @@ def test_get_currency_by_code_when_currency_is_other(
assert currency.name == name
assert currency.code == code
assert currency.numeric_code == numeric_code
assert currency.minor_units == minor_units
if minor_units is None:
assert currency.minor_units is minor_units
else:
assert currency.minor_units == minor_units


def test_get_currency_by_numeric_code_when_currency_is_not_found() -> None:
Expand Down Expand Up @@ -170,22 +152,6 @@ def test_get_currency_by_numeric_code_when_currency_is_fiat(
assert currency.minor_units == minor_units


@pytest.mark.parametrize(
ids=(c[0] for c in commodity_test_cases),
argvalues=commodity_test_cases,
argnames="name, code, numeric_code",
)
def test_get_currency_by_numeric_code_when_currency_is_commodity(name, code, numeric_code) -> None:
# When
currency = get_currency_by_numeric_code(numeric_code)

# Then
assert currency.name == name
assert currency.code == code
assert currency.numeric_code == numeric_code
assert currency.minor_units is None


@pytest.mark.parametrize(
ids=(c[0] for c in other_test_cases),
argvalues=other_test_cases,
Expand All @@ -201,4 +167,7 @@ def test_get_currency_by_numeric_code_when_currency_is_other(
assert currency.name == name
assert currency.code == code
assert currency.numeric_code == numeric_code
assert currency.minor_units == minor_units
if minor_units is None:
assert currency.minor_units is minor_units
else:
assert currency.minor_units == minor_units

0 comments on commit 463a978

Please sign in to comment.