Esempio n. 1
0
def test_check_input_not_list():
    """Test that inputs are of type list."""
    from simplecalc.calculator import _check_input
    from simplecalc.calculator import CalculatorTypeError

    with pytest.raises(CalculatorTypeError) as e:
        _check_input("Test")

    assert "Input must be a list, received: " in str(e)
Esempio n. 2
0
def test_check_input_all_numbers_conversion():
    """Test that the input number conversion works on lists."""
    from simplecalc.calculator import _check_input

    l1 = [0, 1, 2]
    l2 = ["0.", "-1.", "3.5"]
    l3 = ["0", "-1", "-10"]

    assert _check_input(l1) == [0, 1, 2]
    assert _check_input(l2) == [0.0, -1.0, 3.5]
    assert _check_input(l3) == [0, -1, -10]
Esempio n. 3
0
def test_check_input_protect_division_zero():
    """Test that the input conversion fails when checking for zero."""
    from simplecalc.calculator import _check_input
    from simplecalc.calculator import CalculatorValueError

    valid = [0, 1, 2]
    invalid = ["0", "1", "0."]

    with pytest.raises(CalculatorValueError) as e:
        _check_input(invalid, check_zero=True)

    assert _check_input(valid, check_zero=True) == [0, 1, 2]
    assert "No items after the first cannot be zero when diving." in str(e)
Esempio n. 4
0
def test_check_input_all_numbers_error():
    """Test that the input conversion fails as required."""
    from simplecalc.calculator import _check_input
    from simplecalc.calculator import CalculatorValueError

    l1 = ["Error", "Erroring", "Erroringest"]
    l2 = ["0", "0.", "test"]

    with pytest.raises(CalculatorValueError) as e1:
        _check_input(l1)

    with pytest.raises(CalculatorValueError) as e2:
        _check_input(l2)

    assert "All inputs must be a number, received: " in str(e1)
    assert "All inputs must be a number, received: " in str(e2)
Esempio n. 5
0
def test_check_input_list_length():
    """Test that the input length has at least two items."""
    from simplecalc.calculator import _check_input
    from simplecalc.calculator import CalculatorValueError

    with pytest.raises(CalculatorValueError) as e1:
        _check_input([])

    with pytest.raises(CalculatorValueError) as e2:
        _check_input([0])

    with pytest.raises(CalculatorValueError) as e3:
        _check_input(tuple())

    with pytest.raises(CalculatorValueError) as e4:
        _check_input((0, ))

    assert "Input list must have at least two items" in str(e1)
    assert "Input list must have at least two items" in str(e2)
    assert "Input list must have at least two items" in str(e3)
    assert "Input list must have at least two items" in str(e4)