Skip to content

Commit ea6d721

Browse files
committed
CLN: moved all data for tests to /data sub-dir of the tests
1 parent 1052f47 commit ea6d721

21 files changed

+79
-47
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
1617,King of New York (1990)
2+
1618,All Things Fair (1996)
3+
1619,"Sixth Man, The (1997)"
4+
1620,Butterfly Kiss (1995)
5+
1621,"Paris, France (1993)"
6+
1622,"C�r�monie, La (1995)"
7+
1623,Hush (1998)
8+
1624,Nightwatch (1997)
9+
1625,Nobody Loves Me (Keiner liebt mich) (1994)
10+
1626,"Wife, The (1995)"
11+
1627,Lamerica (1994)
12+
1628,Nico Icon (1995)
13+
1629,"Silence of the Palace, The (Saimt el Qusur) (1994)"
14+
1630,"Slingshot, The (1993)"
15+
1631,Land and Freedom (Tierra y libertad) (1995)
16+
1632,� k�ldum klaka (Cold Fever) (1994)
17+
1633,Etz Hadomim Tafus (Under the Domin Tree) (1994)
18+
1634,Two Friends (1986)
File renamed without changes.

pandas/io/tests/test_cparser.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,10 @@
3131
import pandas._parser as parser
3232

3333

34-
def curpath():
35-
pth, _ = os.path.split(os.path.abspath(__file__))
36-
return pth
37-
38-
3934
class TestCParser(unittest.TestCase):
4035

4136
def setUp(self):
42-
self.dirpath = curpath()
37+
self.dirpath = tm.get_data_path('/')
4338
self.csv1 = os.path.join(self.dirpath, 'test1.csv')
4439
self.csv2 = os.path.join(self.dirpath, 'test2.csv')
4540
self.xls1 = os.path.join(self.dirpath, 'test.xls')

pandas/io/tests/test_excel.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ def _skip_if_no_excelsuite():
6565
_skip_if_no_openpyxl()
6666

6767

68-
def curpath():
69-
pth, _ = os.path.split(os.path.abspath(__file__))
70-
return pth
71-
7268
_seriesd = tm.getSeriesData()
7369
_tsd = tm.getTimeSeriesData()
7470
_frame = DataFrame(_seriesd)[:10]
@@ -81,7 +77,7 @@ def curpath():
8177
class ExcelTests(unittest.TestCase):
8278

8379
def setUp(self):
84-
self.dirpath = curpath()
80+
self.dirpath = tm.get_data_path()
8581
self.csv1 = os.path.join(self.dirpath, 'test1.csv')
8682
self.csv2 = os.path.join(self.dirpath, 'test2.csv')
8783
self.xls1 = os.path.join(self.dirpath, 'test.xls')

pandas/io/tests/test_parsers.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def setUp(self):
5959
import warnings
6060
warnings.filterwarnings(action='ignore', category=FutureWarning)
6161

62-
self.dirpath = curpath()
62+
self.dirpath = tm.get_data_path()
6363
self.csv1 = os.path.join(self.dirpath, 'test1.csv')
6464
self.csv2 = os.path.join(self.dirpath, 'test2.csv')
6565
self.xls1 = os.path.join(self.dirpath, 'test.xls')
@@ -1208,7 +1208,7 @@ def test_url(self):
12081208
url = ('https://raw.github.com/pydata/pandas/master/'
12091209
'pandas/io/tests/salary.table')
12101210
url_table = self.read_table(url)
1211-
dirpath = curpath()
1211+
dirpath = tm.get_data_path()
12121212
localtable = os.path.join(dirpath, 'salary.table')
12131213
local_table = self.read_table(localtable)
12141214
tm.assert_frame_equal(url_table, local_table)
@@ -1229,7 +1229,7 @@ def test_file(self):
12291229
# FILE
12301230
if sys.version_info[:2] < (2, 6):
12311231
raise nose.SkipTest("file:// not supported with Python < 2.6")
1232-
dirpath = curpath()
1232+
dirpath = tm.get_data_path()
12331233
localtable = os.path.join(dirpath, 'salary.table')
12341234
local_table = self.read_table(localtable)
12351235

