MCPcopy
hub / github.com/pallets/werkzeug / test_proxy_attributes

Function test_proxy_attributes

tests/test_local.py:513–551  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

511
512
513def test_proxy_attributes():
514 class Example:
515 def __init__(self):
516 object.__setattr__(self, "values", {})
517
518 def __getattribute__(self, name):
519 if name == "ham":
520 return "eggs"
521
522 return super().__getattribute__(name)
523
524 def __getattr__(self, name):
525 return self.values.get(name)
526
527 def __setattr__(self, name, value):
528 self.values[name] = value
529
530 def __delattr__(self, name):
531 del self.values[name]
532
533 def __dir__(self):
534 return sorted(self.values.keys())
535
536 _, p = _make_proxy(Example())
537 assert p.nothing is None
538 assert p.__dict__ == {"values": {}}
539 assert dir(p) == []
540
541 p.x = 1
542 assert p.x == 1
543 assert dir(p) == ["x"]
544
545 del p.x
546 assert dir(p) == []
547
548 assert p.ham == "eggs"
549 p.ham = "spam"
550 assert p.ham == "eggs"
551 assert p.values["ham"] == "spam"
552
553
554def test_proxy_await():

Callers

nothing calls this directly

Calls 2

_make_proxyFunction · 0.85
ExampleClass · 0.85

Tested by

no test coverage detected