Skip to content

Commit

Permalink
Merge pull request #105 from LUMC/release1.3.0
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
rhpvorderman authored Apr 20, 2020
2 parents 844740a + 2cccc3e commit 45887cd
Show file tree
Hide file tree
Showing 31 changed files with 747 additions and 453 deletions.
28 changes: 12 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: python
install:
- pip install tox
dist: xenial
python: 3.5 # Use the oldest supported version of python as default.
python: 3.6 # Use the oldest supported version of python as default.
script:
- tox -e $TOX_ENV
matrix:
Expand All @@ -11,30 +11,25 @@ matrix:
# Use default python3 version here.
- env: TOX_ENV=docs
- env: TOX_ENV=lint

# UNIT TESTS
# On most recent versions of python.
- python: 3.6
env: TOX_ENV=py36
- python: 3.7
env: TOX_ENV=py37
- python: 3.8
env: TOX_ENV=py38
- python: 3.5
env: TOX_ENV=py35
- env: TOX_ENV=py36
install:
- pip install codecov
- pip install tox
after_success:
- codecov -v # -v to make sure coverage upload works.
- python: 3.7
env: TOX_ENV=py37
- python: 3.8
env: TOX_ENV=py38

# FUNCTIONAL TESTS
- python: 3.6
env: TOX_ENV=snakemake
- python: 3.7
env: TOX_ENV=snakemake
# Use default python here.
- env: TOX_ENV=snakemake
- env: TOX_ENV=miniwdl
- env: TOX_ENV=cromwell
before_install:
install:
# Install conda
- export MINICONDA=${HOME}/miniconda
- export PATH=${MINICONDA}/bin:${PATH}
Expand All @@ -44,5 +39,6 @@ matrix:
- conda config --add channels defaults
- conda config --add channels bioconda
- conda config --add channels conda-forge
- conda create -n my_env cromwell tox # Install tox for good integration within the conda env.
# TODO: Upgrade cromwell once https://github.com/broadinstitute/cromwell/pull/5456 is fixed.
- conda create -n my_env cromwell=48 tox # Install tox for good integration within the conda env.
- source activate my_env
36 changes: 36 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,42 @@ Changelog
.. This document is user facing. Please word the changes in such a way
.. that users understand how the changes affect the new version.
version 1.3.0
---------------------------
Python 3.6 and pytest 5.4.0.0 are now minimum requirements for pytest-workflow.
This was necessary for fixing the deprecation warning issue and the issue with
the subdirectory evaluation. This also gave the opportunity to simplify the
source code using new python 3.6 syntax.

+ Using the ``name`` keyword argument in workflow marks will be deprecated
from 1.4.0 onwards. A warning will be given if this is used. For example:
``pytest.mark.workflow(name="my_workflow")``. Use the name as argument
instead: ``pytest.mark.workflow("my_workflow")``.
+ Allow running custom tests on multiple workflows. You can now use
``pytest.mark.workflow("worflow name 1", "workflow name 2", ...)``.
(`Issue #75 <https://github.com/LUMC/pytest-workflow/issues/75>`_)
+ Add a miniwdl example to the documentation.
+ Added a ``--symlink`` flag to the CLI that changes the copying behavior.
Instead of copying, it creates a similar directory structure where all files
are linked to with symbolic links. (`Issue #96
<https://github.com/LUMC/pytest-workflow/issues/98>`_)
+ Refactored the code base. Python 3.6's f-strings and type annotation were
used consistently throughout the project. Some code was rewritten to be more
concise and readable.
+ Improved speed for searching string content in files. This was achieved by
removing intermediate functions and simplifying the search function.
+ Improved speed for calculating md5sums by increasing the read buffer size
from 8k to 64k.
+ Solve issue where pytest would display a lot of deprecation warnings when
running pytest-workflow. (`Issue #98
<https://github.com/LUMC/pytest-workflow/issues/98>`_)
+ Fix issues with later versions of Cromwell and Snakemake in CI testing.
+ Add correct subdirectory evaluation to fix issue where ``/parent-dir/child``
was evaluated as a subdirectory of ``/parent`` due to starting with the same
string. (`Issue #95 <https://github.com/LUMC/pytest-workflow/issues/95>`_)
+ Fix error in cromwell example which did not allow it to remove folders
correctly.

version 1.2.3
---------------------------
+ Added missing ``help`` section for ``--tag`` on the CLI.
Expand Down
45 changes: 42 additions & 3 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ created by the same user that runs the test (docker containers run as root by
default). This will ensure that files can be deleted by pytest-workflow
afterwards.

The following yaml file tests a Cromwell pipeline. In this case Cromwell is
installed via conda. The conda installation adds a wrapper to Cromwell so it
can be used as a command, instead of having to use the jar.
The following yaml file tests a WDL pipeline run with Cromwell. In this case
Cromwell is installed via conda. The conda installation adds a wrapper to
Cromwell so it can be used as a command, instead of having to use the jar.

.. code-block:: yaml
Expand All @@ -70,3 +70,42 @@ can be used as a command, instead of having to use the jar.
contains:
- "WorkflowSucceededState"
WDL with miniwdl example
------------------------

For miniwdl please consult the `runner reference
<https://miniwdl.readthedocs.io/en/stable/runner_reference.html>`_ for more
information on the localization of output files as well as options to modify
the running of miniwdl from the environment.

