diff options
author | Joffrey F <f.joffrey@gmail.com> | 2015-05-20 15:37:22 -0700 |
---|---|---|
committer | Joffrey F <f.joffrey@gmail.com> | 2015-05-20 15:37:22 -0700 |
commit | 7b2fd8cf5ef3bbcbecd190eba39a33b3708ff33b (patch) | |
tree | 86f8238e1162edc23abea8d63ee073a5fe10f296 | |
parent | 08444cf355bd782913776f9da1041384d7c8c7a1 (diff) | |
parent | ef452ed4c1161a0b71369be7c86e450fd41b52f8 (diff) | |
download | docker-py-7b2fd8cf5ef3bbcbecd190eba39a33b3708ff33b.tar.gz |
Merge pull request #562 from smothiki/mems
make memory units compatible with native docker cli
-rw-r--r-- | docker/utils/utils.py | 3 | ||||
-rw-r--r-- | tests/utils_test.py | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py index bca88de..4110017 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -322,6 +322,9 @@ def parse_bytes(s): if len(s) == 0: s = 0 else: + if s[-2:-1].isalpha() and s[-1].isalpha(): + if (s[-1] == "b" or s[-1] == "B"): + s = s[:-1] units = BYTE_UNITS suffix = s[-1].lower() diff --git a/tests/utils_test.py b/tests/utils_test.py index 454a14e..716cde5 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -6,7 +6,7 @@ from docker.client import Client from docker.errors import DockerException from docker.utils import ( parse_repository_tag, parse_host, convert_filters, kwargs_from_env, - create_host_config, Ulimit, LogConfig + create_host_config, Ulimit, LogConfig, parse_bytes ) from docker.utils.ports import build_port_bindings, split_port from docker.auth import resolve_authconfig @@ -37,6 +37,12 @@ class UtilsTest(base.BaseTestCase): self.assertEqual(parse_repository_tag("url:5000/repo:tag"), ("url:5000/repo", "tag")) + def test_parse_bytes(self): + self.assertEqual(parse_bytes("512MB"), (536870912)) + self.assertEqual(parse_bytes("512M"), (536870912)) + self.assertRaises(DockerException, parse_bytes, "512MK") + self.assertRaises(DockerException, parse_bytes, "512L") + def test_parse_host(self): invalid_hosts = [ '0.0.0.0', |