From a11615dbbd364f1e8ccc0277f97308daf3f4cfc1 Mon Sep 17 00:00:00 2001 From: Martin Hunt Date: Thu, 15 Dec 2016 13:45:10 -0500 Subject: [PATCH] fix bug when hitting enter on unitless numbers --- hublib/ui/numvalue.py | 3 ++- tests/test_number.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hublib/ui/numvalue.py b/hublib/ui/numvalue.py index 0867d48..ee875bf 100644 --- a/hublib/ui/numvalue.py +++ b/hublib/ui/numvalue.py @@ -173,7 +173,8 @@ def cb(self, _): self.dd.value = self.default return - val = '{:~}'.format(val) + if self.units is not None: + val = '{:~}'.format(val) if val != self.oldval: self.no_cb = True self.dd.value = val diff --git a/tests/test_number.py b/tests/test_number.py index 815d030..28b4377 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -82,10 +82,19 @@ def test_val_unitless(self): assert x.value == 5 assert x.str == '5' + # simulate pressing enter + x.cb('') + assert x.value == 5 + assert x.str == '5' + x.value = 4.4 assert x.value == 4.4 assert x.str == '4.4' + x.cb('') + assert x.value == 4.4 + assert x.str == '4.4' + # try some bad values with pytest.raises(ValueError): x.value = '4 m'