backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / test_utils.py
1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import unittest
17 import logging
18 import six
19 from nose.tools import eq_
20
21 from ryu import utils
22
23 LOG = logging.getLogger(__name__)
24
25
26 class Test_utils(unittest.TestCase):
27
28     def setUp(self):
29         pass
30
31     def tearDown(self):
32         pass
33
34     def test_hex_array_string(self):
35         """
36         Test hex_array() with str type.
37         """
38         expected_result = '0x01 0x02 0x03 0x04'
39         data = b'\x01\x02\x03\x04'
40         eq_(expected_result, utils.hex_array(data))
41
42     def test_hex_array_bytearray(self):
43         """
44         Test hex_array() with bytearray type.
45         """
46         expected_result = '0x01 0x02 0x03 0x04'
47         data = bytearray(b'\x01\x02\x03\x04')
48         eq_(expected_result, utils.hex_array(data))
49
50     def test_hex_array_bytes(self):
51         """
52         Test hex_array() with bytes type. (Python3 only)
53         """
54         if six.PY2:
55             return
56         expected_result = '0x01 0x02 0x03 0x04'
57         data = bytes(b'\x01\x02\x03\x04')
58         eq_(expected_result, utils.hex_array(data))
59
60     def test_binary_str_string(self):
61         """
62         Test binary_str() with str type.
63         """
64         expected_result = '\\x01\\x02\\x03\\x04'
65         data = b'\x01\x02\x03\x04'
66         eq_(expected_result, utils.binary_str(data))
67
68     def test_binary_str_bytearray(self):
69         """
70         Test binary_str() with bytearray type.
71         """
72         expected_result = '\\x01\\x02\\x03\\x04'
73         data = bytearray(b'\x01\x02\x03\x04')
74         eq_(expected_result, utils.binary_str(data))
75
76     def test_binary_str_bytes(self):
77         """
78         Test binary_str() with bytes type. (Python3 only)
79         """
80         if six.PY2:
81             return
82         expected_result = '\\x01\\x02\\x03\\x04'
83         data = bytes(b'\x01\x02\x03\x04')
84         eq_(expected_result, utils.binary_str(data))