Beispiel #1
0
def test_fail_float():
    with pytest.raises(ValueError):
        to_bool(1.23)
    with pytest.raises(ValueError):
        to_bool(0.9)
    with pytest.raises(ValueError):
        to_bool(-1.0)
Beispiel #2
0
def test_success_bool():
    assert to_bool(True) is True
    assert to_bool(False) is False
Beispiel #3
0
def test_fail_dict():
    with pytest.raises(TypeError):
        to_bool({})
Beispiel #4
0
def test_fail_list():
    with pytest.raises(TypeError):
        to_bool([])
Beispiel #5
0
def test_fail_nonetype():
    with pytest.raises(TypeError):
        to_bool(None)
Beispiel #6
0
def test_fail_str():
    with pytest.raises(ValueError):
        to_bool("1")
Beispiel #7
0
def test_fail_hexstr():
    with pytest.raises(ValueError):
        to_bool("0x02")
Beispiel #8
0
def test_success_hexstr():
    assert to_bool("0x1") is True
    assert to_bool("0x0") is False
    assert to_bool("0x0001") is True
    assert to_bool("0x0000") is False
Beispiel #9
0
def test_fail_int():
    with pytest.raises(ValueError):
        to_bool(2)
    with pytest.raises(ValueError):
        to_bool(-1)
Beispiel #10
0
def test_success_int():
    assert to_bool(1) is True
    assert to_bool(0) is False
Beispiel #11
0
def test_success_float():
    assert to_bool(1.0) is True
    assert to_bool(0.0) is False