Skip to content

Commit

Permalink
Allow workflow.py to work outside a workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Aug 17, 2014
1 parent 239c318 commit b75c7fb
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 51 deletions.
Binary file modified alfred-workflow.zip
Binary file not shown.
10 changes: 6 additions & 4 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

# OUTPUT_PATH=$(pwd)/tests_output

LOGPATH="$(pwd)/test.log"
mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

LOGPATH="${mydir}/test.log"

function log() {
echo "$@" | tee -a $LOGPATH
Expand All @@ -13,13 +15,13 @@ function log() {
rm -rf $LOGPATH

curdir=$(pwd)
wdir="${curdir}/tests"
wdir="${mydir}/tests"
info_linked=0


if [[ ! -f "info.plist" ]]; then
# link info.plist to parent directory so `background.py` can find it
ln -s "${wdir}/info.plist"
ln -s "${wdir}/info.plist.test" "${mydir}/info.plist"
info_linked=1
fi

Expand Down Expand Up @@ -60,7 +62,7 @@ esac
cd "$curdir"

if [[ $info_linked -eq 1 ]]; then
rm -f "info.plist"
rm -f "${mydir}/info.plist"
fi

exit $ret
File renamed without changes.
12 changes: 12 additions & 0 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from xml.etree import ElementTree as ET
from unicodedata import normalize

from util import create_info_plist, delete_info_plist

from workflow.workflow import (Workflow, Settings, PasswordNotFound,
KeychainError, MATCH_ALL, MATCH_ALLCHARS,
MATCH_ATOM, MATCH_CAPITALS, MATCH_STARTSWITH,
Expand All @@ -42,6 +44,7 @@
'key2': 'hübner'}



def setUp():
pass

Expand Down Expand Up @@ -318,6 +321,15 @@ def test_info_plist(self):
self.assertEqual(self.wf.name, WORKFLOW_NAME)
self.assertEqual(self.wf.bundleid, BUNDLE_ID)

def test_info_plist_missing(self):
"""Info.plist missing"""
delete_info_plist()
try:
with self.assertRaises(IOError):
Workflow()
finally:
create_info_plist()

def test_alfred_env_vars(self):
"""Alfred environmental variables"""

Expand Down
45 changes: 0 additions & 45 deletions tests/test_workflow_dir.py

This file was deleted.

33 changes: 33 additions & 0 deletions tests/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright © 2014 [email protected]
#
# MIT Licence. See http://opensource.org/licenses/MIT
#
# Created on 2014-08-17
#

"""
"""

from __future__ import print_function, unicode_literals

import os

INFO_PLIST_TEST = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'info.plist.test')


INFO_PLIST_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)),
'info.plist')


def create_info_plist():
if not os.path.exists(INFO_PLIST_PATH):
os.symlink(INFO_PLIST_TEST, INFO_PLIST_PATH)


def delete_info_plist():
if os.path.exists(INFO_PLIST_PATH):
os.unlink(INFO_PLIST_PATH)
4 changes: 2 additions & 2 deletions workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ def workflowdir(self):
if os.path.exists(os.path.join(dirpath, 'info.plist')):
self._workflowdir = dirpath
break
elif dirpath == '/': # pragma: no cover
elif dirpath == '/':
# no `info.plist` found
break
dirpath = os.path.dirname(dirpath)
Expand All @@ -1112,7 +1112,7 @@ def workflowdir(self):
if self._workflowdir:
break

if not self._workflowdir: # pragma: no cover
if not self._workflowdir:
raise IOError("'info.plist' not found in directory tree")

return self._workflowdir
Expand Down

0 comments on commit b75c7fb

Please sign in to comment.