Skip to content

Commit eec892c

Browse files
committed
MAINT: Add tester
Add tester to fully test install Fix issues related to testing installed package Update isort closes #806
1 parent 3ef1b30 commit eec892c

33 files changed

+117
-76
lines changed

.travis.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ language: python
44
env:
55
global:
66
- TEST_TYPE="stable and not requires_api_key"
7+
- TEST_INSTALL=false
78
# Doctr deploy key for pydata/pandas-datareader
89
- secure: "iGbOAbBSV5y0TKDh2CifRSk6OpLA9GbEEL/hscHFLSDDUCWcdfvYXda3SWJFWyoQ5QUxSigXWd+ukr4u92d7lmB7m3TWj6BAMNuRpatTgnejLNwLvNeYdvLAxPvx39Cq85frd1Rx1beBLn3h/4wm4Ah+dR5W9NH8+x3OuZMH3Eo="
910

@@ -19,7 +20,7 @@ matrix:
1920
- python: 3.8
2021
env: PANDAS=1 NUMPY=1.18
2122
- python: 3.8
22-
env: PANDAS=1 NUMPY=1.19
23+
env: PANDAS=1 NUMPY=1.19 TEST_INSTALL=true
2324
- python: 3.7
2425
env: TEST_TYPE="quandl" PANDAS=1 NUMPY=1.19
2526
# In allow failures
@@ -44,7 +45,15 @@ install:
4445

4546
script:
4647
- if [[ -n "${TEST_TYPE+x}" ]]; then export MARKERS="-m ${TEST_TYPE}"; fi
47-
- pytest -v -s -r xX "${MARKERS}" --cov-config .coveragerc --cov=pandas_datareader --cov-report xml:/tmp/cov-datareader.xml --junitxml=/tmp/datareader.xml
48+
- |
49+
if [[ ${TEST_INSTALL} = false ]]; then
50+
pytest -v -s -r xX "${MARKERS}" --cov-config .coveragerc --cov=pandas_datareader --cov-report xml:/tmp/cov-datareader.xml --junitxml=/tmp/datareader.xml
51+
else
52+
mkdir pdr_test
53+
cd pdf_test
54+
python -c "import pandas_datareader; pandas_datareader.test()"
55+
cd ..
56+
fi
4857
- black --version
4958
- black --check pandas_datareader
5059
- flake8 --version

docs/source/whatsnew/v0.9.0.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
.. _whatsnew_090:
22

3+
v0.9.1 (TBD)
4+
------------
5+
- Added the method ``test`` to the package to simplify running tests from an
6+
installation using
7+
8+
.. code-block:: shell
9+
10+
python -c "import pandas_datareader; pandas_datareader.test()"
11+
12+
313
v0.9.0 (July 10, 2020)
4-
---------------------------
14+
----------------------
515

616
Highlights include:
717

pandas_datareader/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
import sys
3+
14
from ._version import get_versions
25
from .data import (
36
DataReader,
@@ -27,6 +30,8 @@
2730
get_tops_iex,
2831
)
2932

33+
PKG = os.path.dirname(__file__)
34+
3035
__version__ = get_versions()["version"]
3136
del get_versions
3237

@@ -57,4 +62,30 @@
5762
"get_data_tiingo",
5863
"get_iex_data_tiingo",
5964
"get_data_alphavantage",
65+
"test",
6066
]
67+
68+
69+
def test(extra_args=None):
70+
"""
71+
Run the test suite
72+
73+
Parameters
74+
----------
75+
extra_args : {str, List[str]}
76+
A string or list of strings to pass to pytest. Default is
77+
["--only-stable", "--skip-requires-api-key"]
78+
"""
79+
try:
80+
import pytest
81+
except ImportError as err:
82+
raise ImportError("Need pytest>=5.0.1 to run tests") from err
83+
cmd = ["--only-stable", "--skip-requires-api-key"]
84+
if extra_args:
85+
if not isinstance(extra_args, list):
86+
extra_args = [extra_args]
87+
cmd = extra_args
88+
cmd += [PKG]
89+
joined = " ".join(cmd)
90+
print(f"running: pytest {joined}")
91+
sys.exit(pytest.main(cmd))

pandas_datareader/av/quotes.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import pandas as pd
33

44
from pandas_datareader.av import AlphaVantage
5-
from pandas_datareader.exceptions import (
6-
DEP_ERROR_MSG,
7-
ImmediateDeprecationError,
8-
)
5+
from pandas_datareader.exceptions import DEP_ERROR_MSG, ImmediateDeprecationError
96

