Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
#41: Add manual documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Oct 23, 2020
1 parent b65865d commit 6a9cfa1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/usage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ ADVANCED usage
good-practices
process-isolation
docker-entrypoint
tests
70 changes: 70 additions & 0 deletions docs/source/usage/tests.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Testing with unittest
=====================

:code:`rkd.api.testing` provides methods for running tasks with output capturing, a well as mocking RKD classes for unit testing of your task methods.
To use our API just extend one of base classes.

Example: Running a task on a fully featured RKD executor
--------------------------------------------------------

.. code:: python
#!/usr/bin/env python3
import os
from rkd.api.testing import FunctionalTestingCase
SCRIPT_DIR_PATH = os.path.dirname(os.path.realpath(__file__))
class TestFunctional(FunctionalTestingCase):
"""
Functional tests case of the whole application.
Runs application like from the shell, captures output and performs assertions on the results.
"""
def test_tasks_listing(self):
""" :tasks """
full_output, exit_code = self.run_and_capture_output([':tasks'])
self.assertIn(' >> Executing :tasks', full_output)
self.assertIn('[global]', full_output)
self.assertIn(':version', full_output)
self.assertIn('succeed.', full_output)
self.assertEqual(0, exit_code)
Example: Mocking RKD-specific dependencies in TaskInterface
-----------------------------------------------------------

.. code:: python
from rkd.api.inputoutput import BufferedSystemIO
from rkd.api.testing import FunctionalTestingCase
# ...
class SomeTestCase(FunctionalTestingCase):
# ...
def test_something_important(self):
task = LineInFileTask() # put your task class there
io = BufferedSystemIO()
BasicTestingCase.satisfy_task_dependencies(task, io=io)
self.assertEqual('something', task.some_method())
Documentation
-------------

.. autoclass:: rkd.api.testing.BasicTestingCase
:members:

.. autoclass:: rkd.api.testing.FunctionalTestingCase
:members:

.. autoclass:: rkd.api.testing.OutputCapturingSafeTestCase
:members:

0 comments on commit 6a9cfa1

Please sign in to comment.