a 5q]H@sdZddlmZddlZddlZddlZddlZddlZddlZddl m Z ddl Z ddl m Z ddlmZddlZddZe jd d Gd d d eZe jd d Gd ddeZe jd ddGdddeZddZdS)z= Python representations of the JSON Schema Test Suite tests. )partialN)FilePath)PY3) validatorscCsDtjd}|durt|Sttjd}|s@t d|S)NZJSON_SCHEMA_TEST_SUITEjsonzCan't find the JSON-Schema-Test-Suite directory. Set the 'JSON_SCHEMA_TEST_SUITE' environment variable or run the tests from alongside a checkout of the suite.) osenvirongetr jsonschema__file__parentZsiblingisdir ValueError)rootr;/usr/lib/python3.9/site-packages/jsonschema/tests/_suite.py _find_suites rT)hashc@s6eZdZejeedZddZddZ ddZ dS) Suite)defaultcCsB|jddg}ttj|jdg}ddt| d DS)Nbinjsonschema_suiteremotescSsi|]\}}d||qS)zhttp://localhost:1234/r).0nameschemarrr 1sz"Suite._remotes..utf-8) _root descendant subprocessZ check_outputsys executablepathrloadsdecodeitems)selfrrrrr_remotes,s zSuite._remotescCs"tD]}|j|dj|dqdS)N)r)runner)rversion benchmark)r'r)rrrrr+6szSuite.benchmarkcCst||jd|g|dS)Ntests)rr#r)Versionrrr(r'rrrrr*:s z Suite.versionN) __name__ __module__ __qualname__attribZFactoryrrr(r+r*rrrrr's rc@s\eZdZeZeZeZddZddZ ddZ ddZ d d Z d d Z d dZdS)r-c Ks8|D]*}|D] }||jt|jfi|qqdSN)r,Z bench_funcfully_qualified_namervalidate_ignoring_errors)r'r)kwargssuitetestrrrr+Js  zVersion.benchmarkcsfddjdDS)Nc3s2|]*}j|dd|dD] }|Vq qdSNsubjectr# _tests_inbasenamerchildr9r'rr Ss  z Version.tests..*.json)_path globChildrenrCrrCrr,Rs  z Version.testscs(jddg}fdd|dDS)Noptionalformatc3s2|]*}j|dd|dD] }|Vq qdSr:r>rArCrrrD^s  z'Version.format_tests..rE)rFrrG)r'r#rrCr format_tests\s zVersion.format_testscCs|j||j|ddS)N.jsonr<)r?rFrBr.rrrtests_ofgszVersion.tests_ofcCs|j||jd|dgdS)NrHrKr<)r?rFrr.rrroptional_tests_ofmszVersion.optional_tests_ofcs\dd|j}fdd|D}t|tjf|}z t|_WntyVYn0|S)NrZTestc s4i|],}|D]"}|D]}|j|jfiqq qSr) method_nameto_unittest_method)rr8r,r9r7rrrusz0Version.to_unittest_testcase..) poprtitletypeunittestZTestCase)_someone_save_us_the_module_of_the_callerr0 Exception)r'Zsuitesr7rmethodsclsrrPrto_unittest_testcasess   zVersion.to_unittest_testcasec#s:t|dD] fdddDVqdS)Nrc 3s2|]*}tfddjd|VqdS) descriptionr)r*r=case_descriptionrrN)_Testr()rr9Zeachr'r=rrrDsz$Version._tests_in..r,)rr$Z getContentr%)r'r=r#rr]rr?szVersion._tests_inN)r/r0r1r2r3rFr(rr+r,rJrLrMrYr?rrrrr-Bs  r-F)rreprc@seZdZeZeZeZeZeZ ejddZ eZ eZ ddZ eddZeddZd d fd d Zd dZddZdS)r\F)r^cCs d|jS)Nz )rIr5rCrrr__repr__sz_Test.__repr__cCsd|jj|j|j|jgS)Nz > )joinr*rr=r[rZrCrrrr5sz_Test.fully_qualified_namecCsHd}dt|d|jt|d|jt|d|jf}tsD|d}|S)Nz[\W\- ]+z test_%s_%s_%s_r)resubr=r[rZrencode)r'Z delimitersrrrrrNs z_Test.method_namecCsdSr4r)r9rrrz_Test.c sHjrfdd}nfdd}j|_|}t|du||S)NcsjfidSr4)validatethisr7r'rrfnsz$_Test.to_unittest_method..fncs@|tj jfiWdn1s20YdSr4)Z assertRaisesr ValidationErrorrgrhrjrrrks)validrNr/rTZskipIf)r'skipr7rkreasonrrjrrOs z_Test.to_unittest_methodcKs:tjj|j|j|jd}tjf|j|j||d|dS)N)rstoreZid_of)instancerrXresolver)r Z RefResolverZ from_schemarr(ZID_OFrgdata)r' Validatorr7rrrrrrgsz_Test.validatecCs*z|j|dWntjy$Yn0dS)N)rt)rgr rl)r'rtrrrr6sz_Test.validate_ignoring_errorsN)r/r0r1r2r3r*r=r[rZrsrrmr(r_propertyr5rNrOrgr6rrrrr\s     r\cCstdjdS)a The FQON of the module 2nd stack frames up from here. This is intended to allow us to dynamicallly return test case classes that are indistinguishable from being defined in the module that wants them. Otherwise, trial will mis-print the FQON, and copy pasting it won't re-run the class that really is running. Save us all, this is all so so so so so terrible. r/)r! _getframe f_globalsrrrrrUs rU)__doc__ functoolsrrrrbr r!rTZtwisted.python.filepathrr2Zjsonschema.compatrZjsonschema.validatorsrr rsobjectrr-r\rUrrrrs(      R L