Skip to content

Commit 90f5257

Browse files
gfyoungjreback
authored andcommitted
TST: Remove self.assert* from testing (#319)
1 parent 22a0ecb commit 90f5257

15 files changed

+330
-268
lines changed

pandas_datareader/io/tests/test_jsdmx.py

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,58 @@ def setUp(self):
1616

1717
def test_tourism(self):
1818
# OECD -> Industry and Services -> Inbound Tourism
19-
result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx', 'tourism.json'))
20-
self.assertTrue(isinstance(result, pd.DataFrame))
19+
result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx',
20+
'tourism.json'))
21+
assert isinstance(result, pd.DataFrame)
2122

22-
exp_col = pd.MultiIndex.from_product([['Japan'],
23-
['China', 'Hong Kong, China',
24-
'Total international arrivals',
25-
'Total international receipts',
26-
'International passenger transport receipts',
27-
'International travel receipts',
28-
'Korea', 'Chinese Taipei', 'United States']],
29-
names=['Country', 'Variable'])
30-
exp_idx = pd.DatetimeIndex(['2004', '2005', '2006', '2007', '2008',
31-
'2009', '2010', '2011', '2012'], name='Year')
23+
exp_col = pd.MultiIndex.from_product(
24+
[['Japan'], ['China', 'Hong Kong, China',
25+
'Total international arrivals',
26+
'Total international receipts',
27+
'International passenger transport receipts',
28+
'International travel receipts',
29+
'Korea', 'Chinese Taipei', 'United States']],
30+
names=['Country', 'Variable'])
31+
exp_idx = pd.DatetimeIndex(['2004', '2005', '2006', '2007',
32+
'2008', '2009', '2010', '2011',
33+
'2012'], name='Year')
3234

33-
values = np.array([[616, 300, 6138, 1550, 330, 1220, 1588, 1081, 760],
34-
[653, 299, 6728, 1710, 340, 1370, 1747, 1275, 822],
35-
[812, 352, 7334, 1330, 350, 980, 2117, 1309, 817],
36-
[942, 432, 8347, 1460, 360, 1100, 2601, 1385, 816],
37-
[1000, 550, 8351, 1430, 310, 1120, 2382, 1390, 768],
38-
[1006, 450, 6790, 1170, 210, 960, 1587, 1024, 700],
39-
[1413, 509, 8611, 1350, 190, 1160, 2440, 1268, 727],
40-
[1043, 365, 6219, 1000, 100, 900, 1658, 994, 566],
41-
[1430, 482, 8368, 1300, 100, 1200, 2044, 1467, 717]])
35+
values = np.array([
36+
[616, 300, 6138, 1550, 330, 1220, 1588, 1081, 760],
37+
[653, 299, 6728, 1710, 340, 1370, 1747, 1275, 822],
38+
[812, 352, 7334, 1330, 350, 980, 2117, 1309, 817],
39+
[942, 432, 8347, 1460, 360, 1100, 2601, 1385, 816],
40+
[1000, 550, 8351, 1430, 310, 1120, 2382, 1390, 768],
41+
[1006, 450, 6790, 1170, 210, 960, 1587, 1024, 700],
42+
[1413, 509, 8611, 1350, 190, 1160, 2440, 1268, 727],
43+
[1043, 365, 6219, 1000, 100, 900, 1658, 994, 566],
44+
[1430, 482, 8368, 1300, 100, 1200, 2044, 1467, 717]])
4245
expected = pd.DataFrame(values, index=exp_idx, columns=exp_col)
4346
tm.assert_frame_equal(result, expected)
4447

4548
def test_land_use(self):
4649
# OECD -> Environment -> Resources Land Use
47-
result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx', 'land_use.json'))
48-
self.assertTrue(isinstance(result, pd.DataFrame))
50+
result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx',
51+
'land_use.json'))
52+
assert isinstance(result, pd.DataFrame)
4953
result = result.ix['2010':'2011']
5054

