1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 from nose.tools import eq_
23 LOG = logging.getLogger(__name__)
26 class Test_utils(unittest.TestCase):
34 def test_hex_array_string(self):
36 Test hex_array() with str type.
38 expected_result = '0x01 0x02 0x03 0x04'
39 data = b'\x01\x02\x03\x04'
40 eq_(expected_result, utils.hex_array(data))
42 def test_hex_array_bytearray(self):
44 Test hex_array() with bytearray type.
46 expected_result = '0x01 0x02 0x03 0x04'
47 data = bytearray(b'\x01\x02\x03\x04')
48 eq_(expected_result, utils.hex_array(data))
50 def test_hex_array_bytes(self):
52 Test hex_array() with bytes type. (Python3 only)
56 expected_result = '0x01 0x02 0x03 0x04'
57 data = bytes(b'\x01\x02\x03\x04')
58 eq_(expected_result, utils.hex_array(data))
60 def test_binary_str_string(self):
62 Test binary_str() with str type.
64 expected_result = '\\x01\\x02\\x03\\x04'
65 data = b'\x01\x02\x03\x04'
66 eq_(expected_result, utils.binary_str(data))
68 def test_binary_str_bytearray(self):
70 Test binary_str() with bytearray type.
72 expected_result = '\\x01\\x02\\x03\\x04'
73 data = bytearray(b'\x01\x02\x03\x04')
74 eq_(expected_result, utils.binary_str(data))
76 def test_binary_str_bytes(self):
78 Test binary_str() with bytes type. (Python3 only)
82 expected_result = '\\x01\\x02\\x03\\x04'
83 data = bytes(b'\x01\x02\x03\x04')
84 eq_(expected_result, utils.binary_str(data))