File: test_units.py

package info (click to toggle)
beets 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,016 kB
  • sloc: python: 46,429; javascript: 8,018; xml: 334; sh: 261; makefile: 125
file content (43 lines) | stat: -rw-r--r-- 1,086 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pytest

from beets.util.units import human_bytes, human_seconds


@pytest.mark.parametrize(
    "input_bytes,expected",
    [
        (0, "0.0 B"),
        (30, "30.0 B"),
        (pow(2, 10), "1.0 KiB"),
        (pow(2, 20), "1.0 MiB"),
        (pow(2, 30), "1.0 GiB"),
        (pow(2, 40), "1.0 TiB"),
        (pow(2, 50), "1.0 PiB"),
        (pow(2, 60), "1.0 EiB"),
        (pow(2, 70), "1.0 ZiB"),
        (pow(2, 80), "1.0 YiB"),
        (pow(2, 90), "1.0 HiB"),
        (pow(2, 100), "big"),
    ],
)
def test_human_bytes(input_bytes, expected):
    assert human_bytes(input_bytes) == expected


@pytest.mark.parametrize(
    "input_seconds,expected",
    [
        (0, "0.0 seconds"),
        (30, "30.0 seconds"),
        (60, "1.0 minutes"),
        (90, "1.5 minutes"),
        (125, "2.1 minutes"),
        (3600, "1.0 hours"),
        (86400, "1.0 days"),
        (604800, "1.0 weeks"),
        (31449600, "1.0 years"),
        (314496000, "1.0 decades"),
    ],
)
def test_human_seconds(input_seconds, expected):
    assert human_seconds(input_seconds) == expected