51-
exp_col = pd.MultiIndex.from_product([['Japan', 'United States'],
52-
['Arable land and permanent crops',
53-
'Arable and cropland % land area',
54-
'Total area', 'Forest', 'Forest % land area',
55-
'Land area', 'Permanent meadows and pastures',
56-
'Meadows and pastures % land area',
57-
'Other areas', 'Other % land area']],
58-
names=['Country', 'Variable'])
55+
exp_col = pd.MultiIndex.from_product([
56+
['Japan', 'United States'],
57+
['Arable land and permanent crops',
58+
'Arable and cropland % land area',
59+
'Total area', 'Forest', 'Forest % land area',
60+
'Land area', 'Permanent meadows and pastures',
61+
'Meadows and pastures % land area', 'Other areas',
62+
'Other % land area']], names=['Country', 'Variable'])
5963
exp_idx = pd.DatetimeIndex(['2010', '2011'], name='Year')
60-
values = np.array([[45930, 12.601, 377950, 249790, 68.529, 364500, np.nan, np.nan,
61-
68780, 18.87, 1624330, 17.757, 9831510, 3040220, 33.236, 9147420,
62-
2485000, 27.166, 1997870, 21.841],
63-
[45610, 12.513, 377955, 249878, 68.554, 364500, np.nan, np.nan,
64-
69012, 18.933, 1627625, 17.793, 9831510, 3044048, 33.278, 9147420,
65-
2485000, 27.166, 1990747, 21.763]])
64+
values = np.array([[45930, 12.601, 377950, 249790, 68.529, 364500,
65+
np.nan, np.nan, 68780, 18.87, 1624330, 17.757,
66+
9831510, 3040220, 33.236, 9147420, 2485000,
67+
27.166, 1997870, 21.841],
68+
[45610, 12.513, 377955, 249878, 68.554, 364500,
69+
np.nan, np.nan, 69012, 18.933, 1627625, 17.793,
70+
9831510, 3044048, 33.278, 9147420, 2485000,
71+
27.166, 1990747, 21.763]])
6672
expected = pd.DataFrame(values, index=exp_idx, columns=exp_col)
6773
tm.assert_frame_equal(result, expected)

pandas_datareader/io/tests/test_sdmx.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ def test_tourism(self):
1818
# Eurostat
1919
# Employed doctorate holders in non managerial and non professional
2020
# occupations by fields of science (%)
21-
dsd = _read_sdmx_dsd(os.path.join(self.dirpath, 'sdmx', 'DSD_cdh_e_fos.xml'))
22-
df = read_sdmx(os.path.join(self.dirpath, 'sdmx', 'cdh_e_fos.xml'), dsd=dsd)
21+
dsd = _read_sdmx_dsd(os.path.join(self.dirpath, 'sdmx',
22+
'DSD_cdh_e_fos.xml'))
23+
df = read_sdmx(os.path.join(self.dirpath, 'sdmx',
24+
'cdh_e_fos.xml'), dsd=dsd)
2325

24-
self.assertTrue(isinstance(df, pd.DataFrame))
25-
self.assertEqual(df.shape, (2, 336))
26+
assert isinstance(df, pd.DataFrame)
27+
assert df.shape == (2, 336)
2628

2729
df = df['Percentage']['Total']['Natural sciences']
2830
df = df[['Norway', 'Poland', 'Portugal', 'Russia']]
2931

