Esempio n. 1
0
def test_byte_spec_validation():
    bs = utils.ByteSpecification()

    assert bs.validate(None, 1) == 1
    assert bs.validate(None, 1.0) == 1.0

    assert bs.validate(None, "1K") == 1024
    assert bs.validate(None, "1M") == 1024 * 1024
    assert bs.validate(None, "1G") == 1024 * 1024 * 1024
    assert bs.validate(None, "1T") == 1024 * 1024 * 1024 * 1024

    with pytest.raises(traitlets.TraitError):
        bs.validate(None, "NK")

    with pytest.raises(traitlets.TraitError):
        bs.validate(None, "1m")
Esempio n. 2
0
def test_byte_spec_validation():
    bs = utils.ByteSpecification()

    assert bs.validate(None, 1) == 1
    assert bs.validate(None, 1.0) == 1.0

    assert bs.validate(None, '1K') == 1024
    assert bs.validate(None, '1M') == 1024 * 1024
    assert bs.validate(None, '1G') == 1024 * 1024 * 1024
    assert bs.validate(None, '1T') == 1024 * 1024 * 1024 * 1024

    with pytest.raises(traitlets.TraitError):
        bs.validate(None, 'NK')

    with pytest.raises(traitlets.TraitError):
        bs.validate(None, '1m')