Example #1
0
def test_not_existing_file_raises_error(tmp_path):
    path_to_nowhere = tmp_path / "not_existing.txt"
    with pytest.raises(ValueError):
        read_magic_number(path_to_nowhere)
Example #2
0
def test_file_with_almost_3_gives_true(tmp_path):
    path_to_number = tmp_path / "number.txt"
    with open(path_to_number, "w") as suitable:
        suitable.write("2.9999")
    assert read_magic_number(path_to_number)
Example #3
0
def test_file_with_number_less_than_one_gives_false(tmp_path):
    path_to_number = tmp_path / "number.txt"
    with open(path_to_number, "w") as nonsuitable:
        nonsuitable.write("0.9999")
    assert not read_magic_number(path_to_number)
Example #4
0
def test_file_with_1_gives_true(tmp_path):
    path_to_number = tmp_path / "number.txt"
    with open(path_to_number, "w") as one:
        one.write("1\n")
    assert read_magic_number(path_to_number)
Example #5
0
def test_file_with_3_gives_false(tmp_path):
    path_to_number = tmp_path / "number.txt"
    with open(path_to_number, "w") as three:
        three.write("3\n")
    assert not read_magic_number(path_to_number)
Example #6
0
def test_empty_file_gives_false(tmp_path):
    path_to_empty = tmp_path / "empty.txt"
    with open(path_to_empty, "w"):
        pass
    assert not read_magic_number(path_to_empty)
Example #7
0
def test_file_with_text_gives_false(tmp_path):
    path_to_text = tmp_path / "text.txt"
    with open(path_to_text, "w") as text:
        text.write("some text inside")
    assert not read_magic_number(path_to_text)
Example #8
0
def test_text_file():
    with pytest.raises(ValueError):
        hw1.read_magic_number("homework4/test/nan.txt")
Example #9
0
def test_not_existing_file():
    with pytest.raises(ValueError):
        hw1.read_magic_number("homework4/test/wrong.txt")
Example #10
0
def test_empty_file():
    with pytest.raises(ValueError):
        hw1.read_magic_number("homework4/test/empty.txt")
Example #11
0
def test_read_magic_number(file: str, expected_result: bool):

    actual_result = hw1.read_magic_number(file)

    assert actual_result == expected_result
Example #12
0
def test_read_magic_number(open_del_file, expected_result: bool):
    assert read_magic_number(open_del_file) == expected_result
Example #13
0
def test_not_a_number_error(open_del_file):
    with pytest.raises(ValueError, match="Not a number"):
        read_magic_number(open_del_file)
Example #14
0
def test_file_existence_error():
    with pytest.raises(ValueError, match="No such file"):
        read_magic_number("any_file.txt")