summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2015-12-18 14:37:22 -0800
committerJoffrey F <joffrey@docker.com>2015-12-18 14:37:22 -0800
commit93211dd2a85834459dad9f298ff2d0bad33f894d (patch)
tree34fc3ae49949d8a18ee155fa4621b69b8a5effe4 /tests
parent9deffc45a10bf0d03907002a0b3fa6b63c7ff817 (diff)
downloaddocker-py-813-parse-float-bytes.tar.gz
Handle decimal values in parse_bytes813-parse-float-bytes
Also ensure we are able to handle 64-bit integers in py2 Signed-off-by: Joffrey F <joffrey@docker.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/utils_test.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py
index a68e1e7..faf211e 100644
--- a/tests/unit/utils_test.py
+++ b/tests/unit/utils_test.py
@@ -5,6 +5,7 @@ import json
import os
import os.path
import shutil
+import sys
import tarfile
import tempfile
@@ -398,14 +399,28 @@ class ParseRepositoryTagTest(base.BaseTestCase):
)
-class UtilsTest(base.BaseTestCase):
- longMessage = True
+class ParseBytesTest(base.BaseTestCase):
+ def test_parse_bytes_valid(self):
+ self.assertEqual(parse_bytes("512MB"), 536870912)
+ self.assertEqual(parse_bytes("512M"), 536870912)
+ self.assertEqual(parse_bytes("512m"), 536870912)
- def test_parse_bytes(self):
- self.assertEqual(parse_bytes("512MB"), (536870912))
- self.assertEqual(parse_bytes("512M"), (536870912))
+ def test_parse_bytes_invalid(self):
self.assertRaises(DockerException, parse_bytes, "512MK")
self.assertRaises(DockerException, parse_bytes, "512L")
+ self.assertRaises(DockerException, parse_bytes, "127.0.0.1K")
+
+ def test_parse_bytes_float(self):
+ self.assertEqual(parse_bytes("1.5k"), 1536)
+
+ def test_parse_bytes_maxint(self):
+ self.assertEqual(
+ parse_bytes("{0}k".format(sys.maxsize)), sys.maxsize * 1024
+ )
+
+
+class UtilsTest(base.BaseTestCase):
+ longMessage = True
def test_convert_filters(self):
tests = [