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'