Skip to content

Commit

Permalink
Add new utility functions & refactor
Browse files Browse the repository at this point in the history
Helpers
-------

Add new utility functions for running commands and scripts
Move some helpers to util.py

Workflow
--------

Write '.' to debugger on start, so real log messages start on a new line
Use root logger instead of 'workflow'
Add warn_empty() method to Workflow3

Rebuild workflow and docset
  • Loading branch information
deanishe committed Dec 17, 2017
1 parent d92fbda commit 2af73bc
Show file tree
Hide file tree
Showing 16 changed files with 958 additions and 321 deletions.
Binary file not shown.
61 changes: 45 additions & 16 deletions bin/testone
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,57 @@ Run test script(s) with coverage for one package.
Usage:
testone <package.name> <test_script.py>...
testone -h|--help
testone -h
Options:
-h, --help Show this message and exit.
-h Show this message and exit.
Example:
extras/testone workflow.notify tests/test_notify.py
testone workflow.notify tests/test_notify.py
EOS
}

log() {
echo "$@" > /dev/stderr
if [ -t 1 ]; then
red='\033[0;31m'
green='\033[0;32m'
nc='\033[0m'
else
red=
green=
nc=
fi

function log() {
echo "$@"
}

function fail() {
printf "${red}$@${nc}\n"
}

function success() {
printf "${green}$@${nc}\n"
}


while getopts ":h" opt; do
case $opt in
h)
usage
exit 0
;;
\?)
log "Invalid option: -$OPTARG"
exit 1
;;
esac
done
shift $((OPTIND-1))

if [[ "$1" = "-h" ]] || [[ "$1" = "--help" ]]; then
usage
exit 0
fi

if [[ "$1" = "" ]] || [[ "$2" = "" ]]; then
log "ERROR: Missing argument(s)."
fail "missing argument(s)"
log ""
usage
exit 1
Expand All @@ -42,17 +70,16 @@ fi
package="$1"
shift

# export PYTEST_ADDOPTS="--cov-report=term"

# Run tests
pytest --cov="${package}" "$@"
# ret1=$?
ret1=${PIPESTATUS[0]}

echo

case "$ret1" in
0) log "TESTS OK";;
*) log "TESTS FAILED";;
0) success "TESTS OK";;
*) fail "TESTS FAILED";;
esac

log ""
Expand All @@ -64,10 +91,12 @@ ret2=${PIPESTATUS[0]}
echo

case "$ret2" in
0) log "COVERAGE OK" ;;
*) log "COVERAGE FAILED" ;;
0) success "COVERAGE OK" ;;
*) fail "COVERAGE FAILED" ;;
esac

coverage erase

if [[ "$ret1" -ne 0 ]]; then
exit $ret1
fi
Expand Down
Binary file modified docs/Alfred-Workflow.docset.zip
Binary file not shown.
1 change: 1 addition & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ See the :ref:`main index <genindex>` for a list of all classes and methods.

.. include:: notify.rst.inc

.. include:: util.rst.inc
56 changes: 56 additions & 0 deletions docs/api/util.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

.. _api-util:

Utilities & helpers
-------------------


.. currentmodule:: workflow.util

A collection of functions and classes for common workflow-related tasks, such
as running AppleScript or JXA code, or calling an External Trigger.


.. autofunction:: utf8ify

.. autofunction:: applescriptify

.. autofunction:: run_command

.. autofunction:: run_applescript

.. autofunction:: run_jxa

.. autofunction:: run_trigger

.. autoclass:: AppInfo

.. autofunction:: appinfo


Other helpers
^^^^^^^^^^^^^

These utility classes and functions are used internally by Alfred-Workflow,
but may also be useful in your workflow.

.. autoclass:: LockFile
:members:

.. autoclass:: uninterruptible
:members:

.. autofunction:: atomic_writer


.. _api-util-exceptions:


Exceptions
^^^^^^^^^^

The following exceptions, may be raised by utility functions.

.. autoexception:: AcquisitionError

.. autoexception:: subprocess.CalledProcessError
23 changes: 1 addition & 22 deletions docs/api/workflow.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,10 @@ Exceptions
.. currentmodule:: workflow

Alfred-Workflow defines the following exceptions, which may be raised
by the Keychain API or :class:`LockFile`.
by the Keychain API.

.. autoexception:: KeychainError

.. autoexception:: PasswordNotFound

.. autoexception:: workflow.workflow.PasswordExists

.. autoexception:: workflow.workflow.AcquisitionError


.. _api-helpers:

Utilities & helpers
^^^^^^^^^^^^^^^^^^^

.. currentmodule:: workflow.workflow

These utility objects and functions are used internally by Alfred-Workflow,
but may also be useful in your workflow.

.. autoclass:: LockFile
:members:

.. autoclass:: uninterruptible
:members:

.. autofunction:: atomic_writer
2 changes: 2 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ case "$ret2" in
*) fail "COVERAGE FAILED" ;;
esac

coverage erase

if [[ "$ret1" -ne 0 ]]; then
exit $ret1
fi
Expand Down
Loading

0 comments on commit 2af73bc

Please sign in to comment.