diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 48f07d2..5352780 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,12 @@ name: Test on: - - push - - pull_request + push: + branches: + - master + pull_request: + branches: + - master jobs: build: diff --git a/README.rst b/README.rst index e726aa0..d02a8bb 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ binary :target: https://pypi.org/project/binary :alt: Latest PyPI version -.. image:: https://github.com/ofek/binary/workflows/test/badge.svg +.. image:: https://github.com/ofek/binary/actions/workflows/test.yml/badge.svg :target: https://github.com/ofek/binary/actions/workflows/test.yml :alt: GitHub Actions @@ -17,10 +17,14 @@ binary :target: https://pypi.org/project/binary :alt: Supported Python versions -.. image:: https://img.shields.io/pypi/l/binary.svg?style=flat-square - :target: https://choosealicense.com/licenses +.. image:: https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-9400d3.svg + :target: https://spdx.org/licenses/ :alt: License +.. image:: https://img.shields.io/github/sponsors/ofek?logo=GitHub%20Sponsors&style=social + :target: https://github.com/sponsors/ofek + :alt: GitHub sponsors + ----- ``binary`` provides a bug-free and easy way to convert between and within @@ -32,10 +36,6 @@ binary (`IEC`_) and decimal (`SI`_) units. Installation ------------ -``binary`` is distributed on `PyPI `_ as a universal -wheel and is available on Linux/macOS and Windows and supports -Python 2.7/3.5+ and PyPy. - .. code-block:: bash $ pip install binary diff --git a/binary/core.py b/binary/core.py index 8cb48c1..c414094 100644 --- a/binary/core.py +++ b/binary/core.py @@ -165,9 +165,9 @@ def convert_units( if to: try: - return b / to, PREFIXES[to] + return b // to if to == BYTE else b / to, PREFIXES[to] except KeyError: - raise ValueError(f'{to} is not a valid binary unit.') + raise ValueError(f'{to} is not a valid unit.') if unit in BINARY_PREFIXES and not si: if b < KIBIBYTE: diff --git a/tests/test_core.py b/tests/test_core.py index fdbdecc..c12a059 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -119,8 +119,8 @@ def test_yottabyte(self) -> None: class TestConvert: def test_byte(self) -> None: - assert convert_units(1, bunits.YB, bunits.B) == (bunits.YB / 1, 'B') - assert convert_units(1, dunits.YB, dunits.B) == (dunits.YB / 1, 'B') + assert convert_units(1, bunits.YB, bunits.B) == (bunits.YB // 1, 'B') + assert convert_units(1, dunits.YB, dunits.B) == (dunits.YB // 1, 'B') def test_kibibyte(self) -> None: assert convert_units(1, bunits.YB, bunits.KB) == (bunits.YB / 1024 ** 1, 'KiB') @@ -173,8 +173,8 @@ def test_yottabyte(self) -> None: class TestConvertFloatExact: def test_byte(self) -> None: - assert convert_units(3.14, bunits.YB, bunits.B, exact=True) == (Decimal('3796027073589935608577392.64'), 'B') - assert convert_units(3.14, dunits.YB, dunits.B, exact=True) == (Decimal('3140000000000000000000000.00'), 'B') + assert convert_units(3.14, bunits.YB, bunits.B, exact=True) == (Decimal('3796027073589935608577392'), 'B') + assert convert_units(3.14, dunits.YB, dunits.B, exact=True) == (Decimal('3140000000000000000000000'), 'B') def test_kibibyte(self) -> None: assert convert_units(3.14, bunits.YB, bunits.KB, exact=True) == (Decimal('3707057689052671492751.36'), 'KiB')