Miniwdl will localize all the output files to an ``output_links`` directory
inside the test output directory. If you have a workflow with the output:

.. code-block::
output {
File moo_file = moo_task.out
Array[File] stats = moo_task.stats_files
}
Inside the ``output_links`` directory the directories ``moo_file`` and
``stats`` will be created. Inside these directories will be the produced files.

The following yaml file tests a WDL pipeline run with miniwdl.

.. code-block:: yaml
- name: My pipeline
command: miniwdl run -i inputs.json -d test-output/ moo.wdl
files:
- path: test-output/output_links/moo_file/moo.txt.gz
md5sum: 173fd8023240a8016033b33f42db14a2
- path: test-output/output_links/stats/number_of_moos_per_cow.tsv
contains:
- 42
- path: test-output/output_links/stats/joy_invoking_moos.tsv
must_not_contain:
- 0
Please note that the trailing slash in ``-d test-output/`` is important. It
will ensure the files end up in the ``test-output`` directory.
14 changes: 12 additions & 2 deletions docs/running_pytest_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Specific pytest options for pytest workflow
:func: __pytest_workflow_cli
:prog: pytest

Temporary directory cleanup
---------------------------
Temporary directory cleanup and creation
----------------------------------------

The temporary directories are cleaned up after the tests are completed.
If you wish to inspect the output of a failing
Expand All @@ -51,6 +51,16 @@ use ``--basetemp <dir>`` to change pytest's base temp directory.
DO NOT use ``--basetemp`` on directories where none of the
contents should be deleted.

The temporary directories created are copies of pytest's root directory, the
directory from which it runs the tests. If you have lots of tests, and if you
have a large repository, this may take a lot of disk space. To alleviate this
you can use the ``--symlink`` flag which will create the same directory layout
but instead symlinks the files instead of copying them. This is *slower* for
lots of small files, and it carries with it the risk that the tests may alter
files from your work directory. If there are a lot of large files and files are
used read-only in tests, then it will use a lot less disk space and be faster
as well.

Running multiple workflows simultaneously
-----------------------------------------

Expand Down
27 changes: 19 additions & 8 deletions docs/writing_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,34 @@ workflow.
import pathlib
import pytest
@pytest.mark.workflow(name='files containing numbers')
@pytest.mark.workflow('files containing numbers')
def test_div_by_three(workflow_dir):
number_file = pathlib.Path(workflow_dir, "123.txt")
number_file_content = number_file.read_text()
assert int(number_file_content) % 3 == 0
The ``@pytest.mark.workflow(name='files containing numbers')`` marks the test
as belonging to a workflow named ``files containing numbers``. The mark can
also be written without the explicit ``name`` key as
``@pytest.mark.workflow('files containing nummbers')``. This test will only run
if the workflow 'files containing numbers' has run.
The ``@pytest.mark.workflow('files containing numbers')`` marks the test
as belonging to a workflow named ``files containing numbers``. This test will
only run if the workflow 'files containing numbers' has run.

Multiple workflows can use the same custom test like this:

.. code-block:: python
import pathlib
import pytest
@pytest.mark.workflow('my_workflow', 'another_workflow',
'yet_another_workflow')
def test_ensure_long_logs_are_written(workflow_dir):
log = pathlib.Path(workflow_dir, "log.out")
assert len(log.readtext()) > 10000
``workflow_dir`` is a fixture. It does not work without a
``pytest.mark.workflow('workflow_name')`` mark. This is a
`pathlib.Path <https://docs.python.org/3/library/pathlib.html>`_ object that
points to the folder where the named workflow was executed. This allows writing of
advanced python tests for each file produced by the workflow.
points to the folder where the named workflow was executed. This allows writing
of advanced python tests for each file produced by the workflow.

.. note::

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pyyaml
pytest>=4
pytest>=5.4.0
jsonschema
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

setup(
name="pytest-workflow",
version="1.2.3",
version="1.3.0",
description="A pytest plugin for configuring workflow/pipeline tests "
"using YAML files",
author="Leiden University Medical Center",
Expand All @@ -40,7 +40,6 @@
classifiers=[
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
Expand All @@ -49,9 +48,10 @@
"GNU Affero General Public License v3 or later (AGPLv3+)",
"Framework :: Pytest",
],
python_requires=">=3.5", # Because we use type annotation.
# Because we use the resolve(strict=False) feature from pathlib.
python_requires=">=3.6",
install_requires=[
"pytest>=4",
"pytest>=5.4.0", # To use from_parent node instantiation.
"pyyaml",
"jsonschema"
],
Expand Down
22 changes: 0 additions & 22 deletions src/pytest_workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,3 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with pytest-workflow. If not, see <https://www.gnu.org/licenses/

import re
import shutil
from pathlib import Path
from typing import List


# This function was created to ensure the same conversion is used throughout
# pytest-workflow.
def replace_whitespace(string: str, replace_with: str = '_') -> str:
"""
Replaces all whitespace with the string in replace_with.
:param string: input string
:param replace_with: Replace whitespace with this string. Default: '_'
:return: The string with whitespace converted.
"""
return re.sub(r'\s+', replace_with, string)


def rm_dirs(directories: List[Path]):
for directory in directories:
shutil.rmtree(str(directory))
Loading

0 comments on commit 45887cd

Please sign in to comment.