Fix test suites

Re: commit d3294cccf7
This commit is contained in:
Tom Keffer
2023-07-10 17:58:14 -07:00
parent bdebc8ac1f
commit eeeb7e90f2
2 changed files with 20 additions and 2 deletions

View File

@@ -153,16 +153,34 @@ class TestPressureCooker(unittest.TestCase):
t = pc._get_temperature_12h(self.record['dateTime'], db_manager)
# Make sure the mocked database manager got called with a time 12h ago
mock_mgr.assert_called_once_with(self.record['dateTime'] - 12 * 3600, max_delta=1800)
# The results should be in US units
self.assertEqual(t, (80.3, 'degree_F', 'group_temperature'))
# Make sure the value has been cached:
with mock.patch.object(db_manager, 'getRecord',
return_value={'usUnits': weewx.US, 'outTemp': 80.3}) as mock_mgr:
t = pc._get_temperature_12h(self.record['dateTime'], db_manager)
# The cached value should have been used
mock_mgr.assert_not_called()
self.assertEqual(t, (80.3, 'degree_F', 'group_temperature'))
def test_get_temperature_12h_metric(self):
pc = weewx.wxxtypes.PressureCooker(altitude_vt)
# Mock a database in METRICWX units
db_manager = mock.Mock()
with mock.patch.object(db_manager, 'getRecord',
return_value={'usUnits': weewx.METRICWX,
'outTemp': 30.0}) as mock_mgr:
t = pc._get_temperature_12h(self.record['dateTime'], db_manager)
# Make sure the mocked database manager got called with a time 12h ago
mock_mgr.assert_called_once_with(self.record['dateTime'] - 12 * 3600, max_delta=1800)
self.assertEqual(t, (30.0, 'degree_C', 'group_temperature'))
def test_get_temperature_12h_missing(self):
pc = weewx.wxxtypes.PressureCooker(altitude_vt)
db_manager = mock.Mock()
# Mock a database missing a record from 12h ago
with mock.patch.object(db_manager, 'getRecord',
return_value=None) as mock_mgr:

View File

@@ -374,8 +374,8 @@ class PressureCooker(weewx.xtypes.XType):
self.temp_12h_vt = None
def _get_temperature_12h(self, ts, dbmanager):
"""Get the temperature as a ValueTuple from 12 hours ago. The value will
be None if no temperature is available.
"""Get the temperature as a ValueTuple from 12 hours ago. The ValueTuple will use the same
unit system as the database. The value will be None if no temperature is available.
"""
ts_12h = ts - 12 * 3600