1# 2# This file is part of pyasn1 software. 3# 4# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> 5# License: http://snmplabs.com/pyasn1/license.html 6# 7import sys 8 9try: 10 import unittest2 as unittest 11except ImportError: 12 import unittest 13 14from tests.base import BaseTestCase 15 16from pyasn1.compat import binary 17 18 19class BinaryTestCase(BaseTestCase): 20 21 def test_bin_zero(self): 22 assert '0b0' == binary.bin(0) 23 24 25 def test_bin_noarg(self): 26 try: 27 binary.bin() 28 29 except TypeError: 30 pass 31 32 except: 33 assert 0, 'bin() tolerates no arguments' 34 35 36 def test_bin_allones(self): 37 assert '0b1111111111111111111111111111111111111111111111111111111111111111' == binary.bin(0xffffffffffffffff) 38 39 40 def test_bin_allzeros(self): 41 assert '0b0' == binary.bin(0x0000000) 42 43 44 45 def test_bin_pos(self): 46 assert '0b1000000010000000100000001' == binary.bin(0x01010101) 47 48 49 def test_bin_neg(self): 50 assert '-0b1000000010000000100000001' == binary.bin(-0x01010101) 51 52 53suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) 54 55if __name__ == '__main__': 56 unittest.TextTestRunner(verbosity=2).run(suite) 57