Skip to content

Commit

Permalink
feat(gherkin): add gherkin parser for workflow testing (#464)
Browse files Browse the repository at this point in the history
Closes #463

Co-Authored-By: Giuseppe Steduto <[email protected]>
  • Loading branch information
2 people authored and mdonadoni committed Sep 18, 2024
1 parent 3f08c0a commit cf38a92
Show file tree
Hide file tree
Showing 18 changed files with 1,512 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The list of contributors in alphabetical order:

- [Adelina Lintuluoto](https://orcid.org/0000-0002-0726-1452)
- [Agisilaos Kounelis](https://orcid.org/0000-0001-9312-3189)
- [Alastair Lyall](https://orcid.org/0009-0000-4955-8935)
- [Audrius Mecionis](https://orcid.org/0000-0002-3759-1663)
- [Bruno Rosendo](https://orcid.org/0000-0002-0923-3148)
- [Burt Holzman](https://orcid.org/0000-0001-5235-6314)
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ recursive-include docs *.txt
recursive-include reana_commons *.json
recursive-include reana_commons *.py
recursive-include tests *.py
recursive-include tests *.feature
9 changes: 9 additions & 0 deletions reana_commons/gherkin_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2019, 2021 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""REANA-Commons gherkin parser package."""
95 changes: 95 additions & 0 deletions reana_commons/gherkin_parser/data_fetcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# This file is part of REANA.
# Copyright (C) 2024 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.


# This file provides primitives required for gherkin_parser/functions.py, allowing for different
# implementations in both the client side (api calls) and server side (database access). This avoids
# circular dependencies between reana-commons and reana-client.
"""Base class for fetching data related to a workflow."""

from abc import ABC, abstractmethod


class DataFetcherBase(ABC):
"""Base class for fetching date related to a workflow."""

@abstractmethod
def list_files(self, workflow, file_name=None, page=None, size=None, search=None):
"""Return the list of files for a given workflow workspace.
:param workflow: name or id of the workflow.
:param file_name: file name(s) (glob) to list.
:param page: page number of returned file list.
:param size: page size of returned file list.
:param search: filter search results by parameters.
:returns: a list of dictionaries that have the ``name``, ``size`` and
``last-modified`` keys.
"""
pass

@abstractmethod
def get_workflow_disk_usage(self, workflow, parameters):
"""Display disk usage workflow.
:param workflow: name or id of the workflow.
:param parameters: a dictionary to customize the response. It has the following
(optional) keys:
- ``summarize``: a boolean value to indicate whether to summarize the response
to include only the total workspace disk usage
- ``search``: a string to filter the response by file name
:return: a dictionary containing the ``workflow_id``, ``workflow_name``, and the ``user`` ID, with
a ``disk_usage_info`` keys that contains a list of dictionaries, each of one corresponding
to a file, with the ``name`` and ``size`` keys.
"""
pass

@abstractmethod
def get_workflow_logs(self, workflow, steps=None, page=None, size=None):
"""Get logs from a workflow engine.
:param workflow: name or id of the workflow.
:param steps: list of step names to get logs for.
:param page: page number of returned log list.
:param size: page size of returned log list.
:return: a dictionary with a ``logs`` key containing a JSON string that
contains the requested logs.
"""
pass

@abstractmethod
def get_workflow_status(self, workflow):
"""Get status of previously created workflow.
:param workflow: name or id of the workflow.
:return: a dictionary with the information about the workflow status.
The dictionary has the following keys: ``id``, ``logs``, ``name``,
``progress``, ``status``, ``user``.
"""
pass

@abstractmethod
def get_workflow_specification(self, workflow):
"""Get specification of previously created workflow.
:param workflow: name or id of the workflow.
:returns: a dictionary that cointains two top-level keys: ``parameters``, and
``specification`` (which contains a dictionary created from the workflow specification).
"""
pass

@abstractmethod
def download_file(self, workflow, file_name):
"""Download the requested file if it exists.
:param workflow: name or id of the workflow.
:param file_name: file name or path to the file requested.
:return: a tuple containing file binary content, filename and whether
the returned file is a zip archive containing multiple files.
"""
pass
24 changes: 24 additions & 0 deletions reana_commons/gherkin_parser/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is part of REANA.
# Copyright (C) 2024 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
"""Gherkin parser errors."""


class StepDefinitionNotFound(Exception):
"""The step definition was not found."""

pass


class StepSkipped(Exception):
"""The step was skipped."""

pass


class FeatureFileError(Exception):
"""The feature file is invalid."""

pass
Loading

0 comments on commit cf38a92

Please sign in to comment.