Skip to content

Commit

Permalink
Merge branch 'feature/v1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Feb 16, 2015
2 parents b24f5d2 + f22b5e0 commit 7af9b9f
Show file tree
Hide file tree
Showing 20 changed files with 836 additions and 771 deletions.
20 changes: 20 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Configuration for coverage.py (https://pypi.python.org/pypi/coverage)

[run]
# Enable branch coverage
branch = True

[report]

# Regexes for lines to exclude from consideration
exclude_lines =
# Allow source to designate lines/branches to be skipped
pragma: no cover

# Ignore non-runnable code
if __name__ == .__main__.:

# Only check coverage for source files
include =
yv_suggest/open.py
yv_suggest/search.py
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.json]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Files generated by OS
.DS_Store
*.pyc
__pycache__

# Python bytecode
__pycache__/
*.py[cod]

# Unit test / coverage reports
cover/
.coverage
coverage.xml
nosetests.xml
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,42 @@ suggestions matching your query.

* `luke` => Luke
* `eph 3` => Ephesians 3
* `1 t 3 e` => 1 Thessalonians 3 (ESV), 1 Timothy 3 (ESV)
* `1t3e` => 1 Thessalonians 3 (ESV), 1 Timothy 3 (ESV)
* `mat 6:34 nlt` => Matthew 6:34 (NLT)
* `1 co 13.4-7` => 1 Corinthians 13.4-7

## Testing

If you are contributing to the project and would like to run the included unit
tests, run the following command in the project directory:
### Requirements for running tests

Running these unit tests requires Python 2.7, as well as the following packages
to be installed:

* nose
* coverage
* pep8

If you do not have these packages installed already, you can install them via
`pip`:

```
python -m unittest tests
sudo pip install nose coverage pep8
```

### Running an individual test case
### Running tests

If you wish to run a single test case, reference the module name like so:
To run the included unit tests, run the `nosetests` command within the project
directory.

```
python -m unittest tests.test_search_book
nosetests
```

### Requirements for running tests
### Viewing test coverage

Note that running these unit tests requires Python 2.7. Running these tests also
requires the `pep8` module, which you can install using `pip`:
To view the test coverage report, run `nosetests` with the `--with-coverage` and
`--cover-erase` flags.

```
pip install pep8
nosetests --with-coverage --cover-erase
```
Binary file modified YouVersion Suggest.alfredworkflow
Binary file not shown.
11 changes: 0 additions & 11 deletions tests/__init__.py

This file was deleted.

36 changes: 16 additions & 20 deletions tests/test_open.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

import unittest
import nose.tools as nose
import yv_suggest.open as yvs
import inspect

Expand All @@ -13,26 +13,22 @@ def open(self, url):
self.url = url


class OpenTestCase(unittest.TestCase):
"""test the handling of Bible reference URLs"""
def test_url():
"""should build correct URL to Bible reference"""
url = yvs.get_ref_url('esv/jhn.3.16')
nose.assert_equal(url, 'https://www.bible.com/bible/esv/jhn.3.16')

def test_url(self):
"""should build correct URL to Bible reference"""
url = yvs.get_ref_url('esv/jhn.3.16')
self.assertEqual(url, 'https://www.bible.com/bible/esv/jhn.3.16')

def test_query_param(self):
"""should use received query parameter as default ref ID"""
spec = inspect.getargspec(yvs.main)
default_query_str = spec.defaults[0]
self.assertEqual(default_query_str, '{query}')
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(self):
"""should attempt to open URL using webbrowser module"""
mock = WebbrowserMock()
yvs.webbrowser = mock
yvs.main('nlt/jhn.3.17')
self.assertEqual(mock.url, 'https://www.bible.com/bible/nlt/jhn.3.17')

if __name__ == '__main__':
unittest.main()
def test_url_open():
"""should attempt to open URL using webbrowser module"""
mock = WebbrowserMock()
yvs.webbrowser = mock
yvs.main('nlt/jhn.3.17')
nose.assert_equal(mock.url, 'https://www.bible.com/bible/nlt/jhn.3.17')
28 changes: 8 additions & 20 deletions tests/test_pep8.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
#!/usr/bin/env python

import unittest
import nose.tools as nose
import pep8
import glob
import os


class TestPep8(unittest.TestCase):
"""test all python source files for pep8 compliance"""

def test_source_pep8_compliant(self):
"""source files should comply with pep8"""
style_guide = pep8.StyleGuide(quiet=True)
result = style_guide.check_files(glob.iglob('yv_suggest/*.py'))
self.assertEqual(result.total_errors, 0,
'Source files are not pep8-compliant')

def test_test_pep8_compliant(self):
"""unit tests should comply with pep8"""
def test_source_compliance():
"""source files should comply with pep8"""
files = glob.iglob('*/*.py')
for file in files:
style_guide = pep8.StyleGuide(quiet=True)
result = style_guide.check_files(glob.iglob('tests/*.py'))
self.assertEqual(result.total_errors, 0,
'Unit tests not pep8-compliant')

