Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Mar 30, 2015
2 parents 1961a84 + 4e6d7cf commit 5fa3a0a
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 68 deletions.
Binary file modified YouVersion Suggest.alfredworkflow
Binary file not shown.
7 changes: 3 additions & 4 deletions tests/test_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@


def test_pep8():
'''all Python files should comply with PEP 8'''
files = glob.iglob('*/*.py')
for file in files:
test_pep8.__doc__ = '{} should comply with pep8'.format(file)
style_guide = pep8.StyleGuide(quiet=True)
total_errors = style_guide.input_file(file)
msg = '{} is not pep8-compliant'.format(file)
msg = '{} does not comply with PEP 8'.format(file)
yield nose.assert_equal, total_errors, 0, msg


def test_json():
'''all JSON files should comply with respective schemas'''
schemas = {
'schema-languages': 'yv_suggest/data/languages.json',
'schema-defaults': 'yv_suggest/data/defaults.json',
Expand All @@ -32,8 +33,6 @@ def test_json():
schema = json.load(schema_file)
data_paths = glob.iglob(data_path_pattern)
for data_path in data_paths:
test_json.__doc__ = '{} should be schema-compliant'.format(
data_path)
with open(data_path) as data_file:
data = json.load(data_file)
try:
Expand Down
7 changes: 0 additions & 7 deletions tests/test_filter_recent_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
'8/rev.19.16', '111/rev.22', '8/psa.23']


def test_query_param():
"""should use received query parameter as default filter query"""
spec = inspect.getargspec(yvs.main)
default_query_str = spec.defaults[0]
nose.assert_equal(default_query_str, '{query}')


def test_show_all():
"""should show all recent references when given empty query"""
with ctx.use_recent_refs(recent_refs):
Expand Down
7 changes: 4 additions & 3 deletions tests/test_filter_refs_chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def test_id():

def test_nonexistent():
"""should not match nonexistent chapters"""
results = yvs.get_result_list('psalm 160', prefs={})
nose.assert_equal(len(results), 1)
nose.assert_equal(results[0]['title'], 'Psalm 150 (NIV)')
results = yvs.get_result_list('ch 99', prefs={})
nose.assert_equal(len(results), 2)
nose.assert_equal(results[0]['title'], '1 Chronicles 29 (NIV)')
nose.assert_equal(results[1]['title'], '2 Chronicles 36 (NIV)')


def test_zero_chapter():
Expand Down
7 changes: 0 additions & 7 deletions tests/test_filter_refs_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ def test_null_result():
nose.assert_equal(title.text, 'No Results')


def test_query_param():
"""should use typed Alfred query as default query string"""
spec = inspect.getargspec(yvs.main)
default_query_str = spec.defaults[0]
nose.assert_equal(default_query_str, '{query}')


def test_source_only():
"""should run script assuming script is not a file"""
yvs.shared.sys.argv[0] = yvs.shared.__file__
Expand Down
15 changes: 11 additions & 4 deletions tests/test_filter_refs_verse.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def test_space_separator():
nose.assert_equal(results[0]['title'], 'Luke 4:8 (NIV)')


def test_range():
"""should match verse ranges"""
results = yvs.get_result_list('1 cor 13.4-7', prefs={})
def test_zero_verse():
"""should interpret ignore zeroth verse if given"""
results = yvs.get_result_list('ps 23:0', prefs={})
nose.assert_equal(len(results), 1)
nose.assert_equal(results[0]['title'], '1 Corinthians 13:4-7 (NIV)')
nose.assert_equal(results[0]['title'], 'Psalm 23 (NIV)')


def test_id():
Expand All @@ -48,6 +48,13 @@ def test_id():
nose.assert_equal(results[0]['uid'], 'yvs-111/luk.4.8')


def test_range():
"""should match verse ranges"""
results = yvs.get_result_list('1 cor 13.4-7', prefs={})
nose.assert_equal(len(results), 1)
nose.assert_equal(results[0]['title'], '1 Corinthians 13:4-7 (NIV)')


def test_range_id():
"""should use correct ID for verse ranges"""
results = yvs.get_result_list('1 cor 13.4-7', prefs={})
Expand Down
7 changes: 0 additions & 7 deletions tests/test_search_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
import inspect


def test_query_param():
"""should use received query parameter as default ref ID"""
spec = inspect.getargspec(yvs.main)
default_query_str = spec.defaults[0]
nose.assert_equal(default_query_str, '{query}')


def test_url_open_chapter():
"""should attempt to open chapter URL using webbrowser module"""
with ctx.mock_webbrowser(yvs) as mock:
Expand Down
7 changes: 0 additions & 7 deletions tests/test_view_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
import inspect


def test_query_param():
"""should use received query parameter as default ref ID"""
spec = inspect.getargspec(yvs.main)
default_query_str = spec.defaults[0]
nose.assert_equal(default_query_str, '{query}')


def test_url_open():
"""should attempt to open URL using webbrowser module"""
with ctx.mock_webbrowser(yvs) as mock:
Expand Down
8 changes: 3 additions & 5 deletions utilities/add_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# -*- coding: utf-8 -*-

# This script is a handy (albeit imperfect) tool for automatically adding
# support for any language to YouVersion Suggest. Please see the example
# function calls below for details on using it.
# support for any language to YouVersion Suggest.