107

118
class AVQuotesReader(AlphaVantage):

pandas_datareader/compat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pandas as pd
77
from pandas.api.types import is_list_like, is_number
8-
import pandas.io.common as com
8+
from pandas.io import common as com
99
from pandas.testing import assert_frame_equal
1010

1111
PANDAS_VERSION = LooseVersion(pd.__version__)

pandas_datareader/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@
33
import pytest
44

55

6+
def pytest_addoption(parser):
7+
parser.addoption("--only-stable", action="store_true", help="run only stable tests")
8+
parser.addoption(
9+
"--skip-requires-api-key",
10+
action="store_true",
11+
help="skip tests that require an API key",
12+
)
13+
parser.addoption(
14+
"--strict-data-files",
15+
action="store_true",
16+
help="Fail if a test is skipped for missing data file.",
17+
)
18+
19+
20+
def pytest_runtest_setup(item):
21+
if "stable" not in item.keywords and item.config.getoption("--only-stable"):
22+
pytest.skip("skipping due to --only-stable")
23+
24+
if "requires_api_key" in item.keywords and item.config.getoption(
25+
"--skip-requires-api-key"
26+
):
27+
pytest.skip("skipping due to --skip-requires-api-key")
28+
29+
630
@pytest.fixture
731
def datapath(request):
832
"""Get the path to a data file.

pandas_datareader/data.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@
1616
from pandas_datareader.econdb import EcondbReader
1717
from pandas_datareader.enigma import EnigmaReader
1818
from pandas_datareader.eurostat import EurostatReader
19-
from pandas_datareader.exceptions import (
20-
DEP_ERROR_MSG,
21-
ImmediateDeprecationError,
22-
)
19+
from pandas_datareader.exceptions import DEP_ERROR_MSG, ImmediateDeprecationError
2320
from pandas_datareader.famafrench import FamaFrenchReader
2421
from pandas_datareader.fred import FredReader
2522
from pandas_datareader.iex.daily import IEXDailyReader
2623
from pandas_datareader.iex.deep import Deep as IEXDeep
27-
from pandas_datareader.iex.tops import (
28-
LastReader as IEXLasts,
29-
TopsReader as IEXTops,
30-
)
24+
from pandas_datareader.iex.tops import LastReader as IEXLasts, TopsReader as IEXTops
3125
from pandas_datareader.moex import MoexReader
3226
from pandas_datareader.nasdaq_trader import get_nasdaq_symbols
3327
from pandas_datareader.naver import NaverDailyReader

pandas_datareader/enigma.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66
from pandas_datareader.base import _BaseReader, string_types
77
from pandas_datareader.compat import StringIO
8-
from pandas_datareader.exceptions import (
9-
DEP_ERROR_MSG,
10-
ImmediateDeprecationError,
11-
)
8+
from pandas_datareader.exceptions import DEP_ERROR_MSG, ImmediateDeprecationError
129

1310

1411
class EnigmaReader(_BaseReader):

pandas_datareader/io/sdmx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def read_sdmx(path_or_buf, dtype="float64", dsd=None):
4747

4848
xdata = _read_content(path_or_buf)
4949

50-
import xml.etree.ElementTree as ET
50+
from xml.etree import ElementTree as ET
5151

5252
root = ET.fromstring(xdata)
5353

@@ -204,7 +204,7 @@ def _read_sdmx_dsd(path_or_buf):
204204

205205
xdata = _read_content(path_or_buf)
206206

207-
import xml.etree.cElementTree as ET
207+
from xml.etree import cElementTree as ET
208208

209209
root = ET.fromstring(xdata)
210210

pandas_datareader/moex.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
import pandas as pd
44

55
from pandas_datareader.base import _DailyBaseReader
6-
from pandas_datareader.compat import (
7-
StringIO,
8-
binary_type,
9-
concat,
10-
is_list_like,
11-
)
6+
from pandas_datareader.compat import StringIO, binary_type, concat, is_list_like
127

138

149
class MoexReader(_DailyBaseReader):

pandas_datareader/tests/av/test_av_quotes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
import pandas_datareader.data as web
3+
from pandas_datareader import data as web
44
from pandas_datareader.exceptions import ImmediateDeprecationError
55

66
pytestmark = [

pandas_datareader/tests/io/test_jsdmx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import numpy as np
66
import pandas as pd
7-
import pandas.testing as tm
7+
from pandas import testing as tm
88
import pytest
99

1010
from pandas_datareader.compat import PANDAS_0210

pandas_datareader/tests/io/test_sdmx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import numpy as np
66
import pandas as pd
7-
import pandas.testing as tm
7+
from pandas import testing as tm
88
import pytest
99

1010
from pandas_datareader.io.sdmx import _read_sdmx_dsd, read_sdmx

pandas_datareader/tests/test_bankofcanada.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import pytest
44

5+
from pandas_datareader import data as web
56
from pandas_datareader._utils import RemoteDataError
6-
import pandas_datareader.data as web
77

88
pytestmark = pytest.mark.stable
99

pandas_datareader/tests/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
import requests
55

6-
import pandas_datareader.base as base
6+
from pandas_datareader import base as base
77

88
pytestmark = pytest.mark.stable
99

pandas_datareader/tests/test_econdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import numpy as np
22
import pandas as pd
3-
import pandas.testing as tm
3+
from pandas import testing as tm
44
import pytest
55

6-
import pandas_datareader.data as web
6+
from pandas_datareader import data as web
77

88
pytestmark = pytest.mark.stable
99

pandas_datareader/tests/test_enigma.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from requests.exceptions import HTTPError
33

44
import pandas_datareader as pdr
5-
import pandas_datareader.data as web
5+
from pandas_datareader import data as web
66
from pandas_datareader.exceptions import ImmediateDeprecationError
77

88
pytestmark = pytest.mark.requires_api_key

pandas_datareader/tests/test_eurostat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import numpy as np
22
import pandas as pd
3-
import pandas.testing as tm
3+
from pandas import testing as tm
44
import pytest
55

6-
import pandas_datareader.data as web
6+
from pandas_datareader import data as web
77

88
pytestmark = pytest.mark.stable
99

pandas_datareader/tests/test_famafrench.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import pandas as pd
2-
import pandas.testing as tm
2+
from pandas import testing as tm
33
import pytest
44

5-
import pandas_datareader.data as web
5+
from pandas_datareader import data as web
66
from pandas_datareader.famafrench import get_available_datasets
77

88
pytestmark = pytest.mark.stable

pandas_datareader/tests/test_fred.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import numpy as np
44
import pandas as pd
5-
from pandas import DataFrame
6-
import pandas.testing as tm
5+
from pandas import DataFrame, testing as tm
76
import pytest
87

8+
from pandas_datareader import data as web
99
from pandas_datareader._utils import RemoteDataError
10-
import pandas_datareader.data as web
1110

1211
pytestmark = pytest.mark.stable
1312

pandas_datareader/tests/test_iex_daily.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pandas import DataFrame, MultiIndex
55
import pytest
66

7-
import pandas_datareader.data as web
7+
from pandas_datareader import data as web
88
from pandas_datareader.iex.daily import IEXDailyReader
99

1010

pandas_datareader/tests/test_moex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from requests.exceptions import HTTPError
33

4-
import pandas_datareader.data as web
4+
from pandas_datareader import data as web
55

66
pytestmark = pytest.mark.stable
77

pandas_datareader/tests/test_nasdaq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
from pandas_datareader import data as web
12
from pandas_datareader._testing import skip_on_exception
23
from pandas_datareader._utils import RemoteDataError
3-
import pandas_datareader.data as web
44

55

66
class TestNasdaqSymbols(object):

pandas_datareader/tests/test_oecd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import numpy as np
44
import pandas as pd
5-
import pandas.testing as tm
5+
from pandas import testing as tm
66
import pytest
77

8+
from pandas_datareader import data as web
89
from pandas_datareader._utils import RemoteDataError
9-
import pandas_datareader.data as web
1010

1111

1212
class TestOECD(object):

pandas_datareader/tests/test_quandl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import pytest
44

5+
from pandas_datareader import data as web
56
from pandas_datareader.compat import assert_frame_equal
6-
import pandas_datareader.data as web
77

88
TEST_API_KEY = os.getenv("QUANDL_API_KEY")
99
# Ensure blank TEST_API_KEY not used in pull request

pandas_datareader/tests/test_stooq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
import pandas_datareader.data as web
3+
from pandas_datareader import data as web
44
from pandas_datareader.data import get_data_stooq
55

66
pytestmark = pytest.mark.stable

pandas_datareader/tests/test_tsp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
import pandas_datareader.tsp as tsp
5+
from pandas_datareader import tsp as tsp
66

77
pytestmark = pytest.mark.stable
88

pandas_datareader/tests/test_wb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44
import pandas as pd
5-
import pandas.testing as tm
5+
from pandas import testing as tm
66
import pytest
77
import requests
88

0 commit comments

Comments
 (0)