zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
U
P±d©*ã@sXddlZddlZddlmZmZmZddlmZddlm    m
Z ddl m Z mZmZddlmZddlmZddlmZd4dd„Zdad    d
„Zd d „Zd ZdZdZdZddddgZdZ dd„Z!dd„Z"dd„Z#dd„Z$dd„Z%d d!„Z&d"d#„Z'd$d%„Z(Gd&d'„d'ƒZ)Gd(d)„d)ƒZ*Gd*d+„d+ƒZ+Gd,d-„d-ƒZ,Gd.d/„d/ƒZ-Gd0d1„d1ƒZ.d2d3„Z/dS)5éN)ÚmkdtempÚmkstempÚNamedTemporaryFile)Úrmtree)Úassert_Ú assert_equalÚ assert_raises)Úurlparse)ÚURLErrorcCs$|tƒkrtdd}|Stdƒ‚dS)z$Stub to replace urlopen for testing.Zurltmp_)ÚprefixzName or service not knownN)Ú valid_httpurlrr
)ÚurlÚdataÚtmpfile©rúWd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/lib/tests/test__datasource.pyÚ urlopen_stubs
 
rcCstjatt_dS©N)Úurllib_requestÚurlopenÚ old_urlopenrrrrrÚ setup_modulesrcCs
tt_dSr)rrrrrrrÚteardown_module!srzhttp://www.google.com/z
index.htmlzhttp://fake.abc.web/site/zfake.txtz /etc/shadowz ../../shadowz ..\system.datzc:\windows\system.datsthree is the magic numbercCs"tdd|dd\}}t |¡|S)Nú.txtÚdstmp_T)Úsuffixr ÚdirÚtext)rÚosÚclose©ZfiledirÚfdÚpathrrrÚvalid_textfile2s
r#cCs*tdd|d\}}t |¡t |¡|S)Nrr)rr r)rrrÚremover rrrÚinvalid_textfile9s
 
