MCPcopy Create free account
hub / github.com/python-hyper/uritemplate / __new__

Method __new__

tests/test_uritemplate.py:378–404  ·  view source on GitHub ↗
(
        cls, name: str, bases: t.Sequence[t.Any], attrs: t.Dict[str, t.Any]
    )

Source from the content-addressed store, hash-verified

376 }
377
378 def __new__(
379 cls, name: str, bases: t.Sequence[t.Any], attrs: t.Dict[str, t.Any]
380 ) -> t.Any:
381 def make_test(
382 d: t.Dict[str, ExampleWithVariables],
383 ) -> collections.abc.Callable[["unittest.TestCase"], None]:
384 def _test_(self: "unittest.TestCase") -> None:
385 for k, v in d.items():
386 with self.subTest(template=k, **v):
387 t = URITemplate(k)
388 self.assertEqual(
389 t.expand(v["expansion"]), v["expected"]
390 )
391
392 return _test_
393
394 examples = [
395 (n, getattr(RFCTemplateExamples, n))
396 for n in dir(RFCTemplateExamples)
397 if n.startswith("level")
398 ]
399
400 for name, value in examples:
401 testname = "test_%s" % name
402 attrs[testname] = make_test(value)
403
404 return type.__new__(cls, name, bases, attrs) # type: ignore
405
406
407class TestURITemplate(unittest.TestCase, metaclass=RFCTemplateExamples):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected