Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. The input file doesn't exist.
  2. Bad input file extension.
  3. Empty input file.
  4. Bad value type (e.g. base and height can't be strings).
  5. A negative value of base or/and height.
  6. Call function without arguments.
  7. Base or height value bigger than 100 (in get_triangle_area function base and height values should be in the range from 1 to 100).


The next step is writing the tests.

Info

All rules of testing exceptions are explained in 3. Testing exceptions chapter. 


Code Block
languagepy
titletest_get_triangle_area()
def test_get_triangle_area():
    # PROPER RESULT TEST
    assert get_triangle_area("./../resources/base.txt",
                             "./../resources/height.txt") == 25
    # BAD FILENAME
    with pytest.raises(FileNotFoundError):
        get_triangle_area("./../resources/flower.txt",
                          "./../resources/height.txt")
    # EMPTY FILE
    with pytest.raises(ValueError):
        get_triangle_area("./../resources/empty.txt",
                          "./../resources/height.txt")
    # BAD VALUE TYPE
    with pytest.raises(ValueError):
        get_triangle_area("./../resources/string_base.txt",
                          "./../resources/height.txt")
    # NEGATIVE VALUE
    with pytest.raises(ValueError):
        get_triangle_area("./../resources/negative_base.txt",
                          "./../resources/height.txt")
    # BAD FILE EXTENSION
    with pytest.raises(FileNotFoundError):
        get_triangle_area("./../resources/base.txt",
                          "./../resources/height.csv")
    # WITHOUT ARGUMENTS
    with pytest.raises(TypeError):
        get_triangle_area()

    # BASE EQUAL 1000
    with pytest.raises(ValueError):
        get_triangle_area("./../resources/mega_base.txt",
                          "./../resources/height.txt")