Clean up the core method tests
- Use a single complete config file as config mock and mock.patch.dict to mock it.pull/1528/head
parent
3e2f008c12
commit
c14daa5844
|
@ -29,6 +29,10 @@ from mycroft.skills.skill_data import load_regex_from_file, load_regex, \
|
|||
from mycroft.skills.core import MycroftSkill, load_skill, \
|
||||
create_skill_descriptor, open_intent_envelope
|
||||
|
||||
from mycroft.configuration.config import LocalConf, DEFAULT_CONFIG
|
||||
|
||||
BASE_CONF = LocalConf(DEFAULT_CONFIG)
|
||||
|
||||
|
||||
class MockEmitter(object):
|
||||
def __init__(self):
|
||||
|
@ -404,58 +408,17 @@ class MycroftSkillTest(unittest.TestCase):
|
|||
expected = [{'context': 'Donatello'}]
|
||||
check_remove_context(expected)
|
||||
|
||||
@mock.patch.object(Configuration, 'get')
|
||||
def test_skill_location(self, mock_config_get):
|
||||
test_config = {
|
||||
"location": {
|
||||
"city": {
|
||||
"code": "Lawrence",
|
||||
"name": "Lawrence",
|
||||
"state": {
|
||||
"code": "KS",
|
||||
"name": "Kansas",
|
||||
"country": {
|
||||
"code": "US",
|
||||
"name": "United States"
|
||||
}
|
||||
}
|
||||
},
|
||||
"coordinate": {
|
||||
"latitude": 38.971669,
|
||||
"longitude": -95.23525
|
||||
},
|
||||
"timezone": {
|
||||
"code": "America/Chicago",
|
||||
"name": "Central Standard Time",
|
||||
"dstOffset": 3600000,
|
||||
"offset": -21600000
|
||||
}
|
||||
}
|
||||
}
|
||||
mock_config_get.return_value = test_config
|
||||
@mock.patch.dict(Configuration._Configuration__config, BASE_CONF)
|
||||
def test_skill_location(self):
|
||||
s = TestSkill1()
|
||||
self.assertEqual(s.location, test_config.get('location'))
|
||||
self.assertEqula(s.location_pretty,
|
||||
test_config['location']['city']['name'])
|
||||
self.assertEqual(s.location, BASE_CONF.get('location'))
|
||||
self.assertEqual(s.location_pretty,
|
||||
BASE_CONF['location']['city']['name'])
|
||||
self.assertEqual(s.location_timezone,
|
||||
test_config['location']['timezone']['code'])
|
||||
BASE_CONF['location']['timezone']['code'])
|
||||
|
||||
@mock.patch.object(Configuration, 'get')
|
||||
def test_skill_location(self, mock_config_get):
|
||||
test_config = {}
|
||||
mock_config_get.return_value = test_config
|
||||
s = TestSkill1()
|
||||
self.assertEqual(s.location, None)
|
||||
self.assertEqual(s.location_pretty, None)
|
||||
self.assertEqual(s.location_timezone, None)
|
||||
|
||||
@mock.patch.object(Configuration, 'get')
|
||||
def test_add_event(self, mock_config_get):
|
||||
test_config = {
|
||||
'skills': {
|
||||
}
|
||||
}
|
||||
mock_config_get.return_value = test_config
|
||||
@mock.patch.dict(Configuration._Configuration__config, BASE_CONF)
|
||||
def test_add_event(self):
|
||||
emitter = mock.MagicMock()
|
||||
s = TestSkill1()
|
||||
s.bind(emitter)
|
||||
|
@ -465,13 +428,8 @@ class MycroftSkillTest(unittest.TestCase):
|
|||
# Check that the handler was stored in the skill
|
||||
self.assertTrue('handler1' in zip(*s.events)[0])
|
||||
|
||||
@mock.patch.object(Configuration, 'get')
|
||||
def test_remove_event(self, mock_config_get):
|
||||
test_config = {
|
||||
'skills': {
|
||||
}
|
||||
}
|
||||
mock_config_get.return_value = test_config
|
||||
@mock.patch.dict(Configuration._Configuration__config, BASE_CONF)
|
||||
def test_remove_event(self):
|
||||
emitter = mock.MagicMock()
|
||||
s = TestSkill1()
|
||||
s.bind(emitter)
|
||||
|
@ -484,13 +442,8 @@ class MycroftSkillTest(unittest.TestCase):
|
|||
# Check that the handler was registered with the emitter
|
||||
self.assertEqual(emitter.remove.call_args[0][0], 'handler1')
|
||||
|
||||
@mock.patch.object(Configuration, 'get')
|
||||
def test_add_scheduled_event(self, mock_config_get):
|
||||
test_config = {
|
||||
'skills': {
|
||||
}
|
||||
}
|
||||
mock_config_get.return_value = test_config
|
||||
@mock.patch.dict(Configuration._Configuration__config, BASE_CONF)
|
||||
def test_add_scheduled_event(self):
|
||||
emitter = mock.MagicMock()
|
||||
s = TestSkill1()
|
||||
s.bind(emitter)
|
||||
|
@ -499,13 +452,8 @@ class MycroftSkillTest(unittest.TestCase):
|
|||
self.assertEqual(emitter.once.call_args[0][0], '0:sched_handler1')
|
||||
self.assertTrue('0:sched_handler1' in zip(*s.events)[0])
|
||||
|
||||
@mock.patch.object(Configuration, 'get')
|
||||
def test_remove_scheduled_event(self, mock_config_get):
|
||||
test_config = {
|
||||
'skills': {
|
||||
}
|
||||
}
|
||||
mock_config_get.return_value = test_config
|
||||
@mock.patch.dict(Configuration._Configuration__config, BASE_CONF)
|
||||
def test_remove_scheduled_event(self):
|
||||
emitter = mock.MagicMock()
|
||||
s = TestSkill1()
|
||||
s.bind(emitter)
|
||||
|
@ -517,13 +465,8 @@ class MycroftSkillTest(unittest.TestCase):
|
|||
self.assertEqual(emitter.remove.call_args[0][0], '0:sched_handler1')
|
||||
self.assertTrue('0:sched_handler1' not in zip(*s.events)[0])
|
||||
|
||||
@mock.patch.object(Configuration, 'get')
|
||||
def test_run_scheduled_event(self, mock_config_get):
|
||||
test_config = {
|
||||
'skills': {
|
||||
}
|
||||
}
|
||||
mock_config_get.return_value = test_config
|
||||
@mock.patch.dict(Configuration._Configuration__config, BASE_CONF)
|
||||
def test_run_scheduled_event(self):
|
||||
emitter = mock.MagicMock()
|
||||
s = TestSkill1()
|
||||
with mock.patch.object(s, '_settings',
|
||||
|
|
Loading…
Reference in New Issue