@@ -1404,7 +1404,7 @@ def test_utf16_bom_skiprows(self):
14041404
tm.assert_frame_equal(result, expected)
14051405

14061406
def test_utf16_example(self):
1407-
path = os.path.join(self.dirpath, 'utf16_ex.txt')
1407+
path = tm.get_data_path('utf16_ex.txt')
14081408

14091409
# it works! and is the right length
14101410
result = self.read_table(path, encoding='utf-16')
@@ -1476,8 +1476,7 @@ def convert_score(x):
14761476
tm.assert_frame_equal(result, result2)
14771477

14781478
def test_unicode_encoding(self):
1479-
pth = psplit(psplit(curpath())[0])[0]
1480-
pth = os.path.join(pth, 'tests/data/unicode_series.csv')
1479+
pth = tm.get_data_path('unicode_series.csv')
14811480

14821481
result = self.read_csv(pth, header=None, encoding='latin-1')
14831482
result = result.set_index(0)
@@ -2185,11 +2184,6 @@ def assert_same_values_and_dtype(res, exp):
21852184
assert_almost_equal(res, exp)
21862185

21872186

2188-
def curpath():
2189-
pth, _ = os.path.split(os.path.abspath(__file__))
2190-
return pth
2191-
2192-
21932187
if __name__ == '__main__':
21942188
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
21952189
exit=False)

pandas/io/tests/test_pickle.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# pylint: disable=E1101,E1103,W0232
2+
3+
from datetime import datetime, timedelta
4+
import operator
5+
import pickle
6+
import unittest
7+
import nose
8+
import os
9+
10+
import numpy as np
11+
from numpy.testing import assert_array_equal
12+
from pandas.util.testing import assert_almost_equal
13+
from pandas.util import py3compat
14+
import pandas.core.common as com
15+
16+
import pandas.util.testing as tm
17+
import pandas as pd
18+
19+
class TestPickle(unittest.TestCase):
20+
_multiprocess_can_split_ = True
21+
22+
def setUp(self):
23+
pass
24+
25+
#def test_hash_error(self):
26+
# self.assertRaises(TypeError, hash, self.strIndex)
27+
28+
if __name__ == '__main__':
29+
import nose
30+
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
31+
# '--with-coverage', '--cover-package=pandas.core'],
32+
exit=False)

pandas/io/tests/test_pytables.py

+7-18
Original file line numberDiff line numberDiff line change
@@ -2324,25 +2324,23 @@ def _check_roundtrip_table(self, obj, comparator, compression=False):
23242324
comparator(retrieved, obj)
23252325

23262326
def test_pytables_native_read(self):
2327-
pth = curpath()
23282327

23292328
try:
2330-
store = HDFStore(os.path.join(pth, 'pytables_native.h5'), 'r')
2329+
store = HDFStore(tm.get_data_path('legacy_hdf/pytables_native.h5'), 'r')
23312330
d2 = store['detector/readout']
23322331
finally:
23332332
safe_close(store)
23342333

23352334
try:
2336-
store = HDFStore(os.path.join(pth, 'pytables_native2.h5'), 'r')
2335+
store = HDFStore(tm.get_data_path('legacy_hdf/pytables_native2.h5'), 'r')
23372336
str(store)
23382337
d1 = store['detector']
23392338
finally:
23402339
safe_close(store)
23412340

23422341
def test_legacy_read(self):
2343-
pth = curpath()
23442342
try:
2345-
store = HDFStore(os.path.join(pth, 'legacy.h5'), 'r')
2343+
store = HDFStore(tm.get_data_path('legacy_hdf/legacy.h5'), 'r')
23462344
store['a']
23472345
store['b']
23482346
store['c']
@@ -2352,9 +2350,8 @@ def test_legacy_read(self):
23522350

