backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / cmd / test_manager.py
1 # Copyright (C) 2013,2014 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2013,2014 YAMAMOTO Takashi <yamamoto at valinux co jp>
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import sys
18 import unittest
19 import mock
20 from nose.tools import eq_, raises
21
22 try:
23     # Python 3
24     from imp import reload
25 except ImportError:
26     # Python 2
27     pass
28
29 from ryu.cmd.manager import main
30
31
32 class Test_Manager(unittest.TestCase):
33     """Test ryu-manager command
34     """
35
36     def __init__(self, methodName):
37         super(Test_Manager, self).__init__(methodName)
38
39     def setUp(self):
40         pass
41
42     def tearDown(self):
43         pass
44
45     @raises(SystemExit)
46     @mock.patch('sys.argv', new=['ryu-manager', '--version'])
47     def test_version(self):
48         main()
49
50     @raises(SystemExit)
51     @mock.patch('sys.argv', new=['ryu-manager', '--help'])
52     def test_help(self):
53         main()
54
55     @staticmethod
56     def _reset_globals():
57         # hack to reset globals like SERVICE_BRICKS.
58         # assumption: this is the only test which actually starts RyuApp.
59         import ryu.base.app_manager
60         import ryu.ofproto.ofproto_protocol
61
62         reload(ryu.base.app_manager)
63         reload(ryu.ofproto.ofproto_protocol)
64
65     @mock.patch('sys.argv', new=['ryu-manager', '--verbose',
66                                  'ryu.tests.unit.cmd.dummy_app'])
67     def test_no_services(self):
68         self._reset_globals()
69         main()
70         self._reset_globals()
71
72     @mock.patch('sys.argv', new=['ryu-manager', '--verbose',
73                                  'ryu.tests.unit.cmd.dummy_openflow_app'])
74     def test_openflow_app(self):
75         self._reset_globals()
76         main()
77         self._reset_globals()