Files
auto-ragas/rag_evaluation/tests/__pycache__/test_document_loader.cpython-314-pytest-9.0.1.pyc
T

184 lines
48 KiB
Plaintext
Raw Normal View History

2026-01-16 16:01:39 +08:00
+
Å›hi@cóÈ€Rt^RIt^RIHuHt^RIt^RIt^RI t ^RI
H t ^RI H
t
HtHtHtHt!RR4t!RR4t!RR 4t!R
R 4t!R R
4tR#)z
Unit tests for document loader
N)ÚPath)ÚDocumentÚDocumentLoaderÚ
TextLoaderÚMarkdownLoaderÚload_documentscó0a€]tRt^toRtRtRtRtVtR#)Ú TestDocumentzTest cases for Document classc  óŽ€RpRRRR/p\WR7pVPqDV8HqU'gÿ\P!RV3RWA34RR\P
!49g\P !V4'd\P!V4MRR \P!V4R
R \P
!49g\P !V4'd\P!V4MR /,pR R
V/,p\\P!V44hR;rEVPqDV8HqU'gÿ\P!RV3RWB34RR\P
!49g\P !V4'd\P!V4MRR \P!V4R
R\P
!49g\P !V4'd\P!V4MR/,pR R
V/,p\\P!V44hR;rER#)z!Test creating a Document instanceú Test contentÚsourceztest.txtÚauthorÚTest©ÚcontentÚmetadataÚpy0ÚdocÚpy2Úpy4rúassert %(py6)sÚpy6Nr©ú==)z4%(py2)s
{%(py2)s = %(py0)s.page_content
} == %(py4)s)z0%(py2)s
{%(py2)s = %(py0)s.metadata
} == %(py4)s© rÚ page_contentÚ
@pytest_arÚ_call_reprcompareÚ @py_builtinsÚlocalsÚ_should_repr_global_nameÚ _safereprÚAssertionErrorÚ_format_explanationr)ÚselfrrrÚ @py_assert1Ú @py_assert3Ú @py_format5Ú @py_format7s& ÚCD:\workspace\cc-plugin\rag_evaluation\tests\test_document_loader.pyÚtest_document_creationÚ#TestDocument.test_document_creations+€à ˆØ˜j¨(°FÐ;ˆÜ˜wÔ:ˆà×ÑÐ* 7Ñ*×*×*×*Ó*Ð×*×*×*×*×*×*ˆs×*×*×*Ò*ˆs×*×*Ö*Ð×*×*×*×*×*Ö* 7×*×*×*Ò* 7×*×*×*×*×*×*×*Ò*Ø�|‰|Ð'˜xÑ'×'×'×'Ó'ˆ|×'×'×'×'×'×'ˆs×'×'×'Ò'ˆs×'×'Ö'ˆ|×'×'×'×'×'Ö'˜x×'×'×'Ò'˜x×'×'×'×'×'×'×'Ô'óc  ó°€\R/R7pVPpRq2V8HqD'gÇ\P!R
V3R W#34RR\P
!49g\P !V4'd\P!V4MRR\P!V4R\P!V4/,pRRV/,p\\P!V44hR ;p;rCVPp/q2V8HqD'gÇ\P!R
V3R W#34RR\P
!49g\P !V4'd\P!V4MRR\P!V4R\P!V4/,pRRV/,p\\P!V44hR ;p;rCR #)
z+Test creating a Document with empty contentÚrrrrÚpy5úassert %(py7)sÚpy7Nr©z4%(py2)s
{%(py2)s = %(py0)s.page_content
} == %(py5)s)z0%(py2)s
{%(py2)s = %(py0)s.metadata
} == %(py5)sr)r#rr$Ú @py_assert4r%Ú @py_format6Ú @py_format8s& r(Útest_document_empty_contentÚ(TestDocument.test_document_empty_contentsö€ä˜r¨BÔ/ˆØ×ÑÐ% 2Ð% 2Ñ%×%×%×%Ó%Ð×%×%×%×%×%×%ˆs×%×%×%Ò%ˆs×%×%Ö%Ð×%×%Ô% 2×%×%×%×%×%×%×%Ò%Ø�|‰|Ð!˜rÐ!˜rÑ!×!×!×!Ó!ˆ|×!×!×!×!×!×!ˆs×!×!×!Ò!ˆs×!×!Ö!ˆ|×!×!Ô!˜r×!×!×!×!×!×!×!Ô!r+©N) Ú__name__Ú
__module__Ú __qualname__Ú__firstlineno__Ú__doc__r)r5Ú__static_attributes__Ú__classdictcell__©Ú
__classdict__s@r(rrsø‡€Ù'ò(÷"ð"r+rcóBa€]tRt^%toRtRtRtRtRtRt Rt
Vt R#) ÚTestDocumentLoaderz(Test cases for DocumentLoader base classc óš€\P!\4;_uu_4\R4RRR4R# +'giR#;i)z;Test that FileNotFoundError is raised for non-existent fileznonexistent_file.txtN)ÚpytestÚraisesÚFileNotFoundErrorr)r#s&r(Útest_file_not_foundÚ&TestDocumentLoader.test_file_not_found(s*€ä
�]Š]Ô,×
-Õ
-Ü Ð1Ô 2÷.×
-×
-Ò
-ús £ 9¹ A
c óЀ\P!RRRR7;_uu_4pVPR4VPpRRR4\ X4p\
P !\4;_uu_4VP4RRR4\P!V4R# +'giLo;i +'giL;;i \P!X4i;i)z+Test that load() raises NotImplementedErrorÚwFú.txt©ÚmodeÚdeleteÚsuffixÚtestN) ÚtempfileÚNamedTemporaryFileÚwriteÚnamerrDrEÚNotImplementedErrorÚloadÚosÚunlink)r#ÚfÚ temp_pathÚloaders& r(Útest_load_not_implementedÚ,TestDocumentLoader.test_load_not_implemented-s‘€ä
×
(Ò
(¨c¸%È×
OÕ
OÐSTØ
�G‰G�FŒOØŸ™ˆI÷Pð !Ü# IÓ.ˆFÜ—’Ô2×3Õ3Ø— ‘ ”
÷4ô
�IŠI�iÖ ÷P×
Oú÷ 4×3ûô
�IŠI�iÕ ús/¢B'Á -C
Á6B:ÂC
Â' B7 Â: C
ÃC
Ã
C%c ór€Rp\P!RRRRR7;_uu_4pVPV4VPpRRR4\ X4pVP 4p^qeV8„qw'g±\ P!RV3RWV34RR \P!49g\ P!V4'd\ P!V4MR R
\ P!V4/,pR R V/,p \\ P!V 44hR;rvVPp
Rqº!V 4p \V 4qÕV
8¬qw'Eg—\ P!RV3RW]34RR \P!49g\ P!V4'd\ P!V4MR R
R\P!49g!\ P!\4'd\ P!\4MRR
R\P!49g\ P!V4'd\ P!V4MRR \ P!V
4R\ P!V 4R\ P!V 4R\ P!V
4/,pRRV/,p\\ P!V44hR;p;p
;p ;rÍ\ P"!V4R# +'giELÐ;i \ P"!X4i;i)zTest getting file sizez!Test content for size calculationrJFrKúutf-8©rMrNrOÚencodingNrÚsizeÚpy3úassert %(py5)sr.rÚlenrr0Úpy9Úpy11zassert %(py13)sÚpy13©Ú>)z%(py0)s > %(py3)s)ú>=)zl%(py0)s >= %(py11)s
{%(py11)s = %(py2)s(%(py9)s
{%(py9)s = %(py5)s
{%(py5)s = %(py3)s.encode
}(%(py7)s)
})
})rQrRrSrTrÚ
get_file_sizerrrrrr r!r"ÚencodererWrX)r#rrYrZr[rbÚ @py_assert2r$Ú @py_format4r3r2Ú @py_assert6Ú @py_assert8Ú @py_assert10Ú @py_format12Ú @py_format14s& r(Útest_get_file_sizeÚ%TestDocumentLoader.test_get_file_size:s¯€à5ˆÜ
×
(Ò
(¨c¸%ÈÐY`×
aÕ
aÐefØ
�G‰G�GÔ ØŸ™ˆI÷bð !Ü# IÓ.ˆFØ×'Ñ'Ó)ˆD؈O˜!‘8�O�O�O‹O�4�O�O�O�O�O�O�4�O�O�OŠO�4�O�OŽO˜!�O�O�O�O�O�O�OˆOà&Ÿ~™~Ð 7¨gÐ 7˜~¨gÓ6Ð 7œ3Ð6Ó7Ð 7Ð7Ñ7× 7× 7× 7Ô 7�4× 7× 7× 7× 7× 7× 7�4× 7× 7× 7Ò 7�4× 7× 7× 7× 7× 7× 7Ð 7œ3× 7× 7× 7Ò 7œ3× 7× 7× 7× 7× 7× 7Ð 7˜w× 7× 7× 7Ò 7˜w× 7× 7Ö 7˜~× 7× 7Ô 7¨g× 7× 7Ô 7Ð6× 7× 7Ô 7Ð7× 7× 7× 7× 7× 7× 7× 7Ö 7ä �IŠI�iÖ ÷b×
aÐ
aûô
�IŠI�iÕ ús4¥L
Á A8LÃCLÆ$ALÇ6ALÉB*LÌ
L ÌL6c óÖ€\P!RRRR7;_uu_4pVPR4VPpRRR4\ X4pVP 4pRqTV8Hqf'g±\ P!R V3R
WE34RR\P!49g\ P!V4'd\ P!V4MRR \ P!V4/,pR
R V/,p\\ P!V44hR;re\P!V4R# +'giEL;i \P!X4i;i)zTest getting file extensionrJFrKrLrPNrÚextrcrdr.r©z%(py0)s == %(py3)s©rQrRrSrTrÚget_file_extensionrrrrrr r!r"rWrX© r#rYrZr[rxrnr$ror3s & r(Útest_get_file_extensionÚ*TestDocumentLoader.test_get_file_extensionJóÖ€ä
×
(Ò
(¨c¸%È×
OÕ
OÐSTØ
�G‰G�FŒOØŸ™ˆI÷Pð !Ü# IÓ.ˆFØ×+Ñ+Ó-ˆCØ Ð ˜&‘=× × × Ó �3× × × × × × �3× × × Ò �3× × Ö ˜&× × × × × × × Ð ä �IŠI�iÖ ÷P×
OÐ
Oûô
�IŠI�iÕ úó¢D<Á A8EÃA"EÄ< E
ÅE(c óÖ€\P!RRRR7;_uu_4pVPR4VPpRRR4\ X4pVP 4pRqTV8Hqf'g±\ P!R
V3RWE34RR \P!49g\ P!V4'd\ P!V4MR R
\ P!V4/,pR R V/,p\\ P!V44hR;re\P!V4R# +'giEL;i \P!X4i;i)z%Test that file extension is lowercaserJFz.TXTrLrPNrKrrxrcrdr.rryrzr|s & r(Ú(test_get_file_extension_case_insensitiveÚ;TestDocumentLoader.test_get_file_extension_case_insensitiveWrr€r7N) r8r9r:r;r<rGr\rur}r‚r=r>r?s@r(rBrB%s&ø‡€Ù2ò3ò
!ò!ò !÷ !ð !r+rBcó<a€]tRt^etoRtRtRtRtRtRt Vt
R#)ÚTestTextLoaderzTest cases for TextLoaderc  óä €Rp\P!RRRRR7;_uu_4pVPV4VPpRRR4\ X4pVP 4p\
V4p^qvV8Hqˆ'Eg\P!RV3RWg34RR \P!49g!\P!\ 4'd\P!\ 4MR R
R \P!49g\P!V4'd\P!V4MR R \P!V4R
\P!V4/,p RRV /,p
\\P!V
44hR;p;r‡V^,q»PqfV8Hqˆ'gÇ\P!RV3RWa34R
\P!V 4R \P!V4RR\P!49g\P!V4'd\P!V4MR/,p RRV /,p
\\P!V
44hR;p ;rhV^,P R,p RqëV8Hqf'gy\P!RV3RW¾34R
\P!V 4R\P!V4/,pRR
V/,p \\P!V 44hR;p ;rnV^,P R,q»V8Hqf'g±\P!RV3R W³34R
\P!V 4R R\P!49g\P!V4'd\P!V4MR/,pRRV/,p \\P!V 44hR;r¶V^,P R,p ^qëV8„qf'gy\P!R!V3R"W¾34R
\P!V 4R\P!V4/,pRR
V/,p \\P!V 44hR;p ;rn\"P$!V4R# +'giEL‰;i \"P$!X4i;i)#zTest loading a text filez.This is a test text file.
With multiple lines.rJFrKr_r`NrreÚpy1Údocsrcrúassert %(py8)sÚpy8r.rr/r0Ú file_typeÚtextrrr rZrdÚ file_sizer©z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)s©z4%(py3)s
{%(py3)s = %(py1)s.page_content
} == %(py5)s©z%(py1)s == %(py4)s©z%(py1)s == %(py3)sri©z%(py1)s > %(py4)s)rQrRrSrTrrVrerrrrrr r!r"rrrWrX©r#rrYrZr[rˆrnÚ @py_assert5r2r'Ú @py_format9Ú @py_assert0r3r4r%r&ros& r(Útest_load_text_fileÚ"TestTextLoader.test_load_text_filehs¶€àCˆÜ
×
(Ò
(¨c¸%ÈÐY`×
aÕ
aÐefØ
�G‰G�GÔ ØŸ™ˆI÷bð
!Ü  Ó*ˆFØ—;‘;“=ˆDä�t“9Ð ! Ð ! ‘>× !× !× !Ô !�9× !× !× !× !× !× !”3× !× !× !Ò !”3× !× !× !× !× !× !Ð !�t× !× !× !Ò !�t× !× !Ö !�9× !× !Ô ! × !× !× !× !× !× !× !Ò !ؘ•7Ð 2×'Ñ'Ð 2¨7Ñ2× 2× 2× 2Ó 2Ð'× 2× 2Õ 2�7× 2× 2Ô 2Ð'× 2× 2× 2× 2× 2Ö 2¨7× 2× 2× 2Ò 2¨7× 2× 2× 2× 2× 2× 2× 2Ô 2ؘ•7×#Ñ# KÕ0Ð :°FÐ :°FÑ:× :× :× :Ó :Ð0× :× :Õ :Ð0× :× :Ô :°F× :× :× :× :× :× :× :Ò :ؘ•7×#Ñ# HÕ-Ð :°Ñ:× :× :× :Ó :Ð-× :× :Õ :Ð-× :× :× :× :× :Ö :°× :× :× :Ò :°× :× :× :× :× :× :× :Ò :ؘ•7×#Ñ# KÕ0Ð 4°1Ð 4°1Ñ4× 4× 4× 4Ó 4Ð0× 4× 4Õ 4Ð0× 4× 4Ô 4°1× 4× 4× 4× 4× 4× 4× 4Ò 4ä �IŠI�iÖ ÷b×
aÐ
aûô
�IŠI�iÕ úó4¥SÁ BSÃASÄ'DSÈ=E=SÎ;C0SÓ S ÓS/c  ó^€\P!RRRRR7;_uu_4pVPpRRR4\X4pVP 4p\ V4p^qeV8Hqw'Eg\ P!RV3RWV34RR\P!49g!\ P!\
4'd\ P!\
4MRR R
\P!49g\ P!V4'd\ P!V4MR
R \ P!V4R \ P!V4/,pRRV/,p \\ P!V 44hR;p;rvV^,qªPpR
qeV8Hqw'g�\ P!RV3RWV34R \ P!V
4R \ P!V4R \ P!V4/,pRRV/,p \\ P!V 44hR;p
;p;rvV^,PR,p
^qºV 8HqU'gy\ P!RV3RW«34R \ P!V
4R\ P!V 4/,p RR V /,p\\ P!V44hR;p
;r[\ P"!V4R# +'giELÙ;i \ P"!X4i;i)zTest loading an empty text filerJFrKr_r`Nrrer‡rˆrcrr-r‰rŠr�rrrrŽ©z4%(py3)s
{%(py3)s = %(py1)s.page_content
} == %(py6)sr�)rQrRrTrrVrerrrrrr r!r"rrrWrX)
r#rYrZr[rˆrnr”r2r'r•r–r%r&s
& r(Útest_load_empty_text_fileÚ(TestTextLoader.test_load_empty_text_file{sÇ€ä
×
(Ò
(¨c¸%ÈÐY`×
aÕ
aÐefØŸ™ˆI÷bð !Ü  Ó*ˆFØ—;‘;“=ˆDä�t“9Ð ! Ð ! ‘>× !× !× !Ô !�9× !× !× !× !× !× !”3× !× !× !Ò !”3× !× !× !× !× !× !Ð !�t× !× !× !Ò !�t× !× !Ö !�9× !× !Ô ! × !× !× !× !× !× !× !Ò !ؘ•7Ð -×'Ñ'Ð -¨2Ð -¨2Ñ-× -× -× -Ó -Ð'× -× -Õ -�7× -× -Ô -Ð'× -× -Ô -¨2× -× -× -× -× -× -× -Ô -ؘ•7×#Ñ# KÕ0Ð 5°AÐ 5°AÑ5× 5× 5× 5Ó 5Ð0× 5× 5Õ 5Ð0× 5× 5Ô 5°A× 5× 5× 5× 5× 5× 5× 5Ò 5ä �IŠI�iÖ ÷b×
aÐ
aûô
�IŠI�iÕ ús%£
L¹BLÃALÄGLÌ L ÌL,c  ó¤€Rp\P!RRRRR7;_uu_4pVPV4VPpRRR4\ X4pVP 4p\
V4p^qvV8Hqˆ'Eg\P!RV3RWg34RR \P!49g!\P!\ 4'd\P!\ 4MR R
R \P!49g\P!V4'd\P!V4MR R \P!V4R
\P!V4/,p RRV /,p
\\P!V
44hR;p;r‡V^,q»PqfV8Hqˆ'gÇ\P!RV3RWa34R
\P!V 4R \P!V4RR\P!49g\P!V4'd\P!V4MR/,p RRV /,p
\\P!V
44hR;p ;rh\ P"!V4R# +'giELi;i \ P"!X4i;i)z0Test loading a text file with Unicode charactersu2测试中文内容
Test Unicode: 你好世界 ðŸŒ�rJFrKr_r`Nrrer‡rˆrcrr‰rŠr.rr/r0rrŽr�)rQrRrSrTrrVrerrrrrr r!r"rrWrX)r#rrYrZr[rˆrnr”r2r'r•r–r3r4s& r(Ú test_load_text_file_with_unicodeÚ/TestTextLoader.test_load_text_file_with_unicodeŠs�€àGˆÜ
×
(Ò
(¨c¸%ÈÐY`×
aÕ
aÐefØ
�G‰G�GÔ ØŸ™ˆI÷bð !Ü  Ó*ˆFØ—;‘;“=ˆDä�t“9Ð ! Ð ! ‘>× !× !× !Ô !�9× !× !× !× !× !× !”3× !× !× !Ò !”3× !× !× !× !× !× !Ð !�t× !× !× !Ò !�t× !× !Ö !�9× !× !Ô ! × !× !× !× !× !× !× !Ò !ؘ•7Ð 2×'Ñ'Ð 2¨7Ñ2× 2× 2× 2Ó 2Ð'× 2× 2Õ 2�7× 2× 2Ô 2Ð'× 2× 2× 2× 2× 2Ö 2¨7× 2× 2× 2Ò 2¨7× 2× 2× 2× 2× 2× 2× 2Ô 2ä �IŠI�iÖ ÷b×
aÐ
aûô
�IŠI�iÕ ús-¥J#Á BJ7ÃAJ7Ä'DJ7È=AJ7Ê# J4 Ê7Kc
 ón€RR,pVP!\R4!p\P!RRRRR7;_uu_4pVP V4VP
pRRR4\
X4pVP4p\V4p^qvV8Hqˆ'Eg\P!RV3RWg34R R
\P!49g!\P!\4'd\P!\4MR
R R \P!49g\P!V4'd\P!V4MR R
\P!V4R\P!V4/,p RRV /,p
\\P !V
44hR;p;r‡V^,q»P"p \V 4pRq×V
8„qî'gû\P!RV3RW}34R R
\P!49g!\P!\4'd\P!\4MR
R\P!V 4R\P!V 4R\P!V4R\P!V
4/,pRRV/,p\\P !V44hR;p ;p ;p;rí\$P&!V4R# +'giEL®;i \$P&!X4i;i)zTest loading a large text filezLine {}
i'rJFrKr_r`Nrrer‡rˆrcrr‰rŠiPÃrrrfzassert %(py11)srgrrŽri)zQ%(py6)s
{%(py6)s = %(py0)s(%(py4)s
{%(py4)s = %(py2)s.page_content