This repository has been archived by the owner on Jul 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
60 lines (42 loc) · 1.84 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Test the Sprockets Command Line Interface
"""
try:
import unittest2 as unittest
except ImportError:
import unittest
import mock
from sprockets import cli
class Package(object):
def __init__(self, name, module_name):
self.name = name
self.module_name = module_name
class InitializationTests(unittest.TestCase):
@mock.patch('argparse.ArgumentParser.parse_args')
@mock.patch('pkg_resources.iter_entry_points')
def setUp(self, iter_entry_points, parse_args):
self.iter_entry_points = iter_entry_points
self.parse_args = parse_args
self.app_points = [Package('tapp', 'sstubs.app')]
self.ctrl_points = [Package('tcontroller', 'sstubs.controller')]
self.plugin_points = [Package('tplugin', 'sstubs.plugin')]
def entry_point_side_effect(*args, **kwargs):
if kwargs.get('group') == 'sprockets.controller':
return iter(self.ctrl_points)
elif kwargs.get('group') == 'sprockets.plugin':
return iter(self.plugin_points)
elif kwargs.get('group') == 'sprockets.test_http.app':
return iter(self.app_points)
self.iter_entry_points.side_effect = entry_point_side_effect
self.obj = cli.CLI()
def test_pkg_resources_iterated(self):
calls = [mock.call(group='sprockets.controller'),
mock.call(group='sprockets.plugin')]
self.iter_entry_points.assert_has_calls(calls)
def test_controller_imported(self):
for attr in ['add_cli_arguments', 'main']:
self.assertTrue(hasattr(self.obj._controllers.get('tcontroller'),
attr))
def test_plugin_is_imported(self):
for attr in ['initialize', 'on_start', 'on_shutdown']:
self.assertTrue(hasattr(self.obj._plugins.get('tplugin'), attr))