Skip to content

Commit

Permalink
Remove spelling function
Browse files Browse the repository at this point in the history
Fixes #86
  • Loading branch information
moggers87 committed Sep 27, 2018
1 parent 72779ed commit 91fe00d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 57 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -4,6 +4,11 @@ Unreleased
==========

- Don't install python-daemon 2.2.0, it breaks things (#89)
- Remove untested spelling function (#86)

- The spelling function did very little other than assume it could load
PyEnchant and then ``return True`` if it couldn't. If you really miss this
function, submit a PR with something that actually works and has tests!

3.0.2
=====
Expand Down
3 changes: 1 addition & 2 deletions README.rst
Expand Up @@ -36,8 +36,7 @@ any other Mail server.
- Salmon can also run in a completely separate virtualenv for easy deployment.
- A flexible and easy to use routing system lets you write stateful or state\
*less* handlers of your email.
- Helpful tools for unit testing your email applications with nose, including
spell checking with PyEnchant.
- Helpful tools for unit testing your email applications with nose.
- Ability to use Jinja2 or Mako templates to craft emails including the
headers.
- Easily configurable to use alternative sending and receiving systems,
Expand Down
49 changes: 7 additions & 42 deletions salmon/testing.py
@@ -1,23 +1,20 @@
"""
A bag of generally useful things when writing unit tests for your Salmon server.
The most important things are the spelling function and using the
TestConversation vs. RouterConversation to talk to your server.
A bag of generally useful things when writing unit tests for your Salmon
server. The most important thing using the TestConversation vs.
RouterConversation to talk to your server.
The TestConversation will use the salmon.server.Relay you have configured to
talk to your actual running Salmon server. Since by default Salmon reloads each
file you change it will work to run your tests.
talk to your actual running Salmon server. Since by default Salmon reloads
each file you change it will work to run your tests.
However, this isn't that fast, doesn't give you coverage analysis, and doesn't
let you test the results. For that you use RouterConversation to do the exact
same API (they should be interchangeable) but rather than talk to a running
server through the relay, it just runs all the messages through the router
directly.
This is faster and will give you code coverage as well as make sure that all the
modules (not just your handlers) will get reloaded.
The spelling function will use PyEnchant to spell check a string. If it finds
any errors it prints them out, and returns False.
This is faster and will give you code coverage as well as make sure that all
the modules (not just your handlers) will get reloaded.
"""
from __future__ import print_function, unicode_literals

Expand All @@ -29,38 +26,6 @@
TEST_QUEUE = "run/queue"


def spelling(file_name, contents, language="en_US"):
"""
You give it a file_name and the contents of that file and it tells you
if it's spelled correctly. The reason you give it contents is that you
will typically run a template through the render process, so spelling
can't just load a file and check it.
It assumes you have PyEnchant installed correctly and configured
in your test settings module. Use "salmon spell" to make sure it
works right.
"""
try:
from enchant.checker import SpellChecker
from enchant.tokenize import EmailFilter, URLFilter
except ImportError:
print("Failed to load PyEnchant. Make sure it's installed and salmon spell works.")
return True

failures = 0
chkr = SpellChecker(language, filters=[EmailFilter, URLFilter])
chkr.set_text(contents)
for err in chkr:
print("%s: %s \t %r" % (file_name, err.word, contents[err.wordpos - 20:err.wordpos + 20]))
failures += 1

if failures:
print("You have %d spelling errors in %s. Run salmon spell.." % (failures, file_name))
return False
else:
return True


def relay(hostname="127.0.0.1", port=8824):
"""Wires up a default relay on port 8824 (the default salmon log port)."""
return server.Relay(hostname, port, debug=0)
Expand Down
13 changes: 0 additions & 13 deletions tests/salmon_tests/testing_tests.py
@@ -1,5 +1,3 @@
import os

from mock import Mock, patch
from nose.tools import assert_equal, with_setup

Expand All @@ -10,7 +8,6 @@
delivered,
queue,
relay,
spelling,
)

from .setup_env import setup_salmon_dirs, teardown_salmon_dirs
Expand Down Expand Up @@ -55,13 +52,3 @@ def test_RouterConversation():
client.begin()
client.say('testlist@localhost', 'This is a test')
delivered('testlist@localhost'), "Test message not delivered."


def test_spelling():
# specific to a mac setup, because macs are lame
if 'PYENCHANT_LIBRARY_PATH' not in os.environ:
os.environ['PYENCHANT_LIBRARY_PATH'] = '/opt/local/lib/libenchant.dylib'

template = "tests/salmon_tests/templates/template.txt"
contents = open(template).read()
assert spelling(template, contents)

0 comments on commit 91fe00d

Please sign in to comment.