B pSeH@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}|dk rt|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)rootrH/opt/alt/python37/lib/python3.7/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..zutf-8) _root descendant subprocess check_outputsys executablepathrloadsdecodeitems)selfrrrrr_remotes,s zSuite._remotescCs&x tD]}|j|dj|dqWdS)N)r)runner)rversion benchmark)r'r)rrrrr+6s zSuite.benchmarkcCst||jd|g|dS)Ntests)rr#r)Versionrrr()r'rrrrr*:sz Suite.versionN) __name__ __module__ __qualname__attribZFactoryrrr(r+r*rrrrr's rc@s\eZdZeZeZeZddZddZ ddZ ddZ d d Z d d Z d dZdS)r-cKs<x6|D]*}x$|D]}||jt|jf|qWq WdS)N)r,Z bench_funcfully_qualified_namervalidate_ignoring_errors)r'r)kwargssuitetestrrrr+Js  zVersion.benchmarkcsfddjdDS)Nc3s2|]*}j|dd|dD] }|Vq qdS)N)subjectr#) _tests_inbasename)rchildr7)r'rr Tsz Version.tests..z*.json)_path globChildren)r'r)r'rr,Rs z Version.testscs(jddg}fdd|dDS)Noptionalformatc3s2|]*}j|dd|dD] }|Vq qdS)Nr8)r9r#)r:r;)rr<r7)r'rrr=_sz'Version.format_tests..z*.json)r>rr?)r'r#r)r'r format_tests\s zVersion.format_testscCs|j||j|ddS)Nz.json)r9r#)r:r>r<)r'rrrrtests_ofgszVersion.tests_ofcCs|j||jd|dgdS)Nr@z.json)r9r#)r:r>r)r'rrrroptional_tests_ofmszVersion.optional_tests_ofcs^dd|j}fdd|D}t|tjf|}y t|_Wntk rXYnX|S)NrZTestcs0i|](}|D]}|D]}|jf|jqq qSr)to_unittest_method method_name)rr6r,r7)r5rrrusz0Version.to_unittest_testcase..) poprtitletypeunittestZTestCase)_someone_save_us_the_module_of_the_callerr/ Exception)r'Zsuitesr5rmethodsclsr)r5rto_unittest_testcasess  zVersion.to_unittest_testcasec#s>x8t|dD] fdddDVqWdS)Nzutf-8c 3s2|]*}tfddjd|VqdS) descriptionr)r*r9case_descriptionrrN)_Testr()rr7)eachr'r9rrr=sz$Version._tests_in..r,)rr$Z getContentr%)r'r9r#r)rSr'r9rr:szVersion._tests_inN)r.r/r0r1r2r>r(rr+r,rBrCrDrOr:rrrrr-Bs  r-F)rreprc@seZdZeZeZeZeZeZ ejddZ eZ eZ ddZ eddZeddZd d fd d Zd dZddZdS)rRF)rTcCs d|jS)Nz )rAr3)r'rrr__repr__sz_Test.__repr__cCsd|jj|j|j|jgS)Nz > )joinr*rr9rQrP)r'rrrr3s z_Test.fully_qualified_namecCsHd}dt|d|jt|d|jt|d|jf}tsD|d}|S)Nz[\W\- ]+z test_%s_%s_%s_zutf-8)resubr9rQrPrencode)r' delimitersrrrrrFs z_Test.method_namecCsdS)Nr)r7rrrz_Test.c sHjrfdd}nfdd}j|_|}t|dk ||S)NcsjfdS)N)validate)this)r5r'rrfnsz$_Test.to_unittest_method..fnc s(|tjjfWdQRXdS)N)Z assertRaisesr ValidationErrorr^)r_)r5r'rrr`s)validrFr.rJZskipIf)r'skipr5r`reasonr)r5r'rrEs z_Test.to_unittest_methodcKs:tjj|j|j|jd}tjf|j|j||d|dS)N)rstoreZid_of)instancerrNresolver)r Z RefResolverZ from_schemarr(ZID_OFr^data)r' Validatorr5rgrrrr^s z_Test.validatecCs,y|j|dWntjk r&YnXdS)N)ri)r^r ra)r'rirrrr4sz_Test.validate_ignoring_errorsN)r.r/r0r1r2r*r9rQrPrhrrbr(rUpropertyr3rFrEr^r4rrrrrRs   rRcCstdjdS)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_globalsrrrrrKs rK)__doc__ functoolsrrrrXrr!rJZtwisted.python.filepathrr1Zjsonschema.compatrZjsonschema.validatorsrr rsobjectrr-rRrKrrrrs(    RL