Skip to content

Commit

Permalink
Merge pull request #25 from openweathermap/feature/convert-strings-to…
Browse files Browse the repository at this point in the history
…-int

- Parsing simple ints for memory limit
  • Loading branch information
matveyvarg authored Nov 20, 2023
2 parents 1336ee5 + 8a07038 commit 9c012db
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions deker/tools/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def convert_human_memory_to_bytes(memory_limit: Union[int, str]) -> int:
if isinstance(memory_limit, int):
return memory_limit

try:
return int(memory_limit)
except ValueError:
pass

limit, div = memory_limit[:-1], memory_limit.lower()[-1]
try:
int_limit: int = int(limit)
Expand Down
2 changes: 1 addition & 1 deletion docs/deker/collection_schema.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ with its *zero-index* at the front-left-bottom corner.
.. image:: images/varray.png
:scale: 30%

Let's query the following slice of it: ``[:, 2:4, :]``
Let's query the following slice of it: ``[2:4, :, :]``

.. image:: images/varray_request.png
:scale: 30%
Expand Down
2 changes: 1 addition & 1 deletion docs/deker/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Deker depends on the following third-party packages:
* ``h5py`` >= 3.8.0
* ``hdf5plugin`` >= 4.0.1

Also please not that for flexibility few internal Deker components are published as separate
Also please note that for flexibility few internal Deker components are published as separate
packages:

* ``deker-local-adapters``
Expand Down
22 changes: 20 additions & 2 deletions tests/test_cases/test_tools/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from tests.parameters.collection_params import CollectionParams

from deker.collection import Collection
from deker.errors import DekerInstanceNotExistsError, DekerMemoryError
from deker.tools import check_memory
from deker.errors import DekerInstanceNotExistsError, DekerMemoryError, DekerValidationError
from deker.tools import check_memory, convert_human_memory_to_bytes
from deker.tools.time import convert_datetime_attrs_to_iso, convert_iso_attrs_to_datetime


Expand Down Expand Up @@ -227,5 +227,23 @@ def test_generate_id_raises(array_type_arg):
generate_uid(array_type_arg)


@pytest.mark.parametrize(
"params,result,error",
(
("1K", 1024, None),
("1M", 1024**2, None),
("1G", 1024**3, None),
("0", 0, None),
("Foo", None, DekerValidationError),
),
)
def test_convert_human_to_bytes(params, result, error):
if error:
with pytest.raises(error):
convert_human_memory_to_bytes(params)
else:
assert convert_human_memory_to_bytes(params) == result


if __name__ == "__main__":
pytest.main()

0 comments on commit 9c012db

Please sign in to comment.