Skip to content

Commit 050a6d7

Browse files
committed
reorganize tests into subfolders
* closes pvlib#848 * create pvlib/tests/iotools and move all iotools tests into that subfolder * use fixtures in test_ecmwf_macc.py for expected_test_data * use conftest.data_dir instead of redundant boilerplate process of retrieving test folder for each tests, mostly for iotools * fix test_ivtools.py was using full path to conftest but tests is not a python package, so no * change "pvlib/test" -> "pvlib/tests" to conform to popular convention Signed-off-by: Mark Mikofski <[email protected]>
1 parent 98537bc commit 050a6d7

30 files changed

+36
-51
lines changed

pvlib/test/conftest.py renamed to pvlib/tests/conftest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import os
32
import platform
43

@@ -36,8 +35,7 @@ def inner():
3635

3736

3837
# commonly used directories in the tests
39-
test_dir = os.path.dirname(
40-
os.path.abspath(inspect.getfile(inspect.currentframe())))
38+
test_dir = os.path.dirname(__file__)
4139
data_dir = os.path.join(test_dir, os.pardir, 'data')
4240

4341

pvlib/test/test_crn.py renamed to pvlib/tests/iotools/test_crn.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import os
32

43
import pandas as pd
@@ -7,12 +6,10 @@
76
from numpy import dtype, nan
87

98
from pvlib.iotools import crn
9+
from conftest import data_dir
1010

11-
12-
test_dir = os.path.dirname(
13-
os.path.abspath(inspect.getfile(inspect.currentframe())))
14-
testfile = os.path.join(test_dir,
15-
'../data/CRNS0101-05-2019-AZ_Tucson_11_W.txt')
11+
testfile = os.path.join(data_dir,
12+
'CRNS0101-05-2019-AZ_Tucson_11_W.txt')
1613

1714

1815
def test_read_crn():

pvlib/test/test_ecmwf_macc.py renamed to pvlib/tests/iotools/test_ecmwf_macc.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
import os
66
import datetime
77
import numpy as np
8-
from conftest import requires_netCDF4
8+
import pytest
9+
from conftest import requires_netCDF4, data_dir
910
from pvlib.iotools import ecmwf_macc
1011

11-
DIRNAME = os.path.dirname(__file__)
12-
PROJNAME = os.path.dirname(DIRNAME)
13-
DATADIR = os.path.join(PROJNAME, 'data')
1412
TESTDATA = 'aod550_tcwv_20121101_test.nc'
1513

1614
# for creating test data
@@ -21,19 +19,24 @@
2119
LAT_BND = (90, -90)
2220

2321

22+
@pytest.fixture
23+
def expected_test_data():
24+
return os.path.join(data_dir, TESTDATA)
25+
26+
2427
@requires_netCDF4
25-
def test_get_nearest_indices():
28+
def test_get_nearest_indices(expected_test_data):
2629
"""Test getting indices given latitude, longitude from ECMWF_MACC data."""
27-
data = ecmwf_macc.ECMWF_MACC(os.path.join(DATADIR, TESTDATA))
30+
data = ecmwf_macc.ECMWF_MACC(expected_test_data)
2831
ilat, ilon = data.get_nearest_indices(38, -122)
2932
assert ilat == 17
3033
assert ilon == 79
3134

3235

3336
@requires_netCDF4
34-
def test_interp_data():
37+
def test_interp_data(expected_test_data):
3538
"""Test interpolating UTC time from ECMWF_MACC data."""
36-
data = ecmwf_macc.ECMWF_MACC(os.path.join(DATADIR, TESTDATA))
39+
data = ecmwf_macc.ECMWF_MACC(expected_test_data)
3740
test9am = data.interp_data(
3841
38, -122, datetime.datetime(2012, 11, 1, 9, 0, 0), 'aod550')
3942
assert np.isclose(test9am, data.data.variables['aod550'][2, 17, 79])
@@ -47,10 +50,10 @@ def test_interp_data():
4750

4851

4952
@requires_netCDF4
50-
def test_read_ecmwf_macc():
53+
def test_read_ecmwf_macc(expected_test_data):
5154
"""Test reading ECMWF_MACC data from netCDF4 file."""
5255
data = ecmwf_macc.read_ecmwf_macc(
53-
os.path.join(DATADIR, TESTDATA), 38, -122)
56+
expected_test_data, 38, -122)
5457
expected_times = [
5558
1351738800, 1351749600, 1351760400, 1351771200, 1351782000, 1351792800,
5659
1351803600, 1351814400]
@@ -67,7 +70,7 @@ def test_read_ecmwf_macc():
6770
datetimes = (datetime.datetime(2012, 11, 1, 9, 0, 0),
6871
datetime.datetime(2012, 11, 1, 12, 0, 0))
6972
data_9am_12pm = ecmwf_macc.read_ecmwf_macc(
70-
os.path.join(DATADIR, TESTDATA), 38, -122, datetimes)
73+
expected_test_data, 38, -122, datetimes)
7174
assert np.allclose(data_9am_12pm.aod550.values, expected_aod[2:4])
7275
assert np.allclose(data_9am_12pm.tcwv.values, expected_tcwv[2:4])
7376

File renamed without changes.

pvlib/test/test_midc.py renamed to pvlib/tests/iotools/test_midc.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import os
32

43
import pandas as pd
@@ -7,6 +6,7 @@
76
import pytz
87

98
from pvlib.iotools import midc
9+
from conftest import data_dir
1010

