[tox]
minversion = 3.5
# relies on the correct version of Python installed
envlist = tests,mypy-core,mypy-misc
# NOTE: we don't run end2end by default since it requires elaborate setup
# https://github.com/tox-dev/tox/issues/20#issuecomment-247788333
# hack to prevent .tox from crapping to the project directory
toxworkdir={env:TOXWORKDIR_BASE:}{toxinidir}/.tox

[testenv]
passenv =
    CI
    CI_*
    CIRCLE*
    # respect user's cache dirs to prevent tox from crapping into project dir
    MYPY_CACHE_DIR
    PYTHONPYCACHEPREFIX
    MY_CONFIG
    # by default we don't run browser tests to avoid confusing people when they run locally
    # but we want them on CI, so we allow to pass through the variable when we do want to run them
    WITH_BROWSER_TESTS
    UNDER_DOCKER
    # todo ugh this is all so confusing... need to simplify


[testenv:tests]
commands =
    pip install -e .[testing]

    # run this first before we install any extra dependenceies
    {envpython} -m pytest tests/imports.py::test_imports_lazy

    pip install -e .[all]
    pip install -e .[HPI,org]

    # used in some tests
    hpi module install my.google.takeout.parser
    {envpython} -m pytest tests {posargs}


[testenv:end2end]
setenv =
    WITH_BROWSER_TESTS=true
    PYTEST_TIMEOUT=120
commands =
    pip install -e .[testing] hpi
    {envpython} -m pytest tests/end2end_test.py {posargs}


[testenv:mypy-core]
commands =
    pip install -e .[linting]
    {envpython} -m mypy --install-types --non-interactive \
                   # note: sources are tested separately, below
                   -p promnesia --exclude 'sources/*' \
                   # txt report is a bit more convenient to view on CI
                   --txt-report  .coverage.mypy-core  \
                   --html-report .coverage.mypy-core  \
                   {posargs}


[testenv:mypy-misc]
commands =
    pip install -e .[linting]
    pip install -e .[HPI,org]
    # todo install from HPI[all] or something?

    hpi module install my.github.ghexport
    hpi module install my.hypothesis
    hpi module install my.instapaper
    hpi module install my.pocket
    hpi module install my.reddit
    hpi module install my.fbmessenger
    hpi module install my.google.takeout.parser

    {envpython} -m mypy --install-types --non-interactive \
                   -p promnesia.sources \
                   # txt report is a bit more convenient to view on CI
                   --txt-report  .coverage.mypy-misc \
                   --html-report .coverage.mypy-misc \
                   {posargs}

    pip install -e .[testing]
    # ugh. a bit crap to run it separately
    # but first will need to move tests inside the package if we want otherwise?
    # and I recall it was problematic at times..
    {envpython} -m mypy --install-types --non-interactive \
                   tests --exclude 'testdata/*' \
                   {posargs}
