Line | |
---|
1 | """ |
---|
2 | Unit tests for ``allmydata.protocol_switch``. |
---|
3 | |
---|
4 | By its nature, most of the testing needs to be end-to-end; essentially any test |
---|
5 | that uses real Foolscap (``test_system.py``, integration tests) ensures |
---|
6 | Foolscap still works. ``test_istorageserver.py`` tests the HTTP support. |
---|
7 | """ |
---|
8 | |
---|
9 | from foolscap.negotiate import Negotiation |
---|
10 | |
---|
11 | from .common import TestCase |
---|
12 | from ..protocol_switch import _PretendToBeNegotiation |
---|
13 | |
---|
14 | |
---|
15 | class 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.