23532351
def test_legacy_table_read(self):
23542352
# legacy table types
2355-
pth = curpath()
23562353
try:
2357-
store = HDFStore(os.path.join(pth, 'legacy_table.h5'), 'r')
2354+
store = HDFStore(tm.get_data_path('legacy_hdf/legacy_table.h5'), 'r')
23582355
store.select('df1')
23592356
store.select('df2')
23602357
store.select('wp1')
@@ -2376,23 +2373,21 @@ def test_legacy_table_read(self):
23762373

23772374
def test_legacy_0_10_read(self):
23782375
# legacy from 0.10
2379-
pth = curpath()
23802376
try:
2381-
store = HDFStore(os.path.join(pth, 'legacy_0.10.h5'), 'r')
2377+
store = HDFStore(tm.get_data_path('legacy_hdf/legacy_0.10.h5'), 'r')
23822378
for k in store.keys():
23832379
store.select(k)
23842380
finally:
23852381
safe_close(store)
23862382

23872383
def test_copy(self):
2388-
pth = curpath()
23892384

23902385
def do_copy(f = None, new_f = None, keys = None, propindexes = True, **kwargs):
23912386
try:
23922387
import os
23932388

23942389
if f is None:
2395-
f = os.path.join(pth, 'legacy_0.10.h5')
2390+
f = tm.get_data_path('legacy_hdf/legacy_0.10.h5')
23962391

23972392

23982393
store = HDFStore(f, 'r')
@@ -2446,11 +2441,10 @@ def test_legacy_table_write(self):
24462441
raise nose.SkipTest
24472442

24482443
# legacy table types
2449-
pth = curpath()
24502444
df = tm.makeDataFrame()
24512445
wp = tm.makePanel()
24522446

2453-
store = HDFStore(os.path.join(pth, 'legacy_table.h5'), 'a')
2447+
store = HDFStore(tm.get_data_path('legacy_hdf/legacy_table.h5'), 'a')
24542448

24552449
self.assertRaises(Exception, store.append, 'df1', df)
24562450
self.assertRaises(Exception, store.append, 'wp1', wp)
@@ -2532,11 +2526,6 @@ def test_store_datetime_mixed(self):
25322526
# self.assertRaises(Exception, store.put, 'foo', df, table=True)
25332527

25342528

2535-
def curpath():
2536-
pth, _ = os.path.split(os.path.abspath(__file__))
2537-
return pth
2538-
2539-
25402529
def _test_sort(obj):
25412530
if isinstance(obj, DataFrame):
25422531
return obj.reindex(sorted(obj.index))

pandas/tests/test_format.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
_frame = DataFrame(tm.getSeriesData())
2828

2929

30-
def curpath():
31-
pth, _ = os.path.split(os.path.abspath(__file__))
32-
return pth
33-
34-
3530
class TestDataFrameFormatting(unittest.TestCase):
3631
_multiprocess_can_split_ = True
3732

@@ -491,8 +486,7 @@ def test_unicode_problem_decoding_as_ascii(self):
491486
unicode(dm.to_string())
492487

493488
def test_string_repr_encoding(self):
494-
pth = curpath()
495-
filepath = os.path.join(pth, 'data', 'unicode_series.csv')
489+
filepath = tm.get_data_path('unicode_series.csv')
496490
df = pandas.read_csv(filepath, header=None, encoding='latin1')
497491
repr(df)
498492
repr(df[1])

pandas/util/testing.py

+14
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ def ensure_clean(filename = None):
9393
except:
9494
pass
9595

96+
def get_data_path(f = None):
97+
""" return the path of a data file, these are relative to the current test dir """
98+
99+
if f is None:
100+
f = ''
101+
import inspect, os
102+
103+
# get our callers file
104+
frame,filename,line_number,function_name,lines,index = \
105+
inspect.getouterframes(inspect.currentframe())[1]
106+
107+
base_dir = os.path.abspath(os.path.dirname(filename))
108+
return os.path.join(base_dir, 'data/%s' % f)
109+
96110
#------------------------------------------------------------------------------
97111
# Comparators
98112

0 commit comments

Comments
 (0)