Add template multiply test

pull/1359/head
Paulus Schoutsen 2016-02-21 11:12:37 -08:00
parent 7805d2800c
commit 9f5f13644a
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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))