1
1
from collections import deque
2
+ import doctest
2
3
import unittest
3
4
from test import support , seq_tests
4
5
import gc
@@ -743,8 +744,9 @@ class C(object):
743
744
744
745
@support .cpython_only
745
746
def test_sizeof (self ):
747
+ MAXFREEBLOCKS = 16
746
748
BLOCKLEN = 64
747
- basesize = support .calcvobjsize ('2P4nP' )
749
+ basesize = support .calcvobjsize ('2P5n%dPP' % MAXFREEBLOCKS )
748
750
blocksize = struct .calcsize ('P%dPP' % BLOCKLEN )
749
751
self .assertEqual (object .__sizeof__ (deque ()), basesize )
750
752
check = self .check_sizeof
@@ -781,6 +783,9 @@ def test_runtime_error_on_empty_deque(self):
781
783
class Deque (deque ):
782
784
pass
783
785
786
+ class DequeWithSlots (deque ):
787
+ __slots__ = ('x' , 'y' , '__dict__' )
788
+
784
789
class DequeWithBadIter (deque ):
785
790
def __iter__ (self ):
786
791
raise TypeError
@@ -809,41 +814,31 @@ def test_basics(self):
809
814
d .clear ()
810
815
self .assertEqual (len (d ), 0 )
811
816
817
+ # TODO: RUSTPYTHON
818
+ @unittest .expectedFailure
812
819
def test_copy_pickle (self ):
813
-
814
- d = Deque ('abc' )
815
-
816
- e = d .__copy__ ()
817
- self .assertEqual (type (d ), type (e ))
818
- self .assertEqual (list (d ), list (e ))
819
-
820
- e = Deque (d )
821
- self .assertEqual (type (d ), type (e ))
822
- self .assertEqual (list (d ), list (e ))
823
-
824
- for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
825
- s = pickle .dumps (d , proto )
826
- e = pickle .loads (s )
827
- self .assertNotEqual (id (d ), id (e ))
828
- self .assertEqual (type (d ), type (e ))
829
- self .assertEqual (list (d ), list (e ))
830
-
831
- d = Deque ('abcde' , maxlen = 4 )
832
-
833
- e = d .__copy__ ()
834
- self .assertEqual (type (d ), type (e ))
835
- self .assertEqual (list (d ), list (e ))
836
-
837
- e = Deque (d )
838
- self .assertEqual (type (d ), type (e ))
839
- self .assertEqual (list (d ), list (e ))
840
-
841
- for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
842
- s = pickle .dumps (d , proto )
843
- e = pickle .loads (s )
844
- self .assertNotEqual (id (d ), id (e ))
845
- self .assertEqual (type (d ), type (e ))
846
- self .assertEqual (list (d ), list (e ))
820
+ for cls in Deque , DequeWithSlots :
821
+ for d in cls ('abc' ), cls ('abcde' , maxlen = 4 ):
822
+ d .x = ['x' ]
823
+ d .z = ['z' ]
824
+
825
+ e = d .__copy__ ()
826
+ self .assertEqual (type (d ), type (e ))
827
+ self .assertEqual (list (d ), list (e ))
828
+
829
+ e = cls (d )
830
+ self .assertEqual (type (d ), type (e ))
831
+ self .assertEqual (list (d ), list (e ))
832
+
833
+ for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
834
+ s = pickle .dumps (d , proto )
835
+ e = pickle .loads (s )
836
+ self .assertNotEqual (id (d ), id (e ))
837
+ self .assertEqual (type (d ), type (e ))
838
+ self .assertEqual (list (d ), list (e ))
839
+ self .assertEqual (e .x , d .x )
840
+ self .assertEqual (e .z , d .z )
841
+ self .assertFalse (hasattr (e , 'y' ))
847
842
848
843
# TODO: RUSTPYTHON
849
844
@unittest .expectedFailure
@@ -1036,31 +1031,10 @@ def test_free_after_iterating(self):
1036
1031
1037
1032
__test__ = {'libreftest' : libreftest }
1038
1033
1039
- def test_main (verbose = None ):
1040
- import sys
1041
- test_classes = (
1042
- TestBasic ,
1043
- TestVariousIteratorArgs ,
1044
- TestSubclass ,
1045
- TestSubclassWithKwargs ,
1046
- TestSequence ,
1047
- )
1048
-
1049
- support .run_unittest (* test_classes )
1050
-
1051
- # verify reference counting
1052
- if verbose and hasattr (sys , "gettotalrefcount" ):
1053
- import gc
1054
- counts = [None ] * 5
1055
- for i in range (len (counts )):
1056
- support .run_unittest (* test_classes )
1057
- gc .collect ()
1058
- counts [i ] = sys .gettotalrefcount ()
1059
- print (counts )
1034
+ def load_tests (loader , tests , pattern ):
1035
+ tests .addTest (doctest .DocTestSuite ())
1036
+ return tests
1060
1037
1061
- # doctests
1062
- from test import test_deque
1063
- support .run_doctest (test_deque , verbose )
1064
1038
1065
1039
if __name__ == "__main__" :
1066
- test_main ( verbose = True )
1040
+ unittest . main ( )
0 commit comments