Skip to content

Commit

Permalink
support for enphase and no inverter
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanbhosale committed Jun 14, 2024
1 parent 51a673a commit 125976a
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions tests/data/test_make_pv_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pandas as pd
import numpy as np
import xarray as xr
import pytest
from unittest.mock import patch
Expand All @@ -19,7 +20,7 @@ def mock_enphase_data(*args, **kwargs):
(PVSite(latitude=40.7128, longitude=-74.0059, capacity_kwp=8.5, inverter_type='enphase'), mock_enphase_data()),
])
@patch('quartz_solar_forecast.inverters.enphase.get_enphase_data', side_effect=mock_enphase_data)
def test_make_pv_data(mock_get_enphase, site, expected_data, ts=pd.Timestamp('2023-06-14 12:15:00')):
def test_make_pv_data_enphase(mock_get_enphase, site, expected_data, ts=pd.Timestamp('2023-06-14 12:15:00')):
from quartz_solar_forecast.data import make_pv_data
result = make_pv_data(site, ts)
expected = expected_data[expected_data['timestamp'] <= ts]
Expand All @@ -38,30 +39,25 @@ def test_make_pv_data(mock_get_enphase, site, expected_data, ts=pd.Timestamp('20
).to_dataset(name='generation_kw')

assert result.equals(expected_xr)

@pytest.mark.parametrize("site, expected_data", [
(PVSite(latitude=40.7128, longitude=-74.0059, capacity_kwp=8.5, inverter_type='enphase'), pd.DataFrame({'timestamp': [], 'power_kw': []})),
(PVSite(latitude=40.7128, longitude=-74.0059, capacity_kwp=8.5, inverter_type='unknown'), np.array([[np.nan]])),
])
@patch('quartz_solar_forecast.inverters.enphase.get_enphase_data', return_value=pd.DataFrame({'timestamp': [], 'power_kw': []}))
def test_make_pv_data_empty_data(mock_get_enphase, site, expected_data, ts=pd.Timestamp('2023-06-14 12:15:00')):
def test_make_pv_data_no_live(site, expected_data, ts=pd.Timestamp('2023-06-14 12:15:00')):
from quartz_solar_forecast.data import make_pv_data
result = make_pv_data(site, ts)
if not expected_data.empty:
expected = expected_data[expected_data['timestamp'] <= ts]
else:
expected = expected_data
expected_xr = xr.DataArray(
data=expected['power_kw'].values.reshape(1, -1),
data=expected_data,
dims=['pv_id', 'timestamp'],
coords={
'longitude': (['pv_id'], [site.longitude]),
'latitude': (['pv_id'], [site.latitude]),
'timestamp': (['timestamp'], expected['timestamp'].values.astype('datetime64[ns]')),
'timestamp': (['timestamp'], [ts]),
'pv_id': [1],
'kwp': (['pv_id'], [site.capacity_kwp]),
'tilt': (["pv_id"], [site.tilt]),
'orientation': (["pv_id"], [site.orientation]),
}
).to_dataset(name='generation_kw')

assert result.equals(expected_xr)
assert result.equals(expected_xr)

0 comments on commit 125976a

Please sign in to comment.