source: trunk/src/allmydata/test/test_protocol_switch.py

Last change on this file was d4c73f1, checked in by Itamar Turner-Trauring <itamar@…>, at 2022-07-29T14:42:56Z

A unittest for the metaclass.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1"""
2Unit tests for ``allmydata.protocol_switch``.
3
4By its nature, most of the testing needs to be end-to-end; essentially any test
5that uses real Foolscap (``test_system.py``, integration tests) ensures
6Foolscap still works.  ``test_istorageserver.py`` tests the HTTP support.
7"""
8
9from foolscap.negotiate import Negotiation
10
11from .common import TestCase
12from ..protocol_switch import _PretendToBeNegotiation
13
14
15class UtilityTests(TestCase):
16    """Tests for utilities in the protocol switch code."""
17
18    def test_metaclass(self):
19        """
20        A class that has the ``_PretendToBeNegotiation`` metaclass will support
21        ``isinstance()``'s normal semantics on its own instances, but will also
22        indicate that ``Negotiation`` instances are its instances.
23        """
24
25        class Parent(metaclass=_PretendToBeNegotiation):
26            pass
27
28        class Child(Parent):
29            pass
30
31        class Other:
32            pass
33
34        p = Parent()
35        self.assertIsInstance(p, Parent)
36        self.assertIsInstance(Negotiation(), Parent)
37        self.assertNotIsInstance(Other(), Parent)
38
39        c = Child()
40        self.assertIsInstance(c, Child)
41        self.assertIsInstance(c, Parent)
42        self.assertIsInstance(Negotiation(), Child)
43        self.assertNotIsInstance(Other(), Child)
Note: See TracBrowser for help on using the repository browser.