if __name__ == '__main__':
unittest.main()
total_errors = style_guide.input_file(file)
msg = '{} is not pep8-compliant'.format(file)
yield nose.assert_equal, total_errors, 0, msg
149 changes: 76 additions & 73 deletions tests/test_search_book.py
Original file line number Diff line number Diff line change
@@ -1,78 +1,81 @@
#!/usr/bin/env python

import unittest
import nose.tools as nose
import yv_suggest.search as yvs


class SearchBookTestCase(unittest.TestCase):
"""test the searching of Bible books"""

def test_partial(self):
"""should match books by partial name"""
results = yvs.get_result_list('luk')
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['title'], 'Luke')

def test_case(self):
"""should match books irrespective of case"""
query_str = 'Matthew'
results = yvs.get_result_list(query_str)
results_lower = yvs.get_result_list(query_str.lower())
results_upper = yvs.get_result_list(query_str.upper())
self.assertEqual(len(results), 1)
self.assertListEqual(results_lower, results)
self.assertListEqual(results_upper, results)

def test_whitespace(self):
"""should match books irrespective of surrounding whitespace"""
results = yvs.get_result_list(' romans ')
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['title'], 'Romans')

def test_partial_ambiguous(self):
"""should match books by ambiguous partial name"""
results = yvs.get_result_list('r')
self.assertEqual(len(results), 3)
self.assertEqual(results[0]['title'], 'Ruth')
self.assertEqual(results[1]['title'], 'Romans')
self.assertEqual(results[2]['title'], 'Revelation')

def test_multiple_words(self):
"""should match books with names comprised of multiple words"""
results = yvs.get_result_list('song of songs')
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['title'], 'Song of Songs')

def test_numbered_partial(self):
"""should match numbered books by partial numbered name"""
results = yvs.get_result_list('1 cor')
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['title'], '1 Corinthians')

def test_numbered_whitespace(self):
"""should match numbered books irrespective of extra whitespace"""
results = yvs.get_result_list('1 cor')
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['title'], '1 Corinthians')

def test_nonnumbered_partial(self):
"""should match numbered books by partial non-numbered name"""
results = yvs.get_result_list('john')
self.assertEqual(len(results), 4)
self.assertEqual(results[0]['title'], 'John')
self.assertEqual(results[1]['title'], '1 John')
self.assertEqual(results[2]['title'], '2 John')
self.assertEqual(results[3]['title'], '3 John')

def test_id(self):
"""should use correct ID for books"""
results = yvs.get_result_list('philippians')
self.assertEqual(results[0]['uid'], 'niv/php.1')

def test_nonexistent(self):
"""should not match nonexistent books"""
results = yvs.get_result_list('jesus')
self.assertEqual(len(results), 0)

if __name__ == '__main__':
unittest.main()
def test_partial():
"""should match books by partial name"""
results = yvs.get_result_list('luk')
nose.assert_equal(len(results), 1)
nose.assert_equal(results[0]['title'], 'Luke')


def test_case():
"""should match books irrespective of case"""
query_str = 'Matthew'
results = yvs.get_result_list(query_str)
results_lower = yvs.get_result_list(query_str.lower())
results_upper = yvs.get_result_list(query_str.upper())
nose.assert_equal(len(results), 1)
nose.assert_list_equal(results_lower, results)
nose.assert_list_equal(results_upper, results)


def test_whitespace():
"""should match books irrespective of surrounding whitespace"""
results = yvs.get_result_list(' romans ')
nose.assert_equal(len(results), 1)
nose.assert_equal(results[0]['title'], 'Romans')


def test_partial_ambiguous():
"""should match books by ambiguous partial name"""
results = yvs.get_result_list('r')
nose.assert_equal(len(results), 3)
nose.assert_equal(results[0]['title'], 'Ruth')
nose.assert_equal(results[1]['title'], 'Romans')
nose.assert_equal(results[2]['title'], 'Revelation')


def test_multiple_words():
"""should match books with names comprised of multiple words"""
results = yvs.get_result_list('song of songs')
nose.assert_equal(len(results), 1)
nose.assert_equal(results[0]['title'], 'Song of Songs')


def test_numbered_partial():
"""should match numbered books by partial numbered name"""
results = yvs.get_result_list('1 cor')
nose.assert_equal(len(results), 1)
nose.assert_equal(results[0]['title'], '1 Corinthians')


def test_numbered_whitespace():
"""should match numbered books irrespective of extra whitespace"""
results = yvs.get_result_list('1 cor')
nose.assert_equal(len(results), 1)
nose.assert_equal(results[0]['title'], '1 Corinthians')


def test_nonnumbered_partial():
"""should match numbered books by partial non-numbered name"""
results = yvs.get_result_list('john')
nose.assert_equal(len(results), 4)
nose.assert_equal(results[0]['title'], 'John')
nose.assert_equal(results[1]['title'], '1 John')
nose.assert_equal(results[2]['title'], '2 John')
nose.assert_equal(results[3]['title'], '3 John')


def test_id():
"""should use correct ID for books"""
results = yvs.get_result_list('philippians')
nose.assert_equal(results[0]['uid'], 'niv/php.1')


def test_nonexistent():
"""should not match nonexistent books"""
results = yvs.get_result_list('jesus')
nose.assert_equal(len(results), 0)
Loading

0 comments on commit 7af9b9f

Please sign in to comment.