Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: Test

on:
- push
- pull_request
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
Expand Down
14 changes: 7 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -32,10 +36,6 @@ binary (`IEC`_) and decimal (`SI`_) units.
Installation
------------

``binary`` is distributed on `PyPI <https://pypi.org>`_ 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
Expand Down
4 changes: 2 additions & 2 deletions binary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down