python (3.12.0)

(root)/
lib/
python3.12/
test/
__pycache__/
test_memoryview.cpython-312.opt-1.pyc

Αe
WLdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZGddZ
Gdde
ZGdd	e
ZGd
dZGdd
ZGddZGddej&eeZGddej&eeZGddej&eeZGddej&eeZGddej&eeZGddej&eeZGddej&Zedk(rej8yy)zUnit tests for the memoryview

   Some tests are in test_bytes. Many tests that require _testbuffer.ndarray
   are in test_buffer.
N)
import_helperceZdZdZedZedZdZdZdZ	dZ
dZd	Zd
Z
dZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZy)AbstractMemoryTestsabcdefc|jSN)source_bytesselfs H/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/test/test_memoryview.py_sourcezAbstractMemoryTests._sources   cFtd|j|jgSr)filterro_typerw_typer
s r_typeszAbstractMemoryTests._typessdT\\4<<899rcD||j}tj|}|j||j	dtd|j
dt|j	dtd|j	dtd|j	dtd|jtfd|jtfd|jtfd	|jtfd
|jtfd|jtfd|jtfd
d|j	tj||y)NraficdS)Nmsr<lambda>z=AbstractMemoryTests.check_getitem_with_type.<locals>.<lambda>*sadrcdS)Nrrsrrz=AbstractMemoryTests.check_getitem_with_type.<locals>.<lambda>+saerc*tjSrsysmaxsizersrrz=AbstractMemoryTests.check_getitem_with_type.<locals>.<lambda>,sanrc,tjSrr"rsrrz=AbstractMemoryTests.check_getitem_with_type.<locals>.<lambda>-saorcdSrrrsrrz=AbstractMemoryTests.check_getitem_with_type.<locals>.<lambda>/sQtWrcdS)Nrrsrrz=AbstractMemoryTests.check_getitem_with_type.<locals>.<lambda>0QsVrcdS)Narrsrrz=AbstractMemoryTests.check_getitem_with_type.<locals>.<lambda>1r)r)r
r#getrefcount_viewassertEqualordassertIsInstanceintassertRaises
IndexError	TypeError)rtpboldrefcountrs    @rcheck_getitem_with_typez+AbstractMemoryTests.check_getitem_with_type s0t||ooa(JJqM1s4y)adC(1s4y)2D	*2D	**l3*m4*&<=*&=>)_5)^4)^4+[9rcH|jD]}|j|yr)rr8)rr5s  rtest_getitemz AbstractMemoryTests.test_getitem5s#++	-B((,	-rc	|jD]c}||j}|j|}|jt	|tt
|Dcgc]}||	c}eycc}wr)rr
r-r.listrangelenrr5r6ris     r	test_iterzAbstractMemoryTests.test_iter9sc++	EB4<< A

