python-mylib/tests/test_telltale.py

40 lines
1.1 KiB
Python
Raw Normal View History

2022-04-12 12:59:20 +02:00
# pylint: disable=missing-function-docstring
""" Tests on opening hours helpers """
import datetime
import os
2022-04-12 12:59:20 +02:00
import pytest
from mylib.telltale import TelltaleFile
def test_create_telltale_file(tmp_path):
filename = "test"
2022-04-12 12:59:20 +02:00
file = TelltaleFile(filename=filename, dirpath=tmp_path)
assert file.filename == filename
assert file.dirpath == tmp_path
assert file.filepath == os.path.join(tmp_path, filename)
assert not os.path.exists(file.filepath)
assert file.last_update is None
file.update()
assert os.path.exists(file.filepath)
assert isinstance(file.last_update, datetime.datetime)
def test_create_telltale_file_with_filepath_and_invalid_dirpath():
with pytest.raises(AssertionError):
TelltaleFile(filepath="/tmp/test", dirpath="/var/tmp")
2022-04-12 12:59:20 +02:00
def test_create_telltale_file_with_filepath_and_invalid_filename():
with pytest.raises(AssertionError):
TelltaleFile(filepath="/tmp/test", filename="other")
2022-04-12 12:59:20 +02:00
def test_remove_telltale_file(tmp_path):
file = TelltaleFile(filename="test", dirpath=tmp_path)
2022-04-12 12:59:20 +02:00
file.update()
assert file.remove()