def test_encode(self):
        """
        L{dns._OPTVariableOption.encode} encodes the code and data
        instance attributes to a byte string which also includes the
        data length.
        """
        o = dns._OPTVariableOption(1, b'foobar')
        b = BytesIO()
        o.encode(b)
        self.assertEqual(
            b.getvalue(),
            b'\x00\x01' # OPTION-CODE 1
            b'\x00\x06' # OPTION-LENGTH 6
            b'foobar' # OPTION-DATA
            )

        L{dns._OPTVariableOption.encode} encodes the code and data
        instance attributes to a byte string which also includes the
        data length.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/names/test/test_dns.py