Skip to content

Commit

Permalink
fix bug when hitting enter on unitless numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-hunt committed Dec 15, 2016
1 parent b0dcdda commit a11615d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hublib/ui/numvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit a11615d

Please sign in to comment.