forked from vishakha-lall/MapBot
-
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.
unit tests for utilities.py (vishakha-lall#119)
- Loading branch information
1 parent
226ce31
commit 75f797f
Showing
2 changed files
with
62 additions
and
3 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,57 @@ | ||
import utilities | ||
|
||
|
||
class TestClass: | ||
test_input = "The quick brown fox jumps over the lazy dog." | ||
clf = utilities.classify_model() | ||
|
||
def test_setup_nltk(self): | ||
result = utilities.setup_nltk() | ||
assert result | ||
|
||
def test_parse_sentence(self): | ||
triples, root = utilities.parse_sentence(self.test_input) | ||
triples = list(triples) | ||
assert (("jumps", "VBZ"), "nsubj", ("fox", "NN")) in triples | ||
assert (("jumps", "VBZ"), "nmod", ("dog", "NN")) in triples | ||
assert root == "jumps" | ||
|
||
def test_classify_model(self): | ||
from features import features_dict | ||
import hashlib | ||
import numpy as np | ||
|
||
keys = [ | ||
"id", | ||
"wordCount", | ||
"stemmedCount", | ||
"stemmedEndNN", | ||
"CD", | ||
"NN", | ||
"NNP", | ||
"NNPS", | ||
"NNS", | ||
"PRP", | ||
"VBG", | ||
"VBZ", | ||
"startTuple0", | ||
"endTuple0", | ||
"endTuple1", | ||
"endTuple2", | ||
"verbBeforeNoun", | ||
"qMark", | ||
"qVerbCombo", | ||
"qTripleScore", | ||
"sTripleScore", | ||
"class", | ||
] | ||
id = hashlib.md5(str(self.test_input).encode("utf-8")).hexdigest()[:16] | ||
f = features_dict(id, self.test_input) | ||
features = [f[k] for k in keys][1:-1] | ||
features = np.array(features).reshape(1, -1) | ||
|
||
assert self.clf.predict(features)[0] == "S" | ||
|
||
def test_classify_sentence(self): | ||
result = utilities.classify_sentence(self.clf, self.test_input) | ||
assert result == "S" |
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