30-
exp_col = pd.MultiIndex.from_product([['Norway', 'Poland', 'Portugal', 'Russia'],
31-
['Annual']],
32+
exp_col = pd.MultiIndex.from_product([['Norway', 'Poland', 'Portugal',
33+
'Russia'], ['Annual']],
3234
names=['GEO', 'FREQ'])
3335
exp_idx = pd.DatetimeIndex(['2009', '2006'], name='TIME_PERIOD')
3436

pandas_datareader/tests/test_base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
import pytest
12
import pandas.util.testing as tm
23
import pandas_datareader.base as base
34

45

56
class TestBaseReader(tm.TestCase):
67
def test_valid_retry_count(self):
7-
with tm.assertRaises(ValueError):
8+
with pytest.raises(ValueError):
89
base._BaseReader([], retry_count='stuff')
9-
with tm.assertRaises(ValueError):
10+
with pytest.raises(ValueError):
1011
base._BaseReader([], retry_count=-1)
1112

1213
def test_invalid_url(self):
13-
with tm.assertRaises(NotImplementedError):
14+
with pytest.raises(NotImplementedError):
1415
base._BaseReader([]).url
1516

1617
def test_invalid_format(self):
17-
with tm.assertRaises(NotImplementedError):
18+
with pytest.raises(NotImplementedError):
1819
b = base._BaseReader([])
1920
b._format = 'IM_NOT_AN_IMPLEMENTED_TYPE'
2021
b._read_one_data('a', None)
2122

2223

2324
class TestDailyBaseReader(tm.TestCase):
2425
def test_get_params(self):
25-
with tm.assertRaises(NotImplementedError):
26+
with pytest.raises(NotImplementedError):
2627
b = base._DailyBaseReader()
2728
b._get_params()

pandas_datareader/tests/test_data.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
import pandas.util.testing as tm
24
import pandas_datareader.data as web
35

@@ -20,10 +22,6 @@ def test_options_source_warning(self):
2022

2123

2224
class TestDataReader(tm.TestCase):
23-
def test_is_s3_url(self):
24-
from pandas.io.common import _is_s3_url
25-
self.assertTrue(_is_s3_url("s3://pandas/somethingelse.com"))
26-
2725
def test_read_yahoo(self):
2826
gs = DataReader("GS", "yahoo")
2927
assert isinstance(gs, DataFrame)
@@ -41,4 +39,5 @@ def test_read_fred(self):
4139
assert isinstance(vix, DataFrame)
4240

4341
def test_not_implemented(self):
44-
self.assertRaises(NotImplementedError, DataReader, "NA", "NA")
42+
with pytest.raises(NotImplementedError):
43+
DataReader("NA", "NA")

pandas_datareader/tests/test_edgar.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ def test_get_nonzip_index_and_low_date(self):
3232
ed = web.DataReader('daily', 'edgar-index', '1994-06-30',
3333
'1994-07-02')
3434
assert len(ed) > 200
35+
assert ed.index.nlevels == 2
3536

36-
self.assertEqual(ed.index.nlevels, 2)
3737
dti = ed.index.get_level_values(0)
38-
self.assertIsInstance(dti, pd.DatetimeIndex)
38+
assert isinstance(dti, pd.DatetimeIndex)
3939
exp_columns = pd.Index(['company_name', 'form_type',
4040
'filename'], dtype='object')
4141
tm.assert_index_equal(ed.columns, exp_columns)
@@ -57,12 +57,12 @@ def test_6_digit_date(self):
5757
ed = web.DataReader('daily', 'edgar-index', start='1998-05-18',
5858
end='1998-05-18')
5959
assert len(ed) < 1200
60+
assert ed.index.nlevels == 2
6061

61-
self.assertEqual(ed.index.nlevels, 2)
6262
dti = ed.index.get_level_values(0)
63-
self.assertIsInstance(dti, pd.DatetimeIndex)
64-
self.assertEqual(dti[0], pd.Timestamp('1998-05-18'))
65-
self.assertEqual(dti[-1], pd.Timestamp('1998-05-18'))
63+
assert isinstance(dti, pd.DatetimeIndex)
64+
assert dti[0] == pd.Timestamp('1998-05-18')
65+
assert dti[-1] == pd.Timestamp('1998-05-18')
6666

6767
exp_columns = pd.Index(['company_name', 'form_type',
6868
'filename'], dtype='object')

pandas_datareader/tests/test_enigma.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,24 @@ def test_enigma_datareader(self):
2222
try:
2323
df = web.DataReader('enigma.inspections.restaurants.fl',
2424
'enigma', access_key=TEST_API_KEY)
25-
self.assertTrue('serialid' in df.columns)
25+
assert 'serialid' in df.columns
2626
except HTTPError as e: # pragma: no cover
2727
pytest.skip(e)
2828

2929
def test_enigma_get_data_enigma(self):
3030
try:
3131
df = pdr.get_data_enigma(
3232
'enigma.inspections.restaurants.fl', TEST_API_KEY)
33-
self.assertTrue('serialid' in df.columns)
33+
assert 'serialid' in df.columns
3434
except HTTPError as e: # pragma: no cover
3535
pytest.skip(e)
3636

3737
def test_bad_key(self):
38-
with tm.assertRaises(HTTPError):
38+
with pytest.raises(HTTPError):
3939
web.DataReader('enigma.inspections.restaurants.fl',
40-
'enigma',
41-
access_key=TEST_API_KEY + 'xxx')
40+
'enigma', access_key=TEST_API_KEY + 'xxx')
4241

