Add template multiply test
parent
7805d2800c
commit
9f5f13644a
|
@ -162,7 +162,7 @@ def multiply(value, amount):
|
|||
"""Filter to convert value to float and multiply it."""
|
||||
try:
|
||||
return float(value) * amount
|
||||
except ValueError:
|
||||
except (ValueError, TypeError):
|
||||
# If value can't be converted to float
|
||||
return value
|
||||
|
||||
|
|
|
@ -84,6 +84,19 @@ class TestUtilTemplate(unittest.TestCase):
|
|||
'{{ "no_number" | round }}'
|
||||
))
|
||||
|
||||
def test_multiply(self):
|
||||
tests = {
|
||||
None: 'None',
|
||||
10: '100',
|
||||
'"abcd"': 'abcd'
|
||||
}
|
||||
|
||||
for inp, out in tests.items():
|
||||
self.assertEqual(
|
||||
out,
|
||||
template.render(self.hass,
|
||||
'{{ %s | multiply(10) | round }}' % inp))
|
||||
|
||||
def test_passing_vars_as_keywords(self):
|
||||
self.assertEqual(
|
||||
'127', template.render(self.hass, '{{ hello }}', hello=127))
|
||||
|
|
Loading…
Reference in New Issue