diff options
author | Paul Vinciguerra <pvinci@vinciconsulting.com> | 2020-12-01 02:00:35 -0500 |
---|---|---|
committer | Ole Tr�an <otroan@employees.org> | 2020-12-02 10:11:38 +0000 |
commit | 46d6864b9de6d722c4b6eb72d231918b251e267d (patch) | |
tree | da7ee42cf062779f0a0958ec90121551ad729b12 /src/vpp-api/python/vpp_papi/tests | |
parent | 41f15ae1dfd4ac1777b684fdc763d12496209418 (diff) |
papi: improve unit testability
refactor the code so that snippets of json can be used to test vpp_papi
example unit test provided
Type: improvement
Change-Id: Ibec608fd2e5b12515aa4db17d85d4319134c22ea
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'src/vpp-api/python/vpp_papi/tests')
-rw-r--r-- | src/vpp-api/python/vpp_papi/tests/test_vpp_papi.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/vpp-api/python/vpp_papi/tests/test_vpp_papi.py b/src/vpp-api/python/vpp_papi/tests/test_vpp_papi.py index 774b4e1092c..d0c72497bd0 100644 --- a/src/vpp-api/python/vpp_papi/tests/test_vpp_papi.py +++ b/src/vpp-api/python/vpp_papi/tests/test_vpp_papi.py @@ -14,8 +14,12 @@ import ctypes import multiprocessing as mp +import sys import unittest +from unittest import mock + from vpp_papi import vpp_papi +from vpp_papi import vpp_transport_shmem class TestVppPapiVPPApiClient(unittest.TestCase): @@ -51,3 +55,62 @@ class TestVppPapiVPPApiClientMp(unittest.TestCase): # AssertionError: 11 != 1 self.assertEqual(11, c.get_context()) + +class TestVppTypes(unittest.TestCase): + + def test_enum_from_json(self): + json_api = """\ +{ + "enums": [ + + [ + "address_family", + [ + "ADDRESS_IP4", + 0 + ], + [ + "ADDRESS_IP6", + 1 + ], + { + "enumtype": "u8" + } + ], + [ + "if_type", + [ + "IF_API_TYPE_HARDWARE", + 0 + ], + [ + "IF_API_TYPE_SUB", + 1 + ], + [ + "IF_API_TYPE_P2P", + 2 + ], + [ + "IF_API_TYPE_PIPE", + 3 + ], + { + "enumtype": "u32" + } + ] + ] +} +""" + processor = vpp_papi.VPPApiJSONFiles() + + # add the types to vpp_serializer + processor.process_json_str(json_api) + + vpp_transport_shmem.VppTransport = mock.MagicMock() + ac = vpp_papi.VPPApiClient(apifiles=[], testmode=True) + type_name = "vl_api_if_type_t" + t = ac.get_type(type_name) + self.assertTrue(str(t).startswith("VPPEnumType")) + self.assertEqual(t.name, type_name) + |