4342
def test_bad_url(self):
44-
with tm.assertRaises(HTTPError):
43+
with pytest.raises(HTTPError):
4544
web.DataReader('enigma.inspections.restaurants.fllzzy',
46-
'enigma',
47-
access_key=TEST_API_KEY)
45+
'enigma', access_key=TEST_API_KEY)

pandas_datareader/tests/test_eurostat.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def test_get_cdh_e_fos(self):
1313
start=pd.Timestamp('2005-01-01'),
1414
end=pd.Timestamp('2010-01-01'))
1515

16-
self.assertTrue(isinstance(df, pd.DataFrame))
17-
self.assertEqual(df.shape, (2, 336))
16+
assert isinstance(df, pd.DataFrame)
17+
assert df.shape == (2, 336)
1818

1919
df = df['Percentage']['Total']['Natural sciences']
2020
df = df[['Norway', 'Poland', 'Portugal', 'Russia']]
@@ -40,7 +40,8 @@ def test_get_sts_cobp_a(self):
4040
name='TIME_PERIOD')
4141
ne_name = ('Index, 2010=100',
4242
'Building permits - m2 of useful floor area',
43-
'Unadjusted data (i.e. neither seasonally adjusted nor calendar adjusted data)',
43+
'Unadjusted data (i.e. neither seasonally adjusted nor '
44+
'calendar adjusted data)',
4445
'Non-residential buildings, except office buildings',
4546
'Netherlands', 'Annual')
4647
ne_values = [200.0, 186.5, 127.3, 130.7, 143.3, 147.8, 176.7,
@@ -49,7 +50,8 @@ def test_get_sts_cobp_a(self):
4950

5051
uk_name = ('Index, 2010=100',
5152
'Building permits - m2 of useful floor area',
52-
'Unadjusted data (i.e. neither seasonally adjusted nor calendar adjusted data)',
53+
'Unadjusted data (i.e. neither seasonally adjusted nor '
54+
'calendar adjusted data)',
5355
'Non-residential buildings, except office buildings',
5456
'United Kingdom', 'Annual')
5557
uk_values = [112.5, 113.3, 110.2, 112.1, 119.1, 112.7, 113.1,

pandas_datareader/tests/test_famafrench.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ def test_get_data(self):
1818

1919
for name in keys:
2020
ff = web.DataReader(name, 'famafrench')
21-
self.assertTrue('DESCR' in ff)
22-
self.assertTrue(len(ff) > 1)
21+
assert 'DESCR' in ff
22+
assert len(ff) > 1
2323

2424
def test_get_available_datasets(self):
2525
pytest.importorskip("lxml")
2626
l = get_available_datasets()
27-
self.assertTrue(len(l) > 100)
27+
assert len(l) > 100
2828

2929
def test_index(self):
3030
ff = web.DataReader('F-F_Research_Data_Factors', 'famafrench')
31-
self.assertEqual(ff[0].index.freq, 'M')
32-
self.assertEqual(ff[1].index.freq, 'A-DEC')
31+
assert ff[0].index.freq == 'M'
32+
assert ff[1].index.freq == 'A-DEC'
3333

3434
def test_f_f_research(self):
3535
results = web.DataReader("F-F_Research_Data_Factors", "famafrench",
3636
start='2010-01-01', end='2010-12-01')
37-
self.assertTrue(isinstance(results, dict))
38-
self.assertEqual(len(results), 3)
37+
assert isinstance(results, dict)
38+
assert len(results) == 3
3939

4040
exp = pd.DataFrame({'Mkt-RF': [-3.36, 3.4, 6.31, 2., -7.89, -5.56,
4141
6.93, -4.77, 9.54, 3.88, 0.6, 6.82],
@@ -45,38 +45,45 @@ def test_f_f_research(self):
4545
-1.96, -3.12, -2.52, -0.91, 3.78],
4646
'RF': [0., 0., 0.01, 0.01, 0.01, 0.01, 0.01,
4747
0.01, 0.01, 0.01, 0.01, 0.01]},
48-
index=pd.period_range('2010-01-01', '2010-12-01', freq='M', name='Date'),
48+
index=pd.period_range('2010-01-01', '2010-12-01',
49+
freq='M', name='Date'),
4950
columns=['Mkt-RF', 'SMB', 'HML', 'RF'])
5051
tm.assert_frame_equal(results[0], exp)
5152

5253
def test_me_breakpoints(self):
5354
results = web.DataReader("ME_Breakpoints", "famafrench",
5455
start='2010-01-01', end='2010-12-01')
55-
self.assertTrue(isinstance(results, dict))
56-
self.assertEqual(len(results), 2)
57-
self.assertEqual(results[0].shape, (12, 21))
58-
59-
exp_columns = pd.Index(['Count', (0, 5), (5, 10), (10, 15), (15, 20), (20, 25),
60-
(25, 30), (30, 35), (35, 40), (40, 45), (45, 50), (50, 55),
61-
(55, 60), (60, 65), (65, 70), (70, 75), (75, 80), (80, 85),
62-
(85, 90), (90, 95), (95, 100)], dtype='object')
56+
assert isinstance(results, dict)
57+
assert len(results) == 2
58+
assert results[0].shape == (12, 21)
59+
60+
exp_columns = pd.Index(['Count', (0, 5), (5, 10), (10, 15), (15, 20),
61+
(20, 25), (25, 30), (30, 35), (35, 40),
62+
(40, 45), (45, 50), (50, 55), (55, 60),
63+
(60, 65), (65, 70), (70, 75), (75, 80),
64+
(80, 85), (85, 90), (90, 95), (95, 100)],
65+
dtype='object')
6366
tm.assert_index_equal(results[0].columns, exp_columns)
6467

65-
exp_index = pd.period_range('2010-01-01', '2010-12-01', freq='M', name='Date')
68+
exp_index = pd.period_range('2010-01-01', '2010-12-01',
69+
freq='M', name='Date')
6670
tm.assert_index_equal(results[0].index, exp_index)
6771

6872
def test_prior_2_12_breakpoints(self):
6973
results = web.DataReader("Prior_2-12_Breakpoints", "famafrench",
7074
start='2010-01-01', end='2010-12-01')
71-
self.assertTrue(isinstance(results, dict))
72-
self.assertEqual(len(results), 2)
73-
self.assertEqual(results[0].shape, (12, 22))
74-
75-
exp_columns = pd.Index(['<=0', '>0', (0, 5), (5, 10), (10, 15), (15, 20), (20, 25),
76-
(25, 30), (30, 35), (35, 40), (40, 45), (45, 50), (50, 55),
77-
(55, 60), (60, 65), (65, 70), (70, 75), (75, 80), (80, 85),
78-
(85, 90), (90, 95), (95, 100)], dtype='object')
75+
assert isinstance(results, dict)
76+
assert len(results) == 2
77+
assert results[0].shape == (12, 22)
78+
79+
exp_columns = pd.Index(['<=0', '>0', (0, 5), (5, 10), (10, 15),
80+
(15, 20), (20, 25), (25, 30), (30, 35),
81+
(35, 40), (40, 45), (45, 50), (50, 55),
82+
(55, 60), (60, 65), (65, 70), (70, 75),
83+
(75, 80), (80, 85), (85, 90), (90, 95),
84+
(95, 100)], dtype='object')
7985
tm.assert_index_equal(results[0].columns, exp_columns)
8086

81-
exp_index = pd.period_range('2010-01-01', '2010-12-01', freq='M', name='Date')
87+
exp_index = pd.period_range('2010-01-01', '2010-12-01',
88+
freq='M', name='Date')
8289
tm.assert_index_equal(results[0].index, exp_index)

0 commit comments

Comments
 (0)