示例#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)
示例#2
0
def test_success_bool():
    assert to_bool(True) is True
    assert to_bool(False) is False
示例#3
0
def test_fail_dict():
    with pytest.raises(TypeError):
        to_bool({})
示例#4
0
def test_fail_list():
    with pytest.raises(TypeError):
        to_bool([])
示例#5
0
def test_fail_nonetype():
    with pytest.raises(TypeError):
        to_bool(None)
示例#6
0
def test_fail_str():
    with pytest.raises(ValueError):
        to_bool("1")
示例#7
0
def test_fail_hexstr():
    with pytest.raises(ValueError):
        to_bool("0x02")
示例#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
示例#9
0
def test_fail_int():
    with pytest.raises(ValueError):
        to_bool(2)
    with pytest.raises(ValueError):
        to_bool(-1)
示例#10
0
def test_success_int():
    assert to_bool(1) is True
    assert to_bool(0) is False
示例#11
0
def test_success_float():
    assert to_bool(1.0) is True
    assert to_bool(0.0) is False