From 106e40920c5fd466782a1a0da8bcb022bf24856a Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Dec 2023 13:56:26 +0100 Subject: [PATCH] add cli test --- tests/test_cli.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/test_cli.py diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..633bc4a --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,54 @@ +import re +import time +from pathlib import Path + +import pytest + +from pytest_abra import DirManager +from pytest_abra.utils import get_session_id + + +def test_get_session_id_random(tmp_path: Path): + args_output_dir = tmp_path + args_resume = False + args_session_id = None + session_id = get_session_id(args_output_dir, args_resume, args_session_id) + assert re.search("\d+-\d+-\d+", session_id) + + +def test_get_session_id_explicit1(tmp_path: Path): + args_output_dir = tmp_path + args_resume = False + args_session_id = "abc" + session_id = get_session_id(args_output_dir, args_resume, args_session_id) + assert session_id == "abc" + + +def test_get_session_id_explicit2(tmp_path: Path): + args_output_dir = tmp_path + args_resume = True + args_session_id = "abc" + session_id = get_session_id(args_output_dir, args_resume, args_session_id) + assert session_id == "abc" + + +@pytest.mark.slow +def test_get_session_id_integration(tmp_path: Path): + assert len(list(tmp_path.iterdir())) == 0 + session_id_1 = get_session_id(args_output_dir=tmp_path, args_resume=False, args_session_id=None) + + DIR = DirManager(output_dir=tmp_path, session_id=session_id_1) + DIR.create_all_dirs() + assert len(list(tmp_path.iterdir())) == 1 + + time.sleep(1.1) # get_session_id won't be unique if called without time passed + session_id_2 = get_session_id(args_output_dir=tmp_path, args_resume=False, args_session_id=None) + DIR = DirManager(output_dir=tmp_path, session_id=session_id_2) + DIR.create_all_dirs() + assert len(list(tmp_path.iterdir())) == 2 + + session_id_3 = get_session_id(args_output_dir=tmp_path, args_resume=True, args_session_id=None) + assert session_id_2 == session_id_3 + + session_id_4 = get_session_id(args_output_dir=tmp_path, args_resume=True, args_session_id="abc") + assert session_id_4 == "abc"