def test_new_init():
 for x in (_struct.Struct.__new__(_struct.Struct), _struct.Struct.__new__(_struct.Struct, a=2)):
  AreEqual(x.size, (-1))
  AreEqual(x.format, None)
  AssertErrorWithMessage(_struct.error, 'pack requires exactly -1 arguments', x.pack)
  AssertErrorWithMessage(_struct.error, 'unpack requires a string argument of length -1', x.unpack, '')
 a = _struct.Struct('c')
 try:
  a.__init__('bad')
  AssertUnreachable()
 except _struct.error as e:
  pass
 AreEqual(a.format, 'bad')
 AreEqual(a.pack('1'), '1')
 AreEqual(a.unpack('1'), ('1',))
 a.__init__('i')
 AreEqual(a.format, 'i')
 AreEqual(a.pack(0), '\x00\x00\x00\x00')
 AreEqual(a.unpack('\x00\x00\x00\x00'), (0,))

def test_new_init ( ) : for x in ( _struct . Struct . __new__ ( _struct . Struct ) , _struct . Struct . __new__ ( _struct . Struct , a = 2 ) ) : AreEqual ( x . size , ( - 1 ) ) AreEqual ( x . format , None ) AssertErrorWithMessage ( _struct . error , 'pack requires exactly -1 arguments' , x . pack ) AssertErrorWithMessage ( _struct . error , 'unpack requires a string argument of length -1' , x . unpack , '' ) a = _struct . Struct ( 'c' ) try : a . __init__ ( 'bad' ) AssertUnreachable ( ) except _struct . error as e : pass AreEqual ( a . format , 'bad' ) AreEqual ( a . pack ( '1' ) , '1' ) AreEqual ( a . unpack ( '1' ) , ( '1' , ) ) a . __init__ ( 'i' ) AreEqual ( a . format , 'i' ) AreEqual ( a . pack ( 0 ) , '\x00\x00\x00\x00' ) AreEqual ( a . unpack ( '\x00\x00\x00\x00' ) , ( 0 , ) )
tests for calling __new__/__init__ directly on the struct object .