from __future__ import unicode_literals
from pyquery import PyQuery as pq
Expand Down Expand Up @@ -96,9 +95,8 @@ def get_versions(params):

for version_elem in version_elems:
version = get_version(version_elem)
if (params['max_version_id'] and
(version['id'] <= params['max_version_id']) or
(not params['max_version_id'])):
if not params['max_version_id'] or (params['max_version_id'] and
version['id'] <= params['max_version_id']):
versions.append(version)

versions.sort(key=get_item_name)
Expand Down
2 changes: 1 addition & 1 deletion yv_suggest/data/schema/schema-bible.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"title": "Book ID",
"description": "The ID used by YouVersion to uniquely identify this book",
"type": "string",
"pattern": "^[1-9]?[a-z]+$"
"pattern": "^([a-z]{3}|[1-9][a-z]{2})$"
}
},
"required": ["name", "id"],
Expand Down
5 changes: 3 additions & 2 deletions yv_suggest/data/schema/schema-chapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "A list of chapter counts for each book of the Bible",
"type": "object",
"patternProperties": {
"^[1-9]?[a-z]+$": {
"^([a-z]{3}|[1-9][a-z]{2})$": {
"title": "Chapter Count",
"type": "integer",
"minimum": 1
}
}
},
"additionalProperties": false
}
4 changes: 2 additions & 2 deletions yv_suggest/filter_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_result_list(query_str, prefs=None):
return results


def main(query_str='{query}', prefs=None):
def main(query_str, prefs=None):

results = get_result_list(query_str, prefs)

Expand All @@ -99,4 +99,4 @@ def main(query_str='{query}', prefs=None):


if __name__ == '__main__':
main()
main('{query}')
4 changes: 2 additions & 2 deletions yv_suggest/filter_recent_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_result_list(query_str, prefs=None):
return results


def main(query_str='{query}', prefs=None):
def main(query_str, prefs=None):

results = get_result_list(query_str, prefs)

Expand All @@ -84,4 +84,4 @@ def main(query_str='{query}', prefs=None):
print(shared.get_result_list_xml(results))

if __name__ == '__main__':
main()
main('{query}')
28 changes: 16 additions & 12 deletions yv_suggest/filter_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def get_result_list(query_str, prefs=None):
matching_books = get_matching_books(bible['books'], query)
chosen_version = None

if 'chapter' not in query or query['chapter'] == 0:
query['chapter'] = 1

if 'verse' in query and query['verse'] == 0:
del query['verse']

if 'version' in query:
chosen_version = guess_version(bible['versions'], query['version'])

Expand All @@ -63,25 +69,23 @@ def get_result_list(query_str, prefs=None):
chosen_version = shared.get_version(bible['versions'],
bible['default_version'])

if 'chapter' not in query or query['chapter'] == 0:
query['chapter'] = 1

# Build results list from books that matched the query
for book in matching_books:

# Result information
result = {}

if query['chapter'] > chapters[book['id']]:
query['chapter'] = chapters[book['id']]
chosen_chapter = query['chapter']
if chosen_chapter > chapters[book['id']]:
chosen_chapter = chapters[book['id']]

# Find chapter if given
result['uid'] = '{book}.{chapter}'.format(
book=book['id'],
chapter=query['chapter'])
chapter=chosen_chapter)
result['title'] = '{book} {chapter}'.format(
book=book['name'],
chapter=query['chapter'])
chapter=chosen_chapter)

if 'verse' in query:

Expand Down Expand Up @@ -110,20 +114,20 @@ def get_result_list(query_str, prefs=None):
return results


# Outputs an Alfred XML string from the given query string
def main(query_str='{query}', prefs=None):
def main(query_str, prefs=None):

results = get_result_list(query_str, prefs)

if not results:
results = [{
'uid': 'yvs-no-results',
'valid': 'no',
'title': 'No Results',
'subtitle': 'No bible references matching \'{}\''.format(query_str)
'subtitle': 'No bible references matching \'{}\''
.format(query_str),
'valid': 'no'
}]

print(shared.get_result_list_xml(results))

if __name__ == '__main__':
main()
main('{query}')
4 changes: 2 additions & 2 deletions yv_suggest/search_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def open_search_url(ref_uid, prefs=None):
webbrowser.open(get_search_url(ref_uid, prefs))


def main(ref_uid='{query}', prefs=None, save=True):
def main(ref_uid, prefs=None, save=True):
if save:
shared.push_recent_ref(ref_uid)
open_search_url(ref_uid, prefs)

if __name__ == '__main__':
main()
main('{query}')
2 changes: 1 addition & 1 deletion yv_suggest/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
prefs_path = os.path.join(alfred_data_dir, 'preferences.json')
recent_refs_path = os.path.join(alfred_data_dir, 'recent.json')

max_recent_refs = 10
max_recent_refs = 20


def merge_dictionaries(*dictionaries):
Expand Down
4 changes: 2 additions & 2 deletions yv_suggest/view_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def open_ref_url(ref_uid):
webbrowser.open(get_ref_url(ref_uid))


def main(ref_uid='{query}', save=True):
def main(ref_uid, save=True):
if save:
shared.push_recent_ref(ref_uid)
open_ref_url(ref_uid)

if __name__ == '__main__':
main()
main('{query}')

0 comments on commit 5fa3a0a

Please sign in to comment.