blob: 8cbf101d92af609725d0ec0dc69546c8ec0b98ab [file] [log] [blame]
Yesudeep Mangalapillyfd1ec362011-08-11 01:47:46 +05301# -*- coding: utf-8 -*-
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +01002#
3# Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu>
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
Sybren A. Stüvel3934ab42016-02-05 16:01:20 +01009# https://www.apache.org/licenses/LICENSE-2.0
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +010010#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Yesudeep Mangalapillyfd1ec362011-08-11 01:47:46 +053016
Sybren A. Stüveled1c81d2016-01-14 12:23:32 +010017import unittest
Yesudeep Mangalapillyfd1ec362011-08-11 01:47:46 +053018import struct
19
20from rsa._compat import is_bytes, byte
21
Sybren A. Stüveld3d10342016-01-22 11:36:06 +010022
23class TestByte(unittest.TestCase):
Yesudeep Mangalapillyfd1ec362011-08-11 01:47:46 +053024 def test_byte(self):
25 for i in range(256):
26 byt = byte(i)
27 self.assertTrue(is_bytes(byt))
28 self.assertEqual(ord(byt), i)
29
30 def test_raises_StructError_on_overflow(self):
31 self.assertRaises(struct.error, byte, 256)
32 self.assertRaises(struct.error, byte, -1)