-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
2,370 additions
and
883 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from contextlib import contextmanager | ||
from io import BytesIO | ||
import sys | ||
|
||
|
||
@contextmanager | ||
def redirect_stdout(): | ||
"""temporarily redirect stdout to new output stream""" | ||
original_stdout = sys.stdout | ||
out = BytesIO() | ||
try: | ||
sys.stdout = out | ||
yield out | ||
finally: | ||
sys.stdout = original_stdout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
import nose.tools as nose | ||
import glob | ||
import json | ||
import pep8 | ||
import jsonschema | ||
|
||
|
||
def test_pep8(): | ||
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) | ||
yield nose.assert_equal, total_errors, 0, msg | ||
|
||
|
||
def test_json(): | ||
schemas = { | ||
'schema-languages': 'yv_suggest/data/languages.json', | ||
'schema-defaults': 'yv_suggest/data/defaults.json', | ||
'schema-chapters': 'yv_suggest/data/bible/chapters.json', | ||
'schema-bible': 'yv_suggest/data/bible/language-*.json' | ||
} | ||
for schema_name, data_path_pattern in schemas.iteritems(): | ||
schema_path = 'yv_suggest/data/schema/{}.json'.format(schema_name) | ||
with open(schema_path) as schema_file: | ||
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: | ||
validator = jsonschema.validate(data, schema) | ||
yield nose.assert_is_none, validator | ||
except jsonschema.exceptions.ValidationError as error: | ||
assert False, error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
import nose.tools as nose | ||
import yv_suggest.filter_prefs as yvs | ||
from xml.etree import ElementTree as ET | ||
from context_managers import redirect_stdout | ||
|
||
|
||
def test_show_languages(): | ||
"""should show all languages if no value is given""" | ||
results = yvs.get_result_list('language', prefs={}) | ||
nose.assert_not_equal(len(results), 0) | ||
|
||
|
||
def test_filter_languages(): | ||
"""should filter available languages if value is given""" | ||
results = yvs.get_result_list('language en', prefs={}) | ||
nose.assert_equal(len(results), 1) | ||
nose.assert_equal(results[0]['title'], 'English') | ||
nose.assert_equal(results[0]['arg'], 'language:en') | ||
|
||
|
||
def test_show_versions(): | ||
"""should show all versions if no value is given""" | ||
results = yvs.get_result_list('version', prefs={}) | ||
nose.assert_not_equal(len(results), 0) | ||
|
||
|
||
def test_filter_versions(): | ||
"""should filter available versions if value is given""" | ||
results = yvs.get_result_list('version ni', prefs={}) | ||
nose.assert_equal(len(results), 3) | ||
nose.assert_equal(results[0]['title'], 'NIRV') | ||
nose.assert_equal(results[0]['arg'], 'version:110') | ||
|
||
|
||
def test_nonexistent(): | ||
"""should not match nonexistent preferences""" | ||
results = yvs.get_result_list('xyz', prefs={}) | ||
nose.assert_equal(len(results), 0) | ||
|
||
|
||
def test_invalid(): | ||
"""should not match nonexistent preferences""" | ||
results = yvs.get_result_list('!@#', prefs={}) | ||
nose.assert_equal(len(results), 0) | ||
|
||
|
||
def test_main_output(): | ||
"""should output pref result list XML""" | ||
query_str = 'language' | ||
with redirect_stdout() as out: | ||
yvs.main(query_str, prefs={}) | ||
output = out.getvalue().strip() | ||
results = yvs.get_result_list(query_str, prefs={}) | ||
xml = yvs.shared.get_result_list_xml(results).strip() | ||
nose.assert_equal(output, xml) | ||
|
||
|
||
def test_null_result(): | ||
"""should output "No Results" XML item for empty pref result lists""" | ||
query_str = 'xyz' | ||
with redirect_stdout() as out: | ||
yvs.main(query_str, prefs={}) | ||
xml = out.getvalue().strip() | ||
root = ET.fromstring(xml) | ||
item = root.find('item') | ||
nose.assert_is_not_none(item, '<item> element is missing') | ||
nose.assert_equal(item.get('valid'), 'no') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
tests/test_search_chapter.py → tests/test_filter_refs_chapter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
import nose.tools as nose | ||
import yv_suggest.search as yvs | ||
import yv_suggest.filter_refs as yvs | ||
|
||
|
||
def test_basic(): | ||
"""should match chapters""" | ||
results = yvs.get_result_list('matthew 5') | ||
results = yvs.get_result_list('matthew 5', prefs={}) | ||
nose.assert_equal(len(results), 1) | ||
nose.assert_equal(results[0]['title'], 'Matthew 5 (NIV)') | ||
|
||
|
||
def test_ambiguous(): | ||
"""should match chapters by ambiguous book name""" | ||
results = yvs.get_result_list('a 3') | ||
results = yvs.get_result_list('a 3', prefs={}) | ||
nose.assert_equal(len(results), 2) | ||
nose.assert_equal(results[0]['title'], 'Amos 3 (NIV)') | ||
nose.assert_equal(results[1]['title'], 'Acts 3 (NIV)') | ||
|
||
|
||
def test_id(): | ||
"""should use correct ID for chapters""" | ||
results = yvs.get_result_list('luke 4') | ||
nose.assert_equal(results[0]['uid'], 'niv/luk.4') | ||
results = yvs.get_result_list('luke 4', prefs={}) | ||
nose.assert_equal(results[0]['uid'], 'yvs-111/luk.4') | ||
|
||
|
||
def test_nonexistent(): | ||
"""should not match nonexistent chapters""" | ||
results = yvs.get_result_list('psalm 160') | ||
results = yvs.get_result_list('psalm 160', prefs={}) | ||
nose.assert_equal(len(results), 0) | ||
|
||
|
||
def test_zero_chapter(): | ||
"""should not match chapter zero""" | ||
results = yvs.get_result_list('psalm 0') | ||
results = yvs.get_result_list('psalm 0', prefs={}) | ||
nose.assert_equal(len(results), 0) |
Oops, something went wrong.