r%cCsttSr)Ú    http_pathÚ    http_filerrrrr Asr cCsttSr)Ú http_fakepathÚ http_fakefilerrrrÚinvalid_httpurlEsr*cCstSr)r&rrrrÚ valid_baseurlIsr+cCstSr)r(rrrrÚinvalid_baseurlMsr,cCstSr)r'rrrrÚvalid_httpfileQsr-cCstSr)r)rrrrÚinvalid_httpfileUsr.c@sTeZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd d„Z    dd„Z
dd„Z dS)ÚTestDataSourceOpencCstƒ|_t |j¡|_dSr©rÚtmpdirÚ
datasourceÚ
DataSourceÚds©ÚselfrrrÚ setup_methodZszTestDataSourceOpen.setup_methodcCst|jƒ|`dSr©rr1r4r5rrrÚteardown_method^s
z"TestDataSourceOpen.teardown_methodcCs"|j tƒ¡}t|ƒ| ¡dSr)r4Úopenr rr)r6ÚfhrrrÚtest_ValidHTTPbsz!TestDataSourceOpen.test_ValidHTTPc
Cs\tƒ}tt|jj|ƒz|j |¡Wn0tk
rV}zt|jdkƒW5d}~XYnXdSr)r*rÚOSErrorr4r:rÚerrno)r6r ÚerrrÚtest_InvalidHTTPgs z#TestDataSourceOpen.test_InvalidHTTPcCstt|jjtƒƒdSr)rr
r4Ú_cacher*r5rrrÚtest_InvalidHTTPCacheURLErrorpsz0TestDataSourceOpen.test_InvalidHTTPCacheURLErrorcCs*t|jƒ}|j |¡}t|ƒ| ¡dSr)r#r1r4r:rr)r6Ú
local_filer;rrrÚtest_ValidFiless
 z!TestDataSourceOpen.test_ValidFilecCst|jƒ}tt|jj|ƒdSr)r%r1rr=r4r:)r6Z invalid_filerrrÚtest_InvalidFileys
z#TestDataSourceOpen.test_InvalidFilecCs‚z ddl}Wntk
r(t ¡YnXtj |jd¡}| |d¡}|     t
¡|  ¡|j  |¡}|  ¡}|  ¡tt
|ƒdS)Nrz foobar.txt.gzÚw)ÚgzipÚ ImportErrorÚpytestÚskiprr"Újoinr1r:ÚwriteÚ
magic_linerr4Úreadliner)r6rGÚfilepathÚfpÚresultrrrÚtest_ValidGzipFile}s  
 z%TestDataSourceOpen.test_ValidGzipFilecCs‚z ddl}Wntk
r(t ¡YnXtj |jd¡}| |d¡}|     t
¡|  ¡|j   |¡}| ¡}|  ¡tt
|ƒdS)Nrzfoobar.txt.bz2rF)Úbz2rHrIrJrr"rKr1ÚBZ2FilerLrMrr4r:rNr)r6rSrOrPrQrrrÚtest_ValidBz2Files  
 z$TestDataSourceOpen.test_ValidBz2FileN) Ú__name__Ú
__module__Ú __qualname__r7r9r<r@rBrDrErRrUrrrrr/Ys    r/c@s<eZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd S)ÚTestDataSourceExistscCstƒ|_t |j¡|_dSrr0r5rrrr7Ÿsz!TestDataSourceExists.setup_methodcCst|jƒ|`dSrr8r5rrrr9£s
z$TestDataSourceExists.teardown_methodcCst|j tƒ¡ƒdSr)rr4Úexistsr r5rrrr<§sz#TestDataSourceExists.test_ValidHTTPcCst|j tƒ¡dƒdS©NF)rr4rZr*r5rrrr@ªsz%TestDataSourceExists.test_InvalidHTTPcCsDt|jƒ}t|j |¡ƒtƒ}t|ƒ}t|j |¡ƒt|ƒdSr)r#r1rr4rZrr)r6rZlocaldirrrrrD­s 
z#TestDataSourceExists.test_ValidFilecCs t|jƒ}t|j |¡dƒdSr[)r%r1rr4rZ©r6rrrrrE·s
z%TestDataSourceExists.test_InvalidFileN)    rVrWrXr7r9r<r@rDrErrrrrYžs 
rYc@sLeZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd d„Z    dd„Z
dS)ÚTestDataSourceAbspathcCs"tj tƒ¡|_t |j¡|_dSr)rr"Úabspathrr1r2r3r4r5rrrr7½sz"TestDataSourceAbspath.setup_methodcCst|jƒ|`dSrr8r5rrrr9Ás
z%TestDataSourceAbspath.teardown_methodcCsNttƒƒ\}}}}}}tj |j|| tj¡ d¡¡}t||j     
tƒ¡ƒdS©Nú/) r    r rr"rKr1ÚstripÚseprr4r^)r6ÚschemeÚnetlocÚupathÚpmsÚqryÚfrgÚ
local_pathrrrr<Ås
 ÿz$TestDataSourceAbspath.test_ValidHTTPcCsBt|jƒ}tj |¡d}t||j |¡ƒt||j |¡ƒdS©Néÿÿÿÿ)r#r1rr"Úsplitrr4r^)r6rÚ tmpfilenamerrrrDËs
z$TestDataSourceAbspath.test_ValidFilecCsPttƒƒ\}}}}}}tj |j|| tj¡ d¡¡}t||j     
t ƒ¡kƒdSr_) r    r*rr"rKr1rarbrr4r^r )r6rcrdrerfrgrhZ invalidhttprrrr@Ós
 ÿz&TestDataSourceAbspath.test_InvalidHTTPcCsPt|jƒ}t|jƒ}tj |¡d}t||j |¡kƒt||j |¡kƒdSrj)r#r1rr"rlrr4r^)r6Z invalidfilerrmrrrrEÙs
 
 
z&TestDataSourceAbspath.test_InvalidFilecs´tˆjƒ}tj |¡d}‡fdd„}t|tƒƒ ˆj¡ƒt|tƒƒ ˆj¡ƒt||ƒ ˆj¡ƒt||ƒ ˆj¡ƒt    D]0}t|t
|ƒ ˆj¡ƒt||ƒ ˆj¡ƒq~dS)Nrkcstj ˆj |¡¡Sr)rr"r^r4©Úxr5rrÚ<lambda>æóz7TestDataSourceAbspath.test_sandboxing.<locals>.<lambda>) r#r1rr"rlrr Ú
startswithr*Úmalicious_filesr&)r6rrmÚtmp_pathÚfnrr5rÚtest_sandboxingâs
 z%TestDataSourceAbspath.test_sandboxingcCsFtj}z2dt_| ¡| ¡| ¡| ¡| ¡W5|t_XdS©Nú\)rrbr<rDr@rErv©r6Z orig_os_seprrrÚtest_windows_os_sepðs z)TestDataSourceAbspath.test_windows_os_sepN) rVrWrXr7r9r<rDr@rErvrzrrrrr]¼s    r]c@s4eZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd S) ÚTestRepositoryAbspathcCs&tj tƒ¡|_t tƒ|j¡|_dSr)    rr"r^rr1r2Ú
