diff --git a/binary/__init__.py b/binary/__init__.py index ee4536e..578c058 100644 --- a/binary/__init__.py +++ b/binary/__init__.py @@ -11,4 +11,16 @@ BinaryUnits, DecimalUnits, convert_units ) +__all__ = [ + "BYTE", + "KIBIBYTE", "KILOBYTE", + "MEBIBYTE", "MEGABYTE", + "GIBIBYTE", "GIGABYTE", + "TEBIBYTE", "TERABYTE", + "PEBIBYTE", "PETABYTE", + "EXBIBYTE", "EXABYTE", + "ZEBIBYTE", "ZETTABYTE", + "YOBIBYTE", "YOTTABYTE", + "BinaryUnits", "DecimalUnits", "convert_units", +] __version__ = '1.0.0' diff --git a/tests/test_core.py b/tests/test_core.py index 0882419..fdbdecc 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -10,296 +10,296 @@ class TestConstants: - def test_byte(self): + def test_byte(self) -> None: assert binary.BYTE == bunits.BYTE == bunits.B == 1 assert binary.BYTE == dunits.BYTE == dunits.B == 1 - def test_kibibyte(self): + def test_kibibyte(self) -> None: assert binary.KIBIBYTE == bunits.KIBIBYTE == bunits.KB == 1024 ** 1 - def test_mebibyte(self): + def test_mebibyte(self) -> None: assert binary.MEBIBYTE == bunits.MEBIBYTE == bunits.MB == 1024 ** 2 - def test_gibibyte(self): + def test_gibibyte(self) -> None: assert binary.GIBIBYTE == bunits.GIBIBYTE == bunits.GB == 1024 ** 3 - def test_tebibyte(self): + def test_tebibyte(self) -> None: assert binary.TEBIBYTE == bunits.TEBIBYTE == bunits.TB == 1024 ** 4 - def test_pebibyte(self): + def test_pebibyte(self) -> None: assert binary.PEBIBYTE == bunits.PEBIBYTE == bunits.PB == 1024 ** 5 - def test_exbibyte(self): + def test_exbibyte(self) -> None: assert binary.EXBIBYTE == bunits.EXBIBYTE == bunits.EB == 1024 ** 6 - def test_zebibyte(self): + def test_zebibyte(self) -> None: assert binary.ZEBIBYTE == bunits.ZEBIBYTE == bunits.ZB == 1024 ** 7 - def test_yobibyte(self): + def test_yobibyte(self) -> None: assert binary.YOBIBYTE == bunits.YOBIBYTE == bunits.YB == 1024 ** 8 - def test_kilobyte(self): + def test_kilobyte(self) -> None: assert binary.KILOBYTE == dunits.KILOBYTE == dunits.KB == 1000 ** 1 - def test_megabyte(self): + def test_megabyte(self) -> None: assert binary.MEGABYTE == dunits.MEGABYTE == dunits.MB == 1000 ** 2 - def test_gigabyte(self): + def test_gigabyte(self) -> None: assert binary.GIGABYTE == dunits.GIGABYTE == dunits.GB == 1000 ** 3 - def test_terabyte(self): + def test_terabyte(self) -> None: assert binary.TERABYTE == dunits.TERABYTE == dunits.TB == 1000 ** 4 - def test_petabyte(self): + def test_petabyte(self) -> None: assert binary.PETABYTE == dunits.PETABYTE == dunits.PB == 1000 ** 5 - def test_exabyte(self): + def test_exabyte(self) -> None: assert binary.EXABYTE == dunits.EXABYTE == dunits.EB == 1000 ** 6 - def test_zettabyte(self): + def test_zettabyte(self) -> None: assert binary.ZETTABYTE == dunits.ZETTABYTE == dunits.ZB == 1000 ** 7 - def test_yottabyte(self): + def test_yottabyte(self) -> None: assert binary.YOTTABYTE == dunits.YOTTABYTE == dunits.YB == 1000 ** 8 class TestAccurateString: - def test_byte(self): + def test_byte(self) -> None: assert PREFIXES[bunits.BYTE] == 'B' assert PREFIXES[dunits.BYTE] == 'B' - def test_kibibyte(self): + def test_kibibyte(self) -> None: assert PREFIXES[bunits.KIBIBYTE] == 'KiB' - def test_mebibyte(self): + def test_mebibyte(self) -> None: assert PREFIXES[bunits.MEBIBYTE] == 'MiB' - def test_gibibyte(self): + def test_gibibyte(self) -> None: assert PREFIXES[bunits.GIBIBYTE] == 'GiB' - def test_tebibyte(self): + def test_tebibyte(self) -> None: assert PREFIXES[bunits.TEBIBYTE] == 'TiB' - def test_pebibyte(self): + def test_pebibyte(self) -> None: assert PREFIXES[bunits.PEBIBYTE] == 'PiB' - def test_exbibyte(self): + def test_exbibyte(self) -> None: assert PREFIXES[bunits.EXBIBYTE] == 'EiB' - def test_zebibyte(self): + def test_zebibyte(self) -> None: assert PREFIXES[bunits.ZEBIBYTE] == 'ZiB' - def test_yobibyte(self): + def test_yobibyte(self) -> None: assert PREFIXES[bunits.YOBIBYTE] == 'YiB' - def test_kilobyte(self): + def test_kilobyte(self) -> None: assert PREFIXES[dunits.KILOBYTE] == 'KB' - def test_megabyte(self): + def test_megabyte(self) -> None: assert PREFIXES[dunits.MEGABYTE] == 'MB' - def test_gigabyte(self): + def test_gigabyte(self) -> None: assert PREFIXES[dunits.GIGABYTE] == 'GB' - def test_terabyte(self): + def test_terabyte(self) -> None: assert PREFIXES[dunits.TERABYTE] == 'TB' - def test_petabyte(self): + def test_petabyte(self) -> None: assert PREFIXES[dunits.PETABYTE] == 'PB' - def test_exabyte(self): + def test_exabyte(self) -> None: assert PREFIXES[dunits.EXABYTE] == 'EB' - def test_zettabyte(self): + def test_zettabyte(self) -> None: assert PREFIXES[dunits.ZETTABYTE] == 'ZB' - def test_yottabyte(self): + def test_yottabyte(self) -> None: assert PREFIXES[dunits.YOTTABYTE] == 'YB' class TestConvert: - def test_byte(self): + 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') - def test_kibibyte(self): + def test_kibibyte(self) -> None: assert convert_units(1, bunits.YB, bunits.KB) == (bunits.YB / 1024 ** 1, 'KiB') - def test_mebibyte(self): + def test_mebibyte(self) -> None: assert convert_units(1, bunits.YB, bunits.MB) == (bunits.YB / 1024 ** 2, 'MiB') - def test_gibibyte(self): + def test_gibibyte(self) -> None: assert convert_units(1, bunits.YB, bunits.GB) == (bunits.YB / 1024 ** 3, 'GiB') - def test_tebibyte(self): + def test_tebibyte(self) -> None: assert convert_units(1, bunits.YB, bunits.TB) == (bunits.YB / 1024 ** 4, 'TiB') - def test_pebibyte(self): + def test_pebibyte(self) -> None: assert convert_units(1, bunits.YB, bunits.PB) == (bunits.YB / 1024 ** 5, 'PiB') - def test_exbibyte(self): + def test_exbibyte(self) -> None: assert convert_units(1, bunits.YB, bunits.EB) == (bunits.YB / 1024 ** 6, 'EiB') - def test_zebibyte(self): + def test_zebibyte(self) -> None: assert convert_units(1, bunits.YB, bunits.ZB) == (bunits.YB / 1024 ** 7, 'ZiB') - def test_yobibyte(self): + def test_yobibyte(self) -> None: assert convert_units(1, bunits.YB, bunits.YB) == (bunits.YB / 1024 ** 8, 'YiB') - def test_kilobyte(self): + def test_kilobyte(self) -> None: assert convert_units(1, dunits.YB, dunits.KB) == (dunits.YB / 1000 ** 1, 'KB') - def test_megabyte(self): + def test_megabyte(self) -> None: assert convert_units(1, dunits.YB, dunits.MB) == (dunits.YB / 1000 ** 2, 'MB') - def test_gigabyte(self): + def test_gigabyte(self) -> None: assert convert_units(1, dunits.YB, dunits.GB) == (dunits.YB / 1000 ** 3, 'GB') - def test_terabyte(self): + def test_terabyte(self) -> None: assert convert_units(1, dunits.YB, dunits.TB) == (dunits.YB / 1000 ** 4, 'TB') - def test_petabyte(self): + def test_petabyte(self) -> None: assert convert_units(1, dunits.YB, dunits.PB) == (dunits.YB / 1000 ** 5, 'PB') - def test_exabyte(self): + def test_exabyte(self) -> None: assert convert_units(1, dunits.YB, dunits.EB) == (dunits.YB / 1000 ** 6, 'EB') - def test_zettabyte(self): + def test_zettabyte(self) -> None: assert convert_units(1, dunits.YB, dunits.ZB) == (dunits.YB / 1000 ** 7, 'ZB') - def test_yottabyte(self): + def test_yottabyte(self) -> None: assert convert_units(1, dunits.YB, dunits.YB) == (dunits.YB / 1000 ** 8, 'YB') class TestConvertFloatExact: - def test_byte(self): + 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') - def test_kibibyte(self): + def test_kibibyte(self) -> None: assert convert_units(3.14, bunits.YB, bunits.KB, exact=True) == (Decimal('3707057689052671492751.36'), 'KiB') - def test_mebibyte(self): + def test_mebibyte(self) -> None: assert convert_units(3.14, bunits.YB, bunits.MB, exact=True) == (Decimal('3620173524465499504.64'), 'MiB') - def test_gibibyte(self): + def test_gibibyte(self) -> None: assert convert_units(3.14, bunits.YB, bunits.GB, exact=True) == (Decimal('3535325707485839.36'), 'GiB') - def test_tebibyte(self): + def test_tebibyte(self) -> None: assert convert_units(3.14, bunits.YB, bunits.TB, exact=True) == (Decimal('3452466511216.64'), 'TiB') - def test_pebibyte(self): + def test_pebibyte(self) -> None: assert convert_units(3.14, bunits.YB, bunits.PB, exact=True) == (Decimal('3371549327.36'), 'PiB') - def test_exbibyte(self): + def test_exbibyte(self) -> None: assert convert_units(3.14, bunits.YB, bunits.EB, exact=True) == (Decimal('3292528.64'), 'EiB') - def test_zebibyte(self): + def test_zebibyte(self) -> None: assert convert_units(3.14, bunits.YB, bunits.ZB, exact=True) == (Decimal('3215.36'), 'ZiB') - def test_yobibyte(self): + def test_yobibyte(self) -> None: assert convert_units(3.14, bunits.YB, bunits.YB, exact=True) == (Decimal('3.14'), 'YiB') - def test_kilobyte(self): + def test_kilobyte(self) -> None: assert convert_units(3.14, dunits.YB, dunits.KB, exact=True) == (Decimal('3140000000000000000000.00'), 'KB') - def test_megabyte(self): + def test_megabyte(self) -> None: assert convert_units(3.14, dunits.YB, dunits.MB, exact=True) == (Decimal('3140000000000000000.00'), 'MB') - def test_gigabyte(self): + def test_gigabyte(self) -> None: assert convert_units(3.14, dunits.YB, dunits.GB, exact=True) == (Decimal('3140000000000000.00'), 'GB') - def test_terabyte(self): + def test_terabyte(self) -> None: assert convert_units(3.14, dunits.YB, dunits.TB, exact=True) == (Decimal('3140000000000.00'), 'TB') - def test_petabyte(self): + def test_petabyte(self) -> None: assert convert_units(3.14, dunits.YB, dunits.PB, exact=True) == (Decimal('3140000000.00'), 'PB') - def test_exabyte(self): + def test_exabyte(self) -> None: assert convert_units(3.14, dunits.YB, dunits.EB, exact=True) == (Decimal('3140000.00'), 'EB') - def test_zettabyte(self): + def test_zettabyte(self) -> None: assert convert_units(3.14, dunits.YB, dunits.ZB, exact=True) == (Decimal('3140.00'), 'ZB') - def test_yottabyte(self): + def test_yottabyte(self) -> None: assert convert_units(3.14, dunits.YB, dunits.YB, exact=True) == (Decimal('3.14'), 'YB') class TestConvertUnknownTo: - def test_byte(self): + def test_byte(self) -> None: assert convert_units(bunits.B) == (bunits.B, 'B') assert convert_units(bunits.KB - 1) == (bunits.KB - 1, 'B') assert convert_units(dunits.B, si=True) == (dunits.B, 'B') assert convert_units(dunits.KB - 1, si=True) == (dunits.KB - 1, 'B') - def test_kibibyte(self): + def test_kibibyte(self) -> None: assert convert_units(bunits.KB) == (bunits.KB / bunits.KB, 'KiB') assert convert_units(bunits.MB - 1) == ((bunits.MB - 1) / bunits.KB, 'KiB') - def test_mebibyte(self): + def test_mebibyte(self) -> None: assert convert_units(bunits.MB) == (bunits.MB / bunits.MB, 'MiB') assert convert_units(bunits.GB - 1) == ((bunits.GB - 1) / bunits.MB, 'MiB') - def test_gibibyte(self): + def test_gibibyte(self) -> None: assert convert_units(bunits.GB) == (bunits.GB / bunits.GB, 'GiB') assert convert_units(bunits.TB - 1) == ((bunits.TB - 1) / bunits.GB, 'GiB') - def test_tebibyte(self): + def test_tebibyte(self) -> None: assert convert_units(bunits.TB) == (bunits.TB / bunits.TB, 'TiB') assert convert_units(bunits.PB - 1) == ((bunits.PB - 1) / bunits.TB, 'TiB') - def test_pebibyte(self): + def test_pebibyte(self) -> None: assert convert_units(bunits.PB) == (bunits.PB / bunits.PB, 'PiB') assert convert_units(bunits.EB - 1) == ((bunits.EB - 1) / bunits.PB, 'PiB') - def test_exbibyte(self): + def test_exbibyte(self) -> None: assert convert_units(bunits.EB) == (bunits.EB / bunits.EB, 'EiB') assert convert_units(bunits.ZB - 1) == ((bunits.ZB - 1) / bunits.EB, 'EiB') - def test_zebibyte(self): + def test_zebibyte(self) -> None: assert convert_units(bunits.ZB) == (bunits.ZB / bunits.ZB, 'ZiB') assert convert_units(bunits.YB - 1) == ((bunits.YB - 1) / bunits.ZB, 'ZiB') - def test_yobibyte(self): + def test_yobibyte(self) -> None: assert convert_units(bunits.YB) == (bunits.YB / bunits.YB, 'YiB') - def test_kilobyte(self): + def test_kilobyte(self) -> None: assert convert_units(dunits.KB, si=True) == (dunits.KB / dunits.KB, 'KB') assert convert_units(dunits.MB - 1, si=True) == ((dunits.MB - 1) / dunits.KB, 'KB') - def test_megabyte(self): + def test_megabyte(self) -> None: assert convert_units(dunits.MB, si=True) == (dunits.MB / dunits.MB, 'MB') assert convert_units(dunits.GB - 1, si=True) == ((dunits.GB - 1) / dunits.MB, 'MB') - def test_gigabyte(self): + def test_gigabyte(self) -> None: assert convert_units(dunits.GB, si=True) == (dunits.GB / dunits.GB, 'GB') assert convert_units(dunits.TB - 1, si=True) == ((dunits.TB - 1) / dunits.GB, 'GB') - def test_terabyte(self): + def test_terabyte(self) -> None: assert convert_units(dunits.TB, si=True) == (dunits.TB / dunits.TB, 'TB') assert convert_units(dunits.PB - 1, si=True) == ((dunits.PB - 1) / dunits.TB, 'TB') - def test_petabyte(self): + def test_petabyte(self) -> None: assert convert_units(dunits.PB, si=True) == (dunits.PB / dunits.PB, 'PB') assert convert_units(dunits.EB - 1, si=True) == ((dunits.EB - 1) / dunits.PB, 'PB') - def test_exabyte(self): + def test_exabyte(self) -> None: assert convert_units(dunits.EB, si=True) == (dunits.EB / dunits.EB, 'EB') assert convert_units(dunits.ZB - 1, si=True) == ((dunits.ZB - 1) / dunits.EB, 'EB') - def test_zettabyte(self): + def test_zettabyte(self) -> None: assert convert_units(dunits.ZB, si=True) == (dunits.ZB / dunits.ZB, 'ZB') assert convert_units(dunits.YB - 1, si=True) == ((dunits.YB - 1) / dunits.ZB, 'ZB') - def test_yottabyte(self): + def test_yottabyte(self) -> None: assert convert_units(dunits.YB, si=True) == (dunits.YB / dunits.YB, 'YB') class TestUnknownUnits: - def test_unit(self): + def test_unit(self) -> None: with pytest.raises(ValueError): convert_units(1, unit=5) - def test_to(self): + def test_to(self) -> None: with pytest.raises(ValueError): convert_units(1, to=5) diff --git a/tox.ini b/tox.ini index 94cdd98..6d37232 100644 --- a/tox.ini +++ b/tox.ini @@ -16,5 +16,7 @@ commands = [testenv:mypy] deps = mypy + pytest + types-setuptools commands = - mypy binary + mypy .