-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_one_currency.py
81 lines (63 loc) · 2.68 KB
/
test_one_currency.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import csv
import re
import pytest
from urllib.request import Request, urlopen
EXISTING_URL="https://codeforiati.org/imf-exchangerates/imf_exchangerates.csv"
class TestOneCurrency:
imf_currencies = __import__('imf-currencies')
country = {
"@value": "U2",
"Description": {
"@xml:lang": "en",
"#text": "Euro area (Member States and Institutions of the Euro Area) changing composition"
}
}
with open('output/imf_exchangerates_one_currency.csv', 'w') as output_csv:
writer = csv.DictWriter(output_csv, fieldnames=imf_currencies.FIELDNAMES)
writer.writeheader()
imf_currencies.write_data_for_country(writer,
country=country, sleep_time=0.25, freq='M',
source='ENDE', target='USD')
@pytest.fixture
def countries_currencies(self):
imf_currencies = __import__('imf-currencies')
return imf_currencies.countries_currencies
@pytest.fixture
def imf_countries(self):
imf_currencies = __import__('imf-currencies')
return imf_currencies.imf_countries
def test_first_row(self):
"""
Check that the first row outputs the expected data.
"""
with open("output/imf_exchangerates_one_currency.csv", "r") as input_csv:
reader = csv.DictReader(input_csv)
assert next(reader) == {
'Date': '1999-01-31',
'Rate': '0.878425860857344',
'Currency': 'EUR',
'Frequency': 'M',
'Source': 'IMF',
'Country code': 'U2',
'Country': 'Euro area (Member States and Institutions of the Euro Area) changing composition'
}
def test_currency_list(self, countries_currencies):
"""
Check that there are a lot of countries/currencies listed.
"""
# At the last count, it was 259. We shouldn't expect it
# to vary greatly from this.
assert len(countries_currencies) > 250
def test_currency_list_contains(self, countries_currencies):
"""
Check that the list of countries/currencies contains the Eurozone.
"""
assert "U2" in countries_currencies.keys()
def test_currency_list_eurozone_countries(self, countries_currencies):
"""
Check that the list of Eurozone countries/currencies is as expected.
"""
countries = [k for k, v in countries_currencies.items() if v == 'EUR']
assert countries == ['AX', 'AD', 'XK', 'MC', 'ME', 'U2']
# Aland Islands, Andorra, Kosovo, Monaco, Montenegro all use EUR but are not members
assert len([v for k, v in countries_currencies.items() if v == 'EUR']) == 6