1
AT!WU3q6]&Cqt&CD	E'DsA4c|js|jd|j|j}tj|}|j|fd}|j
t|d|j
t|d|j
t|tdd|jtj||y)Nno read-only type to testc|d<y)Nrr)valuers rsetitemz:AbstractMemoryTests.test_setitem_readonly.<locals>.setitemEsAaDrrA)
rskipTestr
r#r,r-r2r4
memoryviewr.)rr6r7rFrs    @rtest_setitem_readonlyz)AbstractMemoryTests.test_setitem_readonly?s||MM56LL&ooa(JJqM	)Wd3)Wb1)Wj.>?+[9rc
|js|jd|j|j|j}tj|}|j|t
dd<|j|dddd|j|dddd	|j|d
ddd|j|d
ddd|j|dd
ddd	|j|dddddd	d
d|j|dfd}|jt|dd|jt|dd|jt|tjd|jt|tjd|jt|dd|jt|dd|jt|tddddfd|jt|dtdddfd|jt|dd|jt|ddtdddtddd
f}|jt||djdk(rtnt}|j||dd|j||dd|jt|tddd|jt|tdd
dd|j!tj||y)Nno writable type to test1rs1bcdef0s0bcdefs12s012defrrrscdedefsababcfc||<yrr)keyrErr5s  rrFz:AbstractMemoryTests.test_setitem_writable.<locals>.setitemfsYAcFrrrr r()rr+csab)rrHr
r#r,r-r/_check_contentsr2r3r$r4sliceNotImplementedErrorformat
ValueErrorr.)rr6r7rFslicesexcrr5s      @@rtest_setitem_writablez)AbstractMemoryTests.test_setitem_writableMs||MM45
\\LL&ooa(JJqM4y!RI.D!ARI.E!ARI.C!ARI.)}!RI.1Q!ARI.)}!1Q!ARI.		
*gq$7*gr48*gs{{DA*g|TB)Wc48)WdD9)WuQq|Q.?F)Wq%!A,.?F)WdD9)Wc48!A,a!--wEHHOj#w3/#w51*guQqz4@*guQqz4@+[9rc$|jD]i}||j}|j|}|jt5|d=ddd|jt5|dd=dddky#1swY/xYw#1swYxYw)NrO)rr
r-r2r4rr5r6rs    rtest_delitemz AbstractMemoryTests.test_delitems++	B4<< A

1
A""9-
aD
""9-
acF

	



