test_parser.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2014-2015 UAVCAN Development Team <uavcan.org>
3 #
4 # This software is distributed under the terms of the MIT License.
5 #
6 # Author: Ben Dyer <ben_dyer@mac.com>
7 # Pavel Kirienko <pavel.kirienko@zubax.com>
8 #
9 
10 import os
11 import unittest
12 from pyuavcan_v0.dsdl import parser
13 from pyuavcan_v0.dsdl import parser, parse_namespaces
14 from pyuavcan_v0.dsdl.common import DsdlException
15 
16 
17 class TestParseNamespaces(unittest.TestCase):
18  '''
19  Unittests of parse_namespaces function.
20  '''
21 
22  def test_builtin(self):
23  '''
24  Test the ability to load all the UAVCAN v0 messages
25  '''
26  built_in_dir = '{}/../../pyuavcan_v0/dsdl_files/uavcan'.format(os.path.dirname(__file__))
27  parse_namespaces([built_in_dir])
28 
30  '''
31  Validate the parser allows and handles duplicate definitions in the search dir
32  '''
33  ns0_dir = '{}/fake_dsdl/ns0_base/ns0'.format(os.path.dirname(__file__))
34  ns0_dir_with_duplicate = '{}/fake_dsdl/ns0_duplicated/ns0'.format(os.path.dirname(__file__))
35 
36  parse_namespaces([ns0_dir], [ns0_dir_with_duplicate])
37 
39  '''
40  Validate the parser does not allow redefinitions in the search dir
41  '''
42  ns0_dir = '{}/fake_dsdl/ns0_base/ns0'.format(os.path.dirname(__file__))
43  ns0_dir_with_redefinition = '{}/fake_dsdl/ns0_redefined/ns0'.format(os.path.dirname(__file__))
44  try:
45  parse_namespaces([ns0_dir], [ns0_dir_with_redefinition])
46  self.assertTrue(False) # parse_namespaces should raise an exception, shouldn't get here
47  except DsdlException as e:
48  self.assertTrue(e.args[0].startswith("Redefinition of data type ID"))
49 
50 
51 if __name__ == '__main__':
52  unittest.main()
dsdl.test_parser.TestParseNamespaces
Definition: test_parser.py:17
pyuavcan_v0.dsdl.parser.parse_namespaces
def parse_namespaces(source_dirs, search_dirs=None)
Definition: parser.py:808
dsdl.test_parser.TestParseNamespaces.test_builtin
def test_builtin(self)
Definition: test_parser.py:22
dsdl.test_parser.TestParseNamespaces.test_duplicate_in_search_dir
def test_duplicate_in_search_dir(self)
Definition: test_parser.py:29
dsdl.test_parser.TestParseNamespaces.test_redefinition_in_search_dir
def test_redefinition_in_search_dir(self)
Definition: test_parser.py:38
pyuavcan_v0.dsdl
Definition: pyuavcan/pyuavcan_v0/dsdl/__init__.py:1
pyuavcan_v0.dsdl.common
Definition: dsdl/common.py:1
test.format
format
Definition: dsdl/test.py:6


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:03