Example #1
0
def test_convert():
    from graphite_beacon.utils import convert_to_format, convert_from_format

    assert convert_to_format(789874) == 789874
    assert convert_from_format(789874)
    assert convert_to_format(45, 'percent') == "45%"
    assert convert_from_format('45', '%') == 45

    assert convert_to_format(789, 'bytes') == 789
    assert convert_to_format(456789, 'bytes') == '446.1KB'
    assert convert_from_format('456.8', 'KB') == 467763.2
    assert convert_to_format(45678912, 'bytes') == '43.6MB'
    assert convert_from_format('45.7', 'MB') == 47919923.2
    assert convert_to_format(4567891245, 'bytes') == '4.3GB'
    assert convert_from_format('4.6', 'GB') == 4939212390.4

    assert convert_from_format('456.8', 'Kb') == 467763.2
    assert convert_from_format('456.8', 'Kbps') == 456800

    assert convert_to_format(789, 'short') == 789
    assert convert_to_format(456789, 'short') == '456.8K'
    assert convert_from_format('456.8', 'K') == 456800
    assert convert_to_format(45678912, 'short') == '45.7Mil'
    assert convert_from_format('45.7', 'Mil') == 45700000
    assert convert_to_format(4567891245, 'short') == '4.6Bil'
    assert convert_from_format('4.6', 'Bil') == 4600000000

    assert convert_to_format(789, 's') == "13.2m"
    assert convert_from_format('13.2', 'm') == 792
    assert convert_to_format(789456, 's') == "1.3w"
    assert convert_from_format('1.3', 'w') == 786240
    assert convert_to_format(789456234, 's') == "25y"

    assert convert_to_format(79456234, 'ms') == "22.1h"
    assert convert_to_format(34, 'ms') == "34ms"
Example #2
0
def test_convert():
    from graphite_beacon.utils import convert_to_format, convert_from_format

    assert convert_to_format(789874) == 789874
    assert convert_from_format(789874)
    assert convert_to_format(45, 'percent') == "45%"
    assert convert_from_format('45', '%') == 45

    assert convert_to_format(789, 'bytes') == 789
    assert convert_to_format(456789, 'bytes') == '446.1KB'
    assert convert_from_format('456.8', 'KB') == 467763.2
    assert convert_to_format(45678912, 'bytes') == '43.6MB'
    assert convert_from_format('45.7', 'MB') == 47919923.2
    assert convert_to_format(4567891245, 'bytes') == '4.3GB'
    assert convert_from_format('4.6', 'GB') == 4939212390.4

    assert convert_from_format('456.8', 'Kb') == 467763.2
    assert convert_from_format('456.8', 'Kbps') == 456800

    assert convert_to_format(789, 'short') == 789
    assert convert_to_format(456789, 'short') == '456.8K'
    assert convert_from_format('456.8', 'K') == 456800
    assert convert_to_format(45678912, 'short') == '45.7Mil'
    assert convert_from_format('45.7', 'Mil') == 45700000
    assert convert_to_format(4567891245, 'short') == '4.6Bil'
    assert convert_from_format('4.6', 'Bil') == 4600000000

    assert convert_to_format(789, 's') == "13.2m"
    assert convert_from_format('13.2', 'm') == 792
    assert convert_to_format(789456, 's') == "1.3w"
    assert convert_from_format('1.3', 'w') == 786240
    assert convert_to_format(789456234, 's') == "25y"

    assert convert_to_format(79456234, 'ms') == "22.1h"
    assert convert_to_format(34, 'ms') == "34ms"
Example #3
0
def test_convert():
    from graphite_beacon.utils import convert_to_format, convert_from_format

    assert convert_to_format(789874) == 789874
    assert convert_from_format(789874)
    assert convert_to_format(45, 'percent') == "45%"
    assert convert_from_format('45%') == 45

    assert convert_to_format(789, 'bytes') == 789
    assert convert_to_format(456789, 'bytes') == '456.8KB'
    assert convert_from_format('456.8KB') == 456800
    assert convert_to_format(45678912, 'bytes') == '45.7MB'
    assert convert_from_format('45.7MB') == 45700000
    assert convert_to_format(4567891245, 'bytes') == '4.6GB'
    assert convert_from_format('4.6GB') == 4600000000

    assert convert_to_format(789, 'short') == 789
    assert convert_to_format(456789, 'short') == '456.8K'
    assert convert_from_format('456.8K') == 456800
    assert convert_to_format(45678912, 'short') == '45.7Mil'
    assert convert_from_format('45.7Mil') == 45700000
    assert convert_to_format(4567891245, 'short') == '4.6Bil'
    assert convert_from_format('4.6Bil') == 4600000000

    assert convert_to_format(789, 's') == "13.2m"
    assert convert_from_format('13.2m') == 792
    assert convert_to_format(789456, 's') == "1.3w"
    assert convert_from_format('1.3w') == 786240
    assert convert_to_format(789456234, 's') == "25y"

    assert convert_to_format(79456234, 'ms') == "22.1h"
    assert convert_to_format(34, 'ms') == "34ms"