sA:)B:B	B	cjD]u}j|j}|j}dj	fddD}j||j
|twy)Nrc3TK|]}jt|g!ywr)getitem_typebytes).0rTrs  r	<genexpr>z3AbstractMemoryTests.test_tobytes.<locals>.<genexpr>s) B23!!%*- Bs%(r)rr-r
tobytesjoinr.r0rd)rr5rr6expecteds`    rtest_tobytesz AbstractMemoryTests.test_tobytessv++	,B

2dll+,A		Axx B7@ BBHQ)!!!U+	,rc|jD]N}|j||j}|j}|j	|tdPy)Nr)rr-r
tolistr.r<)rr5rls    rtest_tolistzAbstractMemoryTests.test_tolistsK++	1B

2dll+,A
AQY0	1rc|jD]}|j||j|jD]}|j|dk(|j	|dk7|j	|dk(|j|dk7|j	|dk(|j|dk7|jk(|jddk(|jddddk(|j	ddk(|j	dk(|jdk7|j	dk(|jdk7dfD]j|jtfd|jtfd	|jtfd
|jtfdly)Nrsabcdesabcde1rrrabcdefckSrrrTrsrrz2AbstractMemoryTests.test_compare.<locals>.<lambda>QUrckSrrrrsrrz2AbstractMemoryTests.test_compare.<locals>.<lambda>Q!Vrck\Srrrrsrrz2AbstractMemoryTests.test_compare.<locals>.<lambda>rurckDSrrrrsrrz2AbstractMemoryTests.test_compare.<locals>.<lambda>rsr)rr-r

assertTrueassertFalser2r4)rr5tp_comprTrs   @@rtest_comparez AbstractMemoryTests.test_compares++	<B

2dll+,A;;
9WY%7 78  gi&8!89  gh&7!78WX%6 67  gi&8!89WY%7 78

9
OOAF#OOA1I&OOAaFadN+QqVq[)
Q(]+OOAM*X]+OOHM*^
<!!)];!!)^<!!)^<!!)];	
<+	<rc|j||j}|j|j|j|j|j|j|j|j
d|j|jd|jt|d|j|j|jf|j|jd|S)NrO)rrr)
r-r
r.rXitemsizendimshaper>strides
suboffsets)rr5rs   rcheck_attributes_with_typez.AbstractMemoryTests.check_attributes_with_typesJJr$,,'(4;;/T]]3#$'Q#T]]$45r*rc|js|jd|j|j}|j|jdy)NrCT)rrHrr.readonlyrrs  rtest_attributes_readonlyz,AbstractMemoryTests.test_attributes_readonlys>||MM56++DLL9T*rc|js|jd|j|j}|j|jdy)NrLF)rrHrr.rrs  rtest_attributes_writablez,AbstractMemoryTests.test_attributes_writables>||MM45++DLL9U+rc|jD]}||j}tj|}|j	|}tj|}t|d}|j
|||jd|jtj||d}|jtj||y)Nzutf-8)	rr
r#r,r-strrUencoder.)rr5r6r7roldviewrefcountss       rtest_getbufferz"AbstractMemoryTests.test_getbuffers++		>B4<< A//!,K

1
A!ooa0OAwA  Q(9:S__Q/AAS__Q/=		>rch|jD]"}t|tsGdd}Gdd|}Gdd}||d}|j|}|}||_||_t
j|}dx}x}}tj|j|du|||d}|}||_||_t
j|}dx}}tj|j|du|%y)NceZdZdZy)+AbstractMemoryTests.test_gc.<locals>.MyViewc$t||_yr)rIr)rbases  r__init__z4AbstractMemoryTests.test_gc.<locals>.MyView.__init__s'-DFrN)__name__
__module____qualname__rrrrMyViewrs.rrceZdZy)-AbstractMemoryTests.test_gc.<locals>.MySourceNrrrrrrMySourcerrrceZdZy)-AbstractMemoryTests.test_gc.<locals>.MyObjectNrrrrMyObjectrrrrabc)r
isinstancetyper-roweakrefrefgccollectrxx)	rr5rrrr6rrwrs	         rtest_gczAbstractMemoryTests.test_gcs
++#	0Bb$'
.
.
2



F$A

1
A
AACACQBAAJJLOOBDDL"$/r&z"A
AACACQBLAJJLOOBDDL"$/G#	0rc|jtd}|5t|ddd|5|jddd|5|j	ddd|5|dddd|5d|d<ddd|5t|ddd|5|jddd|5|jddd|5|jddd|5|jddd|5|jddd|5|jddd|5|5	dddddd|jdt||jdt||j|||j!|t#||j$|j!|||j$y#1swYxYw#1swYxYw#1swYxYw#1swYxYw#1swYxYw#1swYxYw#1swYxxYw#1swYnxYw#1swYdxYw#1swYZxYw#1swYPxYw#1swYFxYw#1swYDxYw#1swYIxYw)Nreleasedrxzreleased memory)assertRaisesRegexrYrdrgrlr>rXr}r~rrrassertInrreprr.assertNotEqualrIr
)rrr5checks    r_check_releasedz#AbstractMemoryTests._check_releaseds&&z:>
E!H
AIIK
AHHJ
AaD
4AaD
CF
AHH
AJJ
AFF
AJJ
AGG
AII
	

		


'Q0

'a1AAz"T\\*:;<Ar$,,/0)	

		sGG
G*%G75HH
H2
H+	
H8 
I7
I
I%I9(I,*I9GG'*G47HHHH(+H58IIII),I6	1I99JcR|jD]}||j}|j|}|5}|j||ddd|j	|||j|}|5|jdddy#1swYJxYw#1swYxYwr)rr
r-assertIsrrelease)rr5r6rcms     rtest_contextmanagerz'AbstractMemoryTests.test_contextmanagers++		B4<< A

1
A
%b

b!$
%  B'

1
A
		

		
%
%


sB5BB	B&	c|jD]i}||j}|j|}|j|j	|||j|j	||kyr)rr
r-rrr_s    rtest_releasez AbstractMemoryTests.test_release&sb++	(B4<< A

1
A
IIK  B'
IIK  B'	(rc|j}||jd||j}|j|}t	j
d}|j
t|j|y)NrCsZZZZ)	rrHr
r-ioBytesIOr2r4readintor?s     rtest_writable_readonlyz*AbstractMemoryTests.test_writable_readonly0s^\\
:MM56t||JJqMJJw)QZZ3rcF|jt|jiyr)r2r4r-r
s rtest_getbuf_failz$AbstractMemoryTests.test_getbuf_fail;s)TZZ4rc|j}||jd||j}|j|}|j	t|td|j
|j	t|td|j|}|j
|jtt
|y)NrCr)	rrHr
r-r.hashrr2rYr_s    r	test_hashzAbstractMemoryTests.test_hash>s\\
:MM56t||JJqMa$y/2			a$y/2
JJqM			*dA.rc|j}||jd||j}|j|}|j	t
t|y)NrL)rrHr
r-r2rYrr_s    rtest_hash_writablez&AbstractMemoryTests.test_hash_writablePsJ
\\
:MM45t||JJqM*dA.rcp|jD]}||j}|j|}g|ffd	}tj||}|j||~tjj|j|d|jd|y)Nc(j|yr)append)rr6Ls  rcallbackz2AbstractMemoryTests.test_weakref.<locals>.callback_srr)	rr
r-rrrtestsupport
gc_collect)rr5r6rrrrs      @rtest_weakrefz AbstractMemoryTests.test_weakrefYs++	#B4<< A

1
AA 
Q)BMM"$"LL##%MM"$%MM!A$"	#rc
^|jD]}||j}|j|}tt	|j}|j
tt	|||j
tt	|t|dddy)Nr)rr
r-r<reversedrlr.)rr5r6raslists     r
test_reversedz!AbstractMemoryTests.test_reversedhs++	?B4<< A

1
A(188:./FT(1+.7T(1+.QttW
>	?rc|jD]}||j}|j|}|j}|j	|j
|j	t
|j
|j|j|j|j|jyr)
rr
r-
toreadonlyrxrrIr.rlr)rr5r6rmms     rtest_toreadonlyz#AbstractMemoryTests.test_toreadonlyps++	B4<< A

1
ABOOBKK(OOJrN334RYY[!((*5JJL
HHJ	rcZtjdgd}t|}|jd}|jd}|dd}t|}~|j|dd|j|dd|j|jd|j|jd|jd}|j|dd|j|dd|j|jd|j|jdy)NH)rrrBrrQrI)arrayrIcastr.rX)rr+rrr6rTd_s        rtest_issue22668z#AbstractMemoryTests.test_issue22668{sKK12qM
FF3K
FF3K
aFqM
1s#1s#3'3'
FF3K1s#1s#3'3'rN) rrrr	propertyr
rr8r:rArJr\r`rjrnr{rrrrrrrrrrrrrrrrrrrrrsL
!!:::*-E:2:h,1<<	+,>$0L10
(	45/$/
#?	(rrc eZdZeZeZeZdZdZ	y)BaseBytesMemoryTestsrOrN)
rrrrdr	bytearrayrrcr}rXrrrrrsGGLH
FrrceZdZdZdZdZejdjZdZe	jddZe	jddZy)	BaseArrayMemoryTestsNc@tjdt|SNr@)rr<rr6s  rrzBaseArrayMemoryTests.<lambda>sekk#tAw7rc\tjdt|jSr)rr<rgrs  rrzBaseArrayMemoryTests.<lambda>s5;;sDG#<#D#D#Frr@z/XXX test should be adapted for non-byte bufferscyrrr
s rrz#BaseArrayMemoryTests.test_getbufferrz:XXX NotImplementedError: tolist() only supports byte viewscyrrr
s rrnz BaseArrayMemoryTests.test_tolistrr)
rrrrrrcrr}rXunittestskiprrnrrrrrslG7GFLu{{3((H
FX]]DE
F
X]]OP
Q
rrceZdZdZdZy)BaseMemoryviewTestsct|SrrI)robjs  rr-zBaseMemoryviewTests._views#rc4|j|||yrr.rr5rcontentss    rrUz#BaseMemoryviewTests._check_contentssbl+rN)rrrr-rUrrrrrs,rrc"eZdZdZdZdZdZy)BaseMemorySliceTestsXabcdefYc"t|}|ddSNrOrrrrs   rr-zBaseMemorySliceTests._viewssO1v
rc:|j|dd||yrrrs    rrUz$BaseMemorySliceTests._check_contentsQq2h<0rc|jD]\}t||j}tj|}|dd|jtj||^y)NrOrQ)rrIr
r#r,r.)rr5rr7s    r	test_refszBaseMemorySliceTests.test_refssX++	>B2dll+,A//!,K
aFS__Q/=		>rN)rrrr	r-rUrrrrrrsL1>rrceZdZdZdZdZy)BaseMemorySliceSliceTestsrc(t|}|ddddS)NrrOrrs   rr-zBaseMemorySliceSliceTests._viewssO!uQRyrc:|j|dd||yrrrs    rrUz)BaseMemorySliceSliceTests._check_contentsrrN)rrrr	r-rUrrrrrsL1rrceZdZdZy)BytesMemoryviewTestc|jD]}||j}|jt||jt||j	t
t|j	t
t|||j	t
t||j	t
t|dy)N)object)argumentT)rr
rxrIr2r4)rr5obs   rtest_constructorz$BytesMemoryviewTest.test_constructors++	HBDLL!BOOJrN+OOJb12i4iR<ibAiR$G	HrN)rrrrrrrrrsHrrceZdZdZy)ArrayMemoryviewTestctjdtd}t|}tjdtddd}||dd|j||y)Nr@
	r)rr=rIr.)rr+rnew_as    rtest_array_assignz%ArrayMemoryviewTest.test_array_assignsQKKU2Y'qMCq"b!12!E"rN)rrrrrrrrrs#rrceZdZy)BytesMemorySliceTestNrrrrrrrrceZdZy)ArrayMemorySliceTestNrrrrrrrrrceZdZy)BytesMemorySliceSliceTestNrrrrrrrrrceZdZy)ArrayMemorySliceSliceTestNrrrrr r rrr c0eZdZdZdZdZdZdZdZy)	OtherTestcttjd}t|jd}|j}t	|jd}|dd|dd|dd|dd|j
