forked from dingdang-robot/dingdang-robot
-
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.
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
WORDS = [u"ECHO", u"CHUANHUA"] | ||
|
||
PRIORITY = 0 | ||
|
||
def handle(text, mic, profile, wxbot=None): | ||
""" | ||
|
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,37 @@ | ||
#!/usr/bin/env python2 | ||
# -*- coding: utf-8-*- | ||
from nose.tools import * | ||
import mock | ||
from client import brain, test_mic | ||
|
||
|
||
DEFAULT_PROFILE = { | ||
'prefers_email': False, | ||
'timezone': 'HKT' | ||
} | ||
|
||
|
||
class TestBrain(): | ||
|
||
@staticmethod | ||
def _emptyBrain(): | ||
mic = test_mic.Mic([]) | ||
profile = DEFAULT_PROFILE | ||
return brain.Brain(mic, profile) | ||
|
||
def testSortByPriority(self): | ||
"""Does Brain sort plugins by priority?""" | ||
my_brain = TestBrain._emptyBrain() | ||
priorities = filter(lambda m: hasattr(m, 'PRIORITY'), my_brain.plugins) | ||
target = sorted(priorities, key=lambda m: m.PRIORITY, reverse=True) | ||
assert target == priorities | ||
|
||
def testPriority(self): | ||
"""Does Brain correctly send query to higher-priority plugin?""" | ||
my_brain = TestBrain._emptyBrain() | ||
echo_plugin = 'Echo' | ||
hn = filter(lambda m: m.__name__ == echo_plugin, my_brain.plugins)[0] | ||
|
||
with mock.patch.object(hn, 'handle') as mocked_handle: | ||
my_brain.query(["echo 你好吗"]) | ||
assert mocked_handle.called |
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,11 @@ | ||
#!/usr/bin/env python2 | ||
# -*- coding: utf-8-*- | ||
from nose.tools import * | ||
from client import diagnose | ||
|
||
|
||
def testPythonImportCheck(): | ||
# This a python stdlib module that definitely exists | ||
assert diagnose.check_python_import("os") | ||
# I sincerly hope nobody will ever create a package with that name | ||
assert not diagnose.check_python_import("nonexistant_package") |