python: Require a unit in anyToFrequency and anyToLatency

The anytToFrequency and anyToLatency conversion functions are
currently ambiguous when called without a unit. Fix this by always
requiring a unit.

Change-Id: I5ea94e655f7ca82c0efe70b9f9f7f734fbf711c1
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/39435
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
This commit is contained in:
Andreas Sandberg
2021-01-20 12:19:26 +00:00
parent ad82dd3b56
commit 9e93ce565d
2 changed files with 32 additions and 34 deletions

View File

@@ -163,28 +163,18 @@ class ConvertTestSuite(unittest.TestCase):
self.assertEqual(conv('1kHz'), 1e-3)
self.assertRaises(ValueError, conv, '42k')
@unittest.expectedFailure
def test_anyToLatency_ambiguous(self):
# This the behavior of anyToFrequency is currently ambiguous
# (and surprising) for unitless quantities. The following
# should be true to be consistent with the other conversion
# functions, but that isn't currently the case.
self.assertEqual(convert.anyToLatency('42'), 42.0)
self.assertRaises(ValueError, conv, '42')
def test_anyToFrequency(self):
conv = convert.anyToFrequency
# This is ambiguous and should probably not be allowed.
self.assertEqual(conv('42'), 42.0)
self.assertEqual(conv('42kHz'), 42e3)
self.assertEqual(conv('0.1s'), 10.0)
self.assertEqual(conv('1ms'), 1000.0)
self.assertRaises(ValueError, conv, '42k')
self.assertRaises(ValueError, conv, '42')
def test_toNetworkBandwidth(self):
conv = convert.toNetworkBandwidth