|jddD]}|j|5|j}t	|j|}t	|j|dd|ddt	|j|dd|dd|j
|jddddy#1swYxYw)Nctypesg333333?rrQBbc)	r
import_modulerdc_doublerIrr.rEsubTest)rr$p6rrrXs      rtest_ctypes_castzOtherTest.test_ctypes_casts&,,X6
6??3'
(OOqMs#2A"112!"#&	/Ff%
/OO%qM&&v."2++F3BQ7"1"2++F3AB7!"  #.
/
/	/
/
/s
BD..D7	cztjdddd}tjdddd}t|jd}t|jd}|j	|j
dz|j
|j
|j|jy)	Neeer(gg?fffefrQ)structpackrIrr.nbytesassertListEqualrl)r	half_data
float_data	half_view
float_views     rtest_half_floatzOtherTest.test_half_floatsKKsD#6	[[T37
y)..s3	
+005
))A-z/@/@AY--/1B1B1DErczddz}t|}|ddd}|j|jddzy)NrNi@
r30)rIr.hex)rrm1m2s    rtest_memoryview_hexzOtherTest.test_memoryview_hexs;6M
]
"X4&=1rctd}|jt5tj|dddy#1swYyxYw)Nr)rIr2r4copyrs  r	test_copyzOtherTest.test_copy"s:v