1111

1212
@pytest.fixture
@@ -20,12 +20,10 @@ def test_mapping():
2020
}
2121

2222

23-
test_dir = os.path.dirname(
24-
os.path.abspath(inspect.getfile(inspect.currentframe())))
25-
midc_testfile = os.path.join(test_dir, '../data/midc_20181014.txt')
26-
midc_raw_testfile = os.path.join(test_dir, '../data/midc_raw_20181018.txt')
23+
midc_testfile = os.path.join(data_dir, 'midc_20181014.txt')
24+
midc_raw_testfile = os.path.join(data_dir, 'midc_raw_20181018.txt')
2725
midc_raw_short_header_testfile = os.path.join(
28-
test_dir, '../data/midc_raw_short_header_20191115.txt')
26+
data_dir, 'midc_raw_short_header_20191115.txt')
2927
midc_network_testfile = ('https://midcdmz.nrel.gov/apps/data_api.pl'
3028
'?site=UAT&begin=20181018&end=20181019')
3129

pvlib/test/test_psm3.py renamed to pvlib/tests/iotools/test_psm3.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44

55
import os
66
from pvlib.iotools import psm3
7-
from conftest import needs_pandas_0_22
7+
from conftest import needs_pandas_0_22, data_dir
88
import numpy as np
99
import pandas as pd
1010
import pytest
1111
from requests import HTTPError
1212
from io import StringIO
1313

14-
BASEDIR = os.path.abspath(os.path.dirname(__file__))
15-
PROJDIR = os.path.dirname(BASEDIR)
16-
DATADIR = os.path.join(PROJDIR, 'data')
17-
TMY_TEST_DATA = os.path.join(DATADIR, 'test_psm3_tmy-2017.csv')
18-
YEAR_TEST_DATA = os.path.join(DATADIR, 'test_psm3_2017.csv')
19-
MANUAL_TEST_DATA = os.path.join(DATADIR, 'test_read_psm3.csv')
14+
TMY_TEST_DATA = os.path.join(data_dir, 'test_psm3_tmy-2017.csv')
15+
YEAR_TEST_DATA = os.path.join(data_dir, 'test_psm3_2017.csv')
16+
MANUAL_TEST_DATA = os.path.join(data_dir, 'test_read_psm3.csv')
2017
LATITUDE, LONGITUDE = 40.5137, -108.5449
2118
HEADER_FIELDS = [
2219
'Source', 'Location ID', 'City', 'State', 'Country', 'Latitude',

pvlib/test/test_pvgis.py renamed to pvlib/tests/iotools/test_pvgis.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
import pytest
99
import requests
1010
from pvlib.iotools import get_pvgis_tmy
11+
from conftest import data_dir
1112

12-
TESTS = Path(__file__).parent
13-
PROJECT = TESTS.parent
14-
DATA = PROJECT / 'data'
13+
DATA = Path(data_dir)
1514

1615

1716
@pytest.fixture
File renamed without changes.

pvlib/test/test_srml.py renamed to pvlib/tests/iotools/test_srml.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import os
32

43
from numpy import isnan
@@ -7,11 +6,9 @@
76
import pytest
87

98
from pvlib.iotools import srml
9+
from conftest import data_dir
1010

11-
12-
test_dir = os.path.dirname(
13-
os.path.abspath(inspect.getfile(inspect.currentframe())))
14-
srml_testfile = os.path.join(test_dir, '../data/SRML-day-EUPO1801.txt')
11+
srml_testfile = os.path.join(data_dir, '../data/SRML-day-EUPO1801.txt')
1512

1613

1714
def test_read_srml():

pvlib/test/test_surfrad.py renamed to pvlib/tests/iotools/test_surfrad.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import inspect
21
import os
32

43
import pandas as pd
54
from pandas.util.testing import network
65

76
from pvlib.iotools import surfrad
7+
from conftest import data_dir
88

9-
test_dir = os.path.dirname(
10-
os.path.abspath(inspect.getfile(inspect.currentframe())))
11-
testfile = os.path.join(test_dir, '../data/surfrad-slv16001.dat')
9+
testfile = os.path.join(data_dir, 'surfrad-slv16001.dat')
1210
network_testfile = ('ftp://aftp.cmdl.noaa.gov/data/radiation/surfrad/'
1311
'Alamosa_CO/2016/slv16001.dat')
1412

pvlib/test/test_tmy.py renamed to pvlib/tests/iotools/test_tmy.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import inspect
21
import os
32

43
from pandas.util.testing import network
54

65
from pvlib.iotools import tmy
6+
from conftest import data_dir
77

8-
test_dir = os.path.dirname(
9-
os.path.abspath(inspect.getfile(inspect.currentframe())))
10-
tmy3_testfile = os.path.join(test_dir, '../data/703165TY.csv')
11-
tmy2_testfile = os.path.join(test_dir, '../data/12839.tm2')
8+
tmy3_testfile = os.path.join(data_dir, '703165TY.csv')
9+
tmy2_testfile = os.path.join(data_dir, '12839.tm2')
1210

1311

1412
def test_read_tmy3():
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.

pvlib/test/test_ivtools.py renamed to pvlib/tests/test_ivtools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111
from pvlib import pvsystem
1212
from pvlib import ivtools
13-
from pvlib.test.conftest import requires_scipy, requires_pysam
13+
from conftest import requires_scipy, requires_pysam
1414

1515

1616
@pytest.fixture
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.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)