import os
import shlex
from typing import Final

import nox
from nox import Session

os.environ['PDM_IGNORE_SAVED_PYTHON'] = '1'
PYTHON_VERS: Final[list[str]] = ['3.11']


@nox.session(name='min', python=PYTHON_VERS, reuse_venv=True)
def tests_wo_models_cyto(session: Session) -> None:
    """Run all tests despite model loading and Cytoscape tests"""
    cmd_raw = 'pdm install -G cytoscape,spacy-sm,spacy-md,spacy-trf -dG tests'
    cmd = shlex.split(cmd_raw)
    session.run_install(*cmd, external=True)
    cmd_tests_raw = 'pytest -m "not mload and not cyto"'
    cmd_tests = shlex.split(cmd_tests_raw)
    session.run(*cmd_tests)


@nox.session(name='all', python=PYTHON_VERS, reuse_venv=True, default=False)
def tests_all(session: Session) -> None:
    """Run all tests, including Cytoscape Docker container"""
    cmd_raw = 'pdm install -G cytoscape,spacy-sm,spacy-md,spacy-trf -dG tests'
    cmd = shlex.split(cmd_raw)
    session.run_install(*cmd, external=True)

    cmd_tests_raw = 'pytest -n 4'
    cmd_tests = shlex.split(cmd_tests_raw)
    session.run(*cmd_tests)

    session.run('docker', 'desktop', 'start', external=True)
    session.run('docker', 'start', 'cyrest', external=True)

    cmd_tests_raw = 'pytest -m "cyto"'
    cmd_tests = shlex.split(cmd_tests_raw)
    session.run(*cmd_tests)

    session.run('docker', 'stop', 'cyrest', external=True)
