54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
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"
|