NOTE: some tests are skipped. all classes that inherit bpdu have some public members which do not relate to arguments of __init__().
a json used for creation of the object does not need 'bpdu_type', 'protocol_id' and 'version_id', but a json which the object generated include them. Signed-off-by: itoyuichi <[email protected]> --- ryu/tests/unit/packet/test_bpdu.py | 138 ++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 ryu/tests/unit/packet/test_bpdu.py diff --git a/ryu/tests/unit/packet/test_bpdu.py b/ryu/tests/unit/packet/test_bpdu.py new file mode 100644 index 0000000..ce554ae --- /dev/null +++ b/ryu/tests/unit/packet/test_bpdu.py @@ -0,0 +1,138 @@ +# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +import unittest +import json +import logging + +from nose.plugins.skip import SkipTest +from nose.tools import eq_ +from ryu.lib.packet import bpdu + + +LOG = logging.getLogger(__name__) + + +class Test_ConfigurationBPDUs(unittest.TestCase): + msg = bpdu.ConfigurationBPDUs() + jsonstr = ''' + { + "ConfigurationBPDUs": { + "flags": 0, + "root_priority": 32768, + "root_system_id_extension": 0, + "root_mac_address": "00:00:00:00:00:00", + "root_path_cost": 0, + "bridge_priority": 32768, + "bridge_system_id_extension": 0, + "bridge_mac_address": "00:00:00:00:00:00", + "port_priority": 128, + "port_number": 0, + "message_age": 0, + "max_age": 20, + "hello_time": 2, + "forward_delay": 15 + } + } + ''' + jsondict = json.loads(jsonstr) + + def test_to_jsondict(self): + # bpdu has some public members which do not relate to arguments + # of __init__(). + LOG.info("SKIP [Test_ConfigurationBPDUs.test_to_jsondict]") + LOG.debug("self.jsondict:") + LOG.debug(self.jsondict) + LOG.debug("self.msg.to_jsondict():") + LOG.debug(self.msg.to_jsondict()) + raise SkipTest("TODO: make reversible ConfigurationBPDUs.") + eq_(self.jsondict, self.msg.to_jsondict()) + + def test_from_jsondict(self): + msg2 = bpdu.ConfigurationBPDUs.from_jsondict( + self.jsondict['ConfigurationBPDUs']) + eq_(str(msg2), str(self.msg)) + + +class Test_TopologyChangeNotificationBPDUs(unittest.TestCase): + msg = bpdu.TopologyChangeNotificationBPDUs() + jsonstr = ''' + { + "TopologyChangeNotificationBPDUs": { + } + } + ''' + jsondict = json.loads(jsonstr) + + def test_to_jsondict(self): + # bpdu has some public members which do not relate to arguments + # of __init__(). + LOG.info( + "SKIP [Test_TopologyChangeNotificationBPDUs.test_to_jsondict]") + LOG.debug("self.jsondict:") + LOG.debug(self.jsondict) + LOG.debug("self.msg.to_jsondict():") + LOG.debug(self.msg.to_jsondict()) + raise SkipTest( + "TODO: make reversible TopologyChangeNotificationBPDUs.") + eq_(self.jsondict, self.msg.to_jsondict()) + + def test_from_jsondict(self): + msg2 = bpdu.TopologyChangeNotificationBPDUs.from_jsondict( + self.jsondict['TopologyChangeNotificationBPDUs']) + eq_(str(msg2), str(self.msg)) + + +class Test_RstBPDUs(unittest.TestCase): + msg = bpdu.RstBPDUs() + jsonstr = ''' + { + "RstBPDUs": { + "flags": 0, + "root_priority": 32768, + "root_system_id_extension": 0, + "root_mac_address": "00:00:00:00:00:00", + "root_path_cost": 0, + "bridge_priority": 32768, + "bridge_system_id_extension": 0, + "bridge_mac_address": "00:00:00:00:00:00", + "port_priority": 128, + "port_number": 0, + "message_age": 0, + "max_age": 20, + "hello_time": 2, + "forward_delay": 15 + } + } + ''' + jsondict = json.loads(jsonstr) + + def test_to_jsondict(self): + # bpdu has some public members which do not relate to arguments + # of __init__(). + LOG.info( + "SKIP [Test_RstBPDUs.test_to_jsondict]") + LOG.debug("self.jsondict:") + LOG.debug(self.jsondict) + LOG.debug("self.msg.to_jsondict():") + LOG.debug(self.msg.to_jsondict()) + raise SkipTest("TODO: make reversible RstBPDUs.") + eq_(self.jsondict, self.msg.to_jsondict()) + + def test_from_jsondict(self): + msg2 = bpdu.RstBPDUs.from_jsondict(self.jsondict['RstBPDUs']) + eq_(str(msg2), str(self.msg)) -- 1.7.10.4 ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