Repositoryr+Úreposr5rrrr7þsz"TestRepositoryAbspath.setup_methodcCst|jƒ|`dSr©rr1r}r5rrrr9s
z%TestRepositoryAbspath.teardown_methodc    CsTttƒƒ\}}}}}}tj |jj|| tj¡ d¡¡}|j     t
ƒ¡}t ||ƒdSr_) r    r rr"rKr}Ú    _destpathrarbr^r-r)    r6rcrdrerfrgrhrirOrrrr<s ÿz$TestRepositoryAbspath.test_ValidHTTPcs\‡fdd„}t|tƒƒ ˆj¡ƒtD]0}t|t|ƒ ˆj¡ƒt||ƒ ˆj¡ƒq&dS)Ncstj ˆj |¡¡Sr)rr"r^r}rnr5rrrprqz7TestRepositoryAbspath.test_sandboxing.<locals>.<lambda>)rr-rrr1rsr&)r6rtrurr5rrv s
 z%TestRepositoryAbspath.test_sandboxingcCs.tj}zdt_| ¡| ¡W5|t_XdSrw)rrbr<rvryrrrrzs  z)TestRepositoryAbspath.test_windows_os_sepN)rVrWrXr7r9r<rvrzrrrrr{ýs
r{c@s<eZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd S)ÚTestRepositoryExistscCstƒ|_t tƒ|j¡|_dSr)rr1r2r|r+r}r5rrrr7sz!TestRepositoryExists.setup_methodcCst|jƒ|`dSrr~r5rrrr9#s
z$TestRepositoryExists.teardown_methodcCst|jƒ}t|j |¡ƒdSr)r#r1rr}rZr\rrrrD's
z#TestRepositoryExists.test_ValidFilecCs t|jƒ}t|j |¡dƒdSr[)r%r1rr}rZr\rrrrE,s
z%TestRepositoryExists.test_InvalidFilecCst|j tƒ¡ƒdSr)rr}rZr r5rrrÚtest_RemoveHTTPFile0sz(TestRepositoryExists.test_RemoveHTTPFilec
CsTtƒ}t|ƒ\}}}}}}tj |jj|¡}t |d¡t|ƒ}    t    |j 
|    ¡ƒdS)NiÀ) r r    rr"rKr}rÚmkdirr#rrZ)
r6Ú    localfilercrdrerfrgrhrirrrrÚtest_CachedHTTPFile3s  z(TestRepositoryExists.test_CachedHTTPFileN)    rVrWrXr7r9rDrErr„rrrrr€s r€c@s$eZdZdd„Zdd„Zdd„ZdS)Ú TestOpenFunccCs tƒ|_dSr)rr1r5rrrr7@szTestOpenFunc.setup_methodcCst|jƒdSr)rr1r5rrrr9CszTestOpenFunc.teardown_methodcCsHt|jƒ}tj||jd}t|ƒ| ¡t |¡}t|ƒ| ¡dS)N)Zdestpath)r#r1r2r:rr)r6rCrPrrrÚtest_DataSourceOpenFs
 
z TestOpenFunc.test_DataSourceOpenN)rVrWrXr7r9r†rrrrr…?sr…cCst ¡}|`| ¡dSr)r2r3Z
_istmpdestÚ__del__)r4rrrÚtest_del_attr_handlingQsrˆ)N)0rrIÚtempfilerrrÚshutilrZnumpy.lib._datasourceÚlibZ _datasourcer2Z numpy.testingrrrÚurllib.requestÚrequestrÚ urllib.parser    Ú urllib.errorr
rrrrr&r'r(r)rsrMr#r%r r*r+r,r-r.r/rYr]r{r€r…rˆrrrrÚ<module>sH    
    ÿEA!!