File: test_error.py

package info (click to toggle)
python-varlink 32.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 328 kB
  • sloc: python: 2,705; sh: 177; makefile: 29
file content (34 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import json
import unittest

import varlink


class OneMessageClientHandler(varlink.ClientInterfaceHandler):
    def __init__(self, interface, namespaced, next_message):
        # No interface but we do not use them
        super().__init__(interface, namespaced)
        self.next_message = next_message

    def _next_message(self):
        yield self.next_message


class TestError(unittest.TestCase):
    def test_pack_unpack(self):
        dummy_if = varlink.Interface("interface org.example.dummy")
        for error in [
            varlink.InterfaceNotFound("org.varlink.notfound"),
            varlink.MethodNotFound("Method"),
            varlink.MethodNotImplemented("Abstract"),
            varlink.InvalidParameter("Struct.param"),
        ]:
            for namespaced in (True, False):
                with self.subTest(error=error, namespaced=namespaced):
                    # encode error
                    encoded = json.dumps(error, cls=varlink.VarlinkEncoder)

                    # Emulates the client receiving an error
                    handler = OneMessageClientHandler(dummy_if, namespaced, encoded)
                    with self.assertRaises(error.__class__):
                        handler._next_varlink_message()