From 125976ad87323bdf68e51df4536e467b69e86de7 Mon Sep 17 00:00:00 2001 From: Aryan Bhosale Date: Fri, 14 Jun 2024 20:37:49 +0530 Subject: [PATCH] support for enphase and no inverter --- tests/data/test_make_pv_data.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/data/test_make_pv_data.py b/tests/data/test_make_pv_data.py index b1f7585f..53c80970 100644 --- a/tests/data/test_make_pv_data.py +++ b/tests/data/test_make_pv_data.py @@ -1,4 +1,5 @@ import pandas as pd +import numpy as np import xarray as xr import pytest from unittest.mock import patch @@ -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] @@ -38,25 +39,20 @@ 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]), @@ -64,4 +60,4 @@ def test_make_pv_data_empty_data(mock_get_enphase, site, expected_data, ts=pd.Ti } ).to_dataset(name='generation_kw') - assert result.equals(expected_xr) + assert result.equals(expected_xr) \ No newline at end of file