File: test_error_msg.py

package info (click to toggle)
python-openflow 2021.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,224 kB
  • sloc: python: 6,906; sh: 4; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 1,319 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
35
36
"""Testing v0x04 error message class."""
from pyof.foundation.exceptions import MethodNotImplemented
from pyof.v0x04.asynchronous.error_msg import (
    ErrorExperimenterMsg, ErrorMsg, ErrorType, MeterModFailedCode)
from tests.unit.test_struct import TestStruct


class TestErrorMsg(TestStruct):
    """ErroMsg message tests (also those in :class:`.TestDump`)."""

    @classmethod
    def setUpClass(cls):
        """Configure raw file and its object in parent class (TestDump)."""
        error_type = ErrorType.OFPET_METER_MOD_FAILED
        code = MeterModFailedCode.OFPMMFC_UNKNOWN_METER
        super().setUpClass()
        super().set_raw_dump_file('v0x04', 'ofpt_error')
        super().set_raw_dump_object(ErrorMsg, xid=1, error_type=error_type,
                                    code=code, data=_get_data())
        super().set_minimum_size(12)

    @staticmethod
    def test_unpack():
        """[Asynchronous/error_msg] - unpack ErrorExperimenterMsg."""
        unpacked = ErrorExperimenterMsg()
        try:
            unpacked.unpack("pack")
        except MethodNotImplemented:
            pass


def _get_data():
    """Return data for ErrorMsg object."""
    data = b'\x04\x12\x00\x18\x00\x00\x00\x01\x00\x0a\x00\x00\x00\x00\x00'
    data += b'\x00\x00\x00\x00\x01\x00\x00\x00\x00'
    return data