File: test_base.py

package info (click to toggle)
python-openflow 1.1.0~alpha2-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 692 kB
  • ctags: 1,027
  • sloc: python: 2,713; makefile: 207; sh: 8
file content (43 lines) | stat: -rw-r--r-- 1,401 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
37
38
39
40
41
42
43
import unittest

from pyof.v0x01.foundation import base
from pyof.v0x01.foundation import basic_types


class TestGenericStruct(unittest.TestCase):

    def setUp(self):
        class AttributeA(base.GenericStruct):
            a1 = basic_types.UBInt8(1)
            a2 = basic_types.UBInt16(2)

        class AttributeC(base.GenericStruct):
            c1 = basic_types.UBInt32(3)
            c2 = basic_types.UBInt64(4)

        class AttributeB(base.GenericStruct):
            c = AttributeC()

        class MyMessage(base.GenericMessage):
            a = AttributeA()
            b = AttributeB()
            i = basic_types.UBInt32(5)

            def __init__(self):
                super().__init__(None)

        self.MyMessage = MyMessage

    def test_basic_attributes(self):
        """[Foundation/Base/GenericStruct] - Attributes Creation"""
        message1 = self.MyMessage()
        message2 = self.MyMessage()
        self.assertIsNot(message1, message2)
        self.assertIsNot(message1.i, message2.i)
        self.assertIsNot(message1.a, message2.a)
        self.assertIsNot(message1.b, message2.b)
        self.assertIsNot(message1.a.a1, message2.a.a1)
        self.assertIsNot(message1.a.a2, message2.a.a2)
        self.assertIsNot(message1.b.c, message2.b.c)
        self.assertIsNot(message1.b.c.c1, message2.b.c.c1)
        self.assertIsNot(message1.b.c.c2, message2.b.c.c2)