diff --git a/YouVersion Suggest.alfredworkflow b/YouVersion Suggest.alfredworkflow index b19c455..07ac345 100644 Binary files a/YouVersion Suggest.alfredworkflow and b/YouVersion Suggest.alfredworkflow differ diff --git a/tests/test_compliance.py b/tests/test_compliance.py index d6dcb27..d82b993 100644 --- a/tests/test_compliance.py +++ b/tests/test_compliance.py @@ -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', @@ -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: diff --git a/tests/test_filter_recent_refs.py b/tests/test_filter_recent_refs.py index dee0dd3..fc121d8 100644 --- a/tests/test_filter_recent_refs.py +++ b/tests/test_filter_recent_refs.py @@ -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): diff --git a/tests/test_filter_refs_chapter.py b/tests/test_filter_refs_chapter.py index 0bf69d8..97de162 100644 --- a/tests/test_filter_refs_chapter.py +++ b/tests/test_filter_refs_chapter.py @@ -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(): diff --git a/tests/test_filter_refs_main.py b/tests/test_filter_refs_main.py index 777a27c..576fc7a 100644 --- a/tests/test_filter_refs_main.py +++ b/tests/test_filter_refs_main.py @@ -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__ diff --git a/tests/test_filter_refs_verse.py b/tests/test_filter_refs_verse.py index 0aa98bf..5d9aa04 100644 --- a/tests/test_filter_refs_verse.py +++ b/tests/test_filter_refs_verse.py @@ -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(): @@ -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={}) diff --git a/tests/test_search_ref.py b/tests/test_search_ref.py index 07804e5..abb55a5 100644 --- a/tests/test_search_ref.py +++ b/tests/test_search_ref.py @@ -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: diff --git a/tests/test_view_ref.py b/tests/test_view_ref.py index 5fa1fe0..98766cb 100644 --- a/tests/test_view_ref.py +++ b/tests/test_view_ref.py @@ -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: diff --git a/utilities/add_language.py b/utilities/add_language.py index a911e3c..428a8f3 100644 --- a/utilities/add_language.py +++ b/utilities/add_language.py @@ -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 @@ -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) diff --git a/yv_suggest/data/schema/schema-bible.json b/yv_suggest/data/schema/schema-bible.json index ce816bf..e447b32 100644 --- a/yv_suggest/data/schema/schema-bible.json +++ b/yv_suggest/data/schema/schema-bible.json @@ -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"], diff --git a/yv_suggest/data/schema/schema-chapters.json b/yv_suggest/data/schema/schema-chapters.json index b03cdc5..dfb413b 100644 --- a/yv_suggest/data/schema/schema-chapters.json +++ b/yv_suggest/data/schema/schema-chapters.json @@ -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 } diff --git a/yv_suggest/filter_prefs.py b/yv_suggest/filter_prefs.py index 68e6928..44ddc67 100644 --- a/yv_suggest/filter_prefs.py +++ b/yv_suggest/filter_prefs.py @@ -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) @@ -99,4 +99,4 @@ def main(query_str='{query}', prefs=None): if __name__ == '__main__': - main() + main('{query}') diff --git a/yv_suggest/filter_recent_refs.py b/yv_suggest/filter_recent_refs.py index 4de3772..78d7c79 100644 --- a/yv_suggest/filter_recent_refs.py +++ b/yv_suggest/filter_recent_refs.py @@ -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) @@ -84,4 +84,4 @@ def main(query_str='{query}', prefs=None): print(shared.get_result_list_xml(results)) if __name__ == '__main__': - main() + main('{query}') diff --git a/yv_suggest/filter_refs.py b/yv_suggest/filter_refs.py index c0bba28..b4de441 100644 --- a/yv_suggest/filter_refs.py +++ b/yv_suggest/filter_refs.py @@ -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']) @@ -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: @@ -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}') diff --git a/yv_suggest/search_ref.py b/yv_suggest/search_ref.py index 1b93f2f..990e3aa 100644 --- a/yv_suggest/search_ref.py +++ b/yv_suggest/search_ref.py @@ -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}') diff --git a/yv_suggest/shared.py b/yv_suggest/shared.py index a5f3c49..b49d87d 100644 --- a/yv_suggest/shared.py +++ b/yv_suggest/shared.py @@ -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): diff --git a/yv_suggest/view_ref.py b/yv_suggest/view_ref.py index 94b5305..49f0d6e 100644 --- a/yv_suggest/view_ref.py +++ b/yv_suggest/view_ref.py @@ -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}')