@@ -1589,7 +1589,32 @@ def test_copy(self):
15891589 self .assertEqual (type (a ), type (b ))
15901590 self .assertEqual (type (a .y ), type (b .y ))
15911591
1592- test_fromhex = BaseBytesTest .test_fromhex
1592+ def test_fromhex (self ):
1593+ b = self .type2test .fromhex ('1a2B30' )
1594+ self .assertEqual (b , b'\x1a \x2b \x30 ' )
1595+ self .assertIs (type (b ), self .type2test )
1596+
1597+ class B1 (self .basetype ):
1598+ def __new__ (cls , value ):
1599+ me = self .basetype .__new__ (cls , value )
1600+ me .foo = 'bar'
1601+ return me
1602+
1603+ b = B1 .fromhex ('1a2B30' )
1604+ self .assertEqual (b , b'\x1a \x2b \x30 ' )
1605+ self .assertIs (type (b ), B1 )
1606+ self .assertEqual (b .foo , 'bar' )
1607+
1608+ class B2 (self .basetype ):
1609+ def __init__ (me , * args , ** kwargs ):
1610+ if self .basetype is not bytes :
1611+ self .basetype .__init__ (me , * args , ** kwargs )
1612+ me .foo = 'bar'
1613+
1614+ b = B2 .fromhex ('1a2B30' )
1615+ self .assertEqual (b , b'\x1a \x2b \x30 ' )
1616+ self .assertIs (type (b ), B2 )
1617+ self .assertEqual (b .foo , 'bar' )
15931618
15941619
15951620class ByteArraySubclass (bytearray ):
0 commit comments