2022-04-12 12:59:20 +02:00
|
|
|
# pylint: disable=missing-function-docstring
|
|
|
|
""" Tests on opening hours helpers """
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import os
|
2023-01-16 12:56:12 +01:00
|
|
|
|
2022-04-12 12:59:20 +02:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from mylib.telltale import TelltaleFile
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_telltale_file(tmp_path):
|
2023-01-16 12:56:12 +01:00
|
|
|
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):
|
2023-10-27 13:35:59 +02:00
|
|
|
TelltaleFile(filepath="/tmp/test", dirpath="/var/tmp") # nosec: B108
|
2022-04-12 12:59:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_create_telltale_file_with_filepath_and_invalid_filename():
|
|
|
|
with pytest.raises(AssertionError):
|
2023-10-27 13:35:59 +02:00
|
|
|
TelltaleFile(filepath="/tmp/test", filename="other") # nosec: B108
|
2022-04-12 12:59:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_remove_telltale_file(tmp_path):
|
2023-01-16 12:56:12 +01:00
|
|
|
file = TelltaleFile(filename="test", dirpath=tmp_path)
|
2022-04-12 12:59:20 +02:00
|
|
|
file.update()
|
|
|
|
assert file.remove()
|