-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fleshed out the husk of the unit tests * Modularized blog parser a bit and removed error.txt * added simple happy path tests for analyzer * Added autopep8 pre-commit hook
- Loading branch information
1 parent
7f062c6
commit 67d598c
Showing
9 changed files
with
117 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v1.3.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: autopep8-wrapper | ||
- id: requirements-txt-fixer |
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,5 +1,6 @@ | ||
beautifulsoup4 >= 4.6.3 | ||
nltk >= 3.3 | ||
pre-commit==1.10.3 | ||
redis >= 2.10.6 | ||
requests >= 2.19.1 | ||
validators | ||
validators |
Empty file.
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
Empty file.
Empty file.
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,15 @@ | ||
class MockRedis: | ||
def __init__(self, cache=None): | ||
self.cache = cache | ||
|
||
def incr(self, key): | ||
self.cache[key] = self.cache.setdefault(key, 0) + 1 | ||
|
||
def dbsize(self): | ||
return len(self.cache) | ||
|
||
def set(self, k, v): | ||
self.cache[k] = v | ||
|
||
def get(self, k): | ||
return self.cache.get(k) |
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,25 @@ | ||
from unittest import TestCase, mock | ||
|
||
from src.blog_parser import get_results, analyze_word | ||
from test.mocks.redis_client import MockRedis | ||
|
||
|
||
class TestBlogParser(TestCase): | ||
|
||
@mock.patch('src.blog_parser.word_client', new=MockRedis(cache={'foo': 2, 'bar': 1})) | ||
@mock.patch('src.blog_parser.blogs_scraped_counter', new=1) | ||
def test_result_generator(self): | ||
""" | ||
Test ensures that stats can be calculated, given a functioning redis client | ||
""" | ||
get_results() | ||
|
||
@mock.patch('src.blog_parser.word_client', new=MockRedis(cache={'foo': 2, 'bar': 1})) | ||
def test_word_analyze(self): | ||
""" | ||
Check that the analyzer runs and doesn't bark at empty strings | ||
""" | ||
self.assertEqual(analyze_word('foo', 'https://amifired.today'), ('foo', 'NN')) | ||
self.assertIsNone(analyze_word('', 'https://foo.bar')) | ||
|
||
|
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,26 @@ | ||
from unittest import TestCase | ||
|
||
from src.utils import sanitize_blogpost | ||
|
||
|
||
class TestUtilities(TestCase): | ||
def test_sanitizer(self): | ||
""" | ||
Ensures that the blog post sanitizer works as intended. | ||
""" | ||
fake_post = 'Words! Mere words! \n\nHow terrible they were! ' \ | ||
'How clear\n, and vivid, ~and cruel! \"One could not ' \ | ||
'escape from them.\n And yet\n what a \'subtle magic there ' \ | ||
'was in them! They seemed .to be able :to give a plastic ' \ | ||
'form to\n\n formless things, and. to ;have a music \nof their ' \ | ||
'own as sweet as that\n of viol or of lute. Mere words! Was ' \ | ||
'there anything so real as words? Also here\'s a hyphenated-word.' | ||
expected_result = 'words mere words how terrible they were ' \ | ||
'how clear and vivid and cruel one could not ' \ | ||
'escape from them and yet what a subtle magic ' \ | ||
'there was in them they seemed to be able to give ' \ | ||
'a plastic form to formless things and to have a music ' \ | ||
'of their own as sweet as that of viol or of lute mere ' \ | ||
'words was there anything so real as words also heres a hyphenated-word' | ||
|
||
self.assertEqual(sanitize_blogpost(fake_post), expected_result) |