Skip to content

Commit

Permalink
Fix Workflow.debugging in production
Browse files Browse the repository at this point in the history
Ensure unit tests encode environment variables.
  • Loading branch information
deanishe committed May 6, 2019
1 parent 5c8c2c9 commit 4dd77c9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def env(**kwargs):
if k in os.environ:
del os.environ[k]
else:
if isinstance(v, unicode):
v = v.encode('utf-8')
else:
v = str(v)
os.environ[k] = v

yield
Expand Down
15 changes: 15 additions & 0 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

from workflow import Workflow

from .conftest import env


def test_args(alfred4):
"""ARGV"""
Expand Down Expand Up @@ -106,5 +108,18 @@ def test_icons():
assert os.path.exists(path)


def test_debugging(alfred4):
"""Debugging"""
tests = [
('', False),
('0', False),
('1', True),
]
for s, wanted in tests:
with env(alfred_debug=s):
wf = Workflow()
assert wf.debugging == wanted, "unexpected debugging"


if __name__ == '__main__': # pragma: no cover
pytest.main([__file__])
2 changes: 1 addition & 1 deletion workflow/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.37
1.37.1
43 changes: 21 additions & 22 deletions workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,31 +1052,30 @@ def alfred_env(self):
data = {}

for key in (
'alfred_debug',
'alfred_preferences',
'alfred_preferences_localhash',
'alfred_theme',
'alfred_theme_background',
'alfred_theme_subtext',
'alfred_version',
'alfred_version_build',
'alfred_workflow_bundleid',
'alfred_workflow_cache',
'alfred_workflow_data',
'alfred_workflow_name',
'alfred_workflow_uid',
'alfred_workflow_version'):

value = os.getenv(key)

if isinstance(value, str):
if key in ('alfred_debug', 'alfred_version_build',
'alfred_theme_subtext'):
'debug',
'preferences',
'preferences_localhash',
'theme',
'theme_background',
'theme_subtext',
'version',
'version_build',
'workflow_bundleid',
'workflow_cache',
'workflow_data',
'workflow_name',
'workflow_uid',
'workflow_version'):

value = os.getenv('alfred_' + key, '')

if value:
if key in ('debug', 'version_build', 'theme_subtext'):
value = int(value)
else:
value = self.decode(value)

data[key[7:]] = value
data[key] = value

self._alfred_env = data

Expand Down Expand Up @@ -1113,7 +1112,7 @@ def debugging(self):
:rtype: ``bool``
"""
return self.alfred_env.get('debug') == '1'
return self.alfred_env.get('debug') == 1

@property
def name(self):
Expand Down

0 comments on commit 4dd77c9

Please sign in to comment.