y
)	IIaL			sAA	ctd}ttjdzD]6}|j	t
5tj||ddd8y#1swYCxYw)NrrO)rIr=pickleHIGHEST_PROTOCOLr2r4dumps)rrprotos   rtest_picklezOtherTest.test_pickle'sav622Q67	'E""9-
'Q&
'
'	'
'
'sA""A+	cdfdGfdd}Gfdd}Gfdd}dttd	z|jt5|ddddttd	z|j	td|d
gdzdttd	z|j	t|dd
gdzdttd	zj
d
d|jtd5|dfddddttd	zj
d
d|jtd5d|fddddttd	z|jtd5d|<ddd|j	ddddttd	z|jtd5dd|ddd|j	ddddttd	z|jtd5d|dddd|j	ddddttd	zj
d
d|jtd5d|df<ddd|j	ddddttd	zj
d
d|jtd5dd|f<ddd|j	ddddttd	z|jtd5|d<ddd|j	ddddD]}|j|5dttd	zj
||jtd5|d<ddd|j	dddddddD]}|j|5dttd	zj
||jtd5|d<ddd|j	dddddddttd	zj
d|jtd5|d<ddd|j	dddy#1swYxYw#1swYxYw#1swYxYw#1swYxYw#1swYJxYw#1swYxYw#1swYxYw#1swYHxYw#1swYxYw#1swYxYw#1swYxYw#1swYxYw#1swYxYw#1swYxYw)Nc<jtyr)rr)barsizesrrz3OtherTest.test_use_released_memory.<locals>.release2s
IIK4BrceZdZfdZy)3OtherTest.test_use_released_memory.<locals>.MyIndexcy)Nr^rrrs r	__index__z=OtherTest.test_use_released_memory.<locals>.MyIndex.__index__7s	rN)rrrrQrsrMyIndexrN6s
rrSceZdZfdZy)3OtherTest.test_use_released_memory.<locals>.MyFloatcy)Ng@rrPs r	__float__z=OtherTest.test_use_released_memory.<locals>.MyFloat.__float__;	rN)rrrrWrRsrMyFloatrU:
rrYceZdZfdZy)2OtherTest.test_use_released_memory.<locals>.MyBoolcy)NTrrPs r__bool__z;OtherTest.test_use_released_memory.<locals>.MyBool.__bool__?rXrN)rrrr^rRsrMyBoolr\>rZrr_r^r)@rQzoperation forbiddenr)rQrc*ssspambhilqnBHILQN)fmtfd?)	rIrr2rYr.r<rrr()	rrSrYr_rgrKrrrLs	     @@@@rtest_use_released_memoryz"OtherTest.test_use_released_memory-s	!						
y./


