fix entrypoint tests
This commit is contained in:
parent
69b0321e0f
commit
95b7196fc3
3 changed files with 28 additions and 20 deletions
|
|
@ -179,6 +179,17 @@ def default_config(working_directory) -> ConfigFile:
|
||||||
return ConfigFile.from_dict({"configuration": {"working_directory": working_directory}})
|
return ConfigFile.from_dict({"configuration": {"working_directory": working_directory}})
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def default_config_path(default_config) -> str:
|
||||||
|
with tempfile.NamedTemporaryFile(suffix=".yaml", delete=False) as tmp_file:
|
||||||
|
tmp_file.write(json.dumps(default_config._value).encode("utf-8"))
|
||||||
|
|
||||||
|
try:
|
||||||
|
yield tmp_file.name
|
||||||
|
finally:
|
||||||
|
FileHandler.delete(tmp_file.name)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def music_subscriptions_path() -> Path:
|
def music_subscriptions_path() -> Path:
|
||||||
return Path("examples/music_subscriptions.yaml")
|
return Path("examples/music_subscriptions.yaml")
|
||||||
|
|
|
||||||
|
|
@ -11,17 +11,6 @@ from ytdl_sub.subscriptions.subscription import Subscription
|
||||||
from ytdl_sub.utils.file_handler import FileHandler
|
from ytdl_sub.utils.file_handler import FileHandler
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def default_config_for_cli(default_config) -> str:
|
|
||||||
with tempfile.NamedTemporaryFile(suffix=".yaml", delete=False) as tmp_file:
|
|
||||||
tmp_file.write(json.dumps(default_config._value).encode("utf-8"))
|
|
||||||
|
|
||||||
try:
|
|
||||||
yield tmp_file.name
|
|
||||||
finally:
|
|
||||||
FileHandler.delete(tmp_file.name)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def timestamps_file_path():
|
def timestamps_file_path():
|
||||||
timestamps = [
|
timestamps = [
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ def test_subscription_logs_write_to_file(
|
||||||
mock_success_output: bool,
|
mock_success_output: bool,
|
||||||
keep_successful_logs: bool,
|
keep_successful_logs: bool,
|
||||||
):
|
):
|
||||||
num_subscriptions = 3
|
subscripton_names = ["Rick Astley", "Michael Jackson", "Eric Clapton"]
|
||||||
num_runs = 2
|
num_runs = 2
|
||||||
|
|
||||||
config = persist_logs_config_factory(keep_successful_logs=keep_successful_logs)
|
config = persist_logs_config_factory(keep_successful_logs=keep_successful_logs)
|
||||||
|
|
@ -53,7 +53,7 @@ def test_subscription_logs_write_to_file(
|
||||||
except ValueError:
|
except ValueError:
|
||||||
assert not mock_success_output
|
assert not mock_success_output
|
||||||
|
|
||||||
log_directory_files = list(Path(persist_logs_directory).rglob("*"))
|
log_directory_files = sorted(list(Path(persist_logs_directory).rglob("*")))
|
||||||
|
|
||||||
# If dry run or success but success logging disabled, expect 0 log files
|
# If dry run or success but success logging disabled, expect 0 log files
|
||||||
if dry_run or (mock_success_output and not keep_successful_logs):
|
if dry_run or (mock_success_output and not keep_successful_logs):
|
||||||
|
|
@ -61,9 +61,11 @@ def test_subscription_logs_write_to_file(
|
||||||
return
|
return
|
||||||
# If not success, expect 2 log files for both sub errors
|
# If not success, expect 2 log files for both sub errors
|
||||||
elif not mock_success_output:
|
elif not mock_success_output:
|
||||||
assert len(log_directory_files) == num_subscriptions
|
assert len(log_directory_files) == (num_runs * len(subscripton_names))
|
||||||
for log_path in log_directory_files:
|
for log_path, subscription_name in zip(log_directory_files, subscripton_names):
|
||||||
assert bool(re.match(r"\d\.john_smith\.error\.log", log_path.name))
|
subscription_log_file_name = subscription_name.lower().replace(" ", "_")
|
||||||
|
|
||||||
|
assert bool(re.match(rf"\d\.{subscription_log_file_name}\.error\.log", log_path.name))
|
||||||
with open(log_path, "r", encoding="utf-8") as log_file:
|
with open(log_path, "r", encoding="utf-8") as log_file:
|
||||||
assert log_file.readlines()[-1] == (
|
assert log_file.readlines()[-1] == (
|
||||||
f"Please upload the error log file '{str(log_path)}' and make a Github issue "
|
f"Please upload the error log file '{str(log_path)}' and make a Github issue "
|
||||||
|
|
@ -72,13 +74,19 @@ def test_subscription_logs_write_to_file(
|
||||||
)
|
)
|
||||||
# If success and success logging, expect 3 log files
|
# If success and success logging, expect 3 log files
|
||||||
else:
|
else:
|
||||||
assert len(log_directory_files) == (num_runs * num_subscriptions)
|
assert len(log_directory_files) == (num_runs * len(subscripton_names))
|
||||||
for log_file_path in log_directory_files:
|
for log_file_path, subscription_name in zip(
|
||||||
assert bool(re.match(r"\d\.john_smith\.success\.log", log_file_path.name))
|
log_directory_files, subscripton_names * num_runs
|
||||||
|
):
|
||||||
|
subscription_log_file_name = subscription_name.lower().replace(" ", "_")
|
||||||
|
|
||||||
|
assert bool(
|
||||||
|
re.match(rf"\d\.{subscription_log_file_name}\.success\.log", log_file_path.name)
|
||||||
|
)
|
||||||
with open(log_file_path, "r", encoding="utf-8") as log_file:
|
with open(log_file_path, "r", encoding="utf-8") as log_file:
|
||||||
assert (
|
assert (
|
||||||
log_file.readlines()[-1]
|
log_file.readlines()[-1]
|
||||||
== "[ytdl-sub] name=john_smith success=True dry_run=False\n"
|
== f"[ytdl-sub] name={subscription_name} success=True dry_run=False\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue