Пример #1
0
def test_raise_value_error_when_startswith_number_between_1_and_3_endswith_string(
    tmp_path, ):
    d = tmp_path
    some_file = d / "test_task01.txt"
    some_file.write_text("2 test")
    with pytest.raises(ValueError):
        read_magic_number(str(some_file))
Пример #2
0
def test_file_not_exist_error():
    """Test that read_magic_number throw file doesn't exist error"""
    file_path = os.path.join(DIR_PATH, "this_file_will_delete_before_tests.txt")
    try:
        os.remove(file_path)
    except FileNotFoundError:
        pass
    with pytest.raises(ValueError, match=r"file not found"):
        read_magic_number(file_path)
Пример #3
0
def test_negative_case2(tmp_path):
    d = tmp_path / "sub"
    d.mkdir()
    p = d / "data.txt"

    p.write_text("12\n" "0\n\\" "abrakadabra")
    assert read_magic_number(p) == False
Пример #4
0
def test_positive_case1(tmp_path):
    d = tmp_path / "sub"
    d.mkdir()
    p = d / "data.txt"

    p.write_text("1")
    assert read_magic_number(p) == True
Пример #5
0
def test_if_file_does_not_exist_raise_value_error(tmp_path):
    with pytest.raises(ValueError):
        read_magic_number(str(tmp_path))
Пример #6
0
def test_negative_raise_value_error_with_number_over_maximal_border(tmp_path):
    d = tmp_path
    some_file = d / "test_task01.txt"
    some_file.write_text("26")
    assert not read_magic_number(str(some_file))
Пример #7
0
def test_negative_maximal_border_exclusively(tmp_path):
    d = tmp_path
    some_file = d / "test_task01.txt"
    some_file.write_text("3\n lk")
    assert not read_magic_number(str(some_file))
Пример #8
0
def test_positive_medium_number(tmp_path):
    d = tmp_path
    some_file = d / "test_task01.txt"
    some_file.write_text("2.99\n lk")
    assert read_magic_number(str(some_file))
Пример #9
0
def test_positive_minimal_border_inclusively(tmp_path):
    d = tmp_path
    some_file = d / "test_task01.txt"
    some_file.write_text("1\n lk")
    assert read_magic_number(str(some_file))