[Git][NTPsec/ntpsec][unit-rewrite] Fixed unitify strip bug, added neglected tests.
Ian Bruene
gitlab at mg.gitlab.com
Mon Apr 10 20:45:23 UTC 2017
Ian Bruene pushed to branch unit-rewrite at NTPsec / ntpsec
Commits:
3df840d2 by Ian Bruene at 2017-04-10T15:44:32-05:00
Fixed unitify strip bug, added neglected tests.
- - - - -
2 changed files:
- pylib/util.py
- tests/pylib/test_util.py
Changes:
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -332,6 +332,8 @@ def unitify(value, unitgroup, startingunit, baseunit=0,
newvalue = fitinfield(newvalue, width - len(unit)) + unit
else: # don't have a replacement unit, use original
newvalue = value + unitgroup[startingunit]
+ if strip is True:
+ newvalue = newvalue.strip()
return newvalue
=====================================
tests/pylib/test_util.py
=====================================
--- a/tests/pylib/test_util.py
+++ b/tests/pylib/test_util.py
@@ -316,6 +316,12 @@ class TestPylibUtilMethods(unittest.TestCase):
# Different units
self.assertEqual(f("12.345", nu.UNITS_PPX, nu.UNIT_PPM),
"12.34ppm")
+ # Strip
+ self.assertEqual(f("1.23", nu.UNITS_SEC, nu.UNIT_MS, strip=True),
+ "1.23ms")
+ # Different width
+ self.assertEqual(f("1.234", nu.UNITS_SEC, nu.UNIT_MS, width=12),
+ " 1.234ms")
if __name__ == '__main__':
unittest.main()
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/3df840d22e7acc043a7aafa7e9dd9eef1c443967
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170410/676f6c8d/attachment.html>
More information about the vc
mailing list