z
*	
giL	y./a
m,seai8
y./a	!n-uqy9
y./44S'B

#
#J0E
F	
gilO	y./44S'B

#
#J0E
F	
alO	y./

#
#J0E
F	AgiL	BQ)
y./

#
#J0E
F	$#AjwyM	$BQ)
y./

#
#J0E
F	%$AgiN	%BQ)
y./44S'B

#
#J0E
F	! AgilO	!Ab7+
y./44S'B

#
#J0E
F	! AalO	!BQ)
y./

#
#J0E
F	9AaD	BQ)!	2C#&
2y67<<SA++J8MN%"9AaD%  BQ1
2
2	2	2C#&
2y67<<SA++J8MN%"9AaD%  BQ1
2
2	2y./44S9

#
#J0E
F	8AaD	BQ)Y				
		
			$	$	%	%	!	!
	!	!		%%
2
2%%
2
2		s U2
U

U
U'!U48V
V
V!V( ?WV5*W(?W'W2WW)U

UU$'U14U>VVV%(V25V?:WW	WWW&	)W2N)	rrrr*r8r>rArGrjrrrr"r"s"/&F2
'd*rr"__main__)__doc__rtest.supportrr#rrrrr@rCr0rrrrrrrTestCaserrrrrr r"rmainrrr<module>rps3
		

&y(y(@.

.

(,,>>"11H(++-H	#(++-	#	8,,.		8,,.		 1 13		 1 13	
R*!!R*hzHMMOr