mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
new filter human_bytes: convert a string (ex: 1Mo, 1K) into bytes (#12074)
* Rework human_readable and human_to_bytes. New filter human_to_bytes. * Fix for python 3.
This commit is contained in:
@@ -61,13 +61,40 @@
|
||||
- 'diff_result.stdout == ""'
|
||||
|
||||
- name: Verify human_readable
|
||||
tags: "human_readable"
|
||||
assert:
|
||||
that:
|
||||
- '"1.00 Bytes" == 1|human_readable'
|
||||
- '"1.00 bits" == 1|human_readable(isbits=True)'
|
||||
- '"10.00 KB" == 10240|human_readable'
|
||||
- '"97.66 MB" == 102400000|human_readable'
|
||||
- '"0.10 GB" == 102400000|human_readable(unit="G")'
|
||||
- '"0.10 Gb" == 102400000|human_readable(isbits=True, unit="G")'
|
||||
|
||||
- name: Verify human_to_bytes
|
||||
tags: "human_to_bytes"
|
||||
assert:
|
||||
that:
|
||||
- "{{'0'|human_to_bytes}} == 0"
|
||||
- "{{'0.1'|human_to_bytes}} == 0"
|
||||
- "{{'0.9'|human_to_bytes}} == 1"
|
||||
- "{{'1'|human_to_bytes}} == 1"
|
||||
- "{{'10.00 KB'|human_to_bytes}} == 10240"
|
||||
- "{{ '11 MB'|human_to_bytes}} == 11534336"
|
||||
- "{{ '1.1 GB'|human_to_bytes}} == 1181116006"
|
||||
- "{{'10.00 Kb'|human_to_bytes(isbits=True)}} == 10240"
|
||||
|
||||
- name: Verify human_to_bytes (bad string)
|
||||
tags: "human_to_bytes"
|
||||
set_fact: bad_string="{{'10.00 foo'|human_to_bytes}}"
|
||||
ignore_errors: yes
|
||||
register: _
|
||||
|
||||
- name: Verify human_to_bytes (bad string)
|
||||
tags: "human_to_bytes"
|
||||
assert:
|
||||
that: "{{_.failed}}"
|
||||
|
||||
- name: Container lookups with extract
|
||||
assert:
|
||||
that:
|
||||
|
||||
Reference in New Issue
Block a user