|
| 1 | +# Copyright 2021 Insight Software Consortium. |
| 2 | +# Distributed under the Boost Software License, Version 1.0. |
| 3 | +# See http://www.boost.org/LICENSE_1_0.txt |
| 4 | + |
| 5 | +import unittest |
| 6 | + |
| 7 | +from . import parser_test_case |
| 8 | + |
| 9 | +from pygccxml import parser |
| 10 | +from pygccxml import declarations |
| 11 | + |
| 12 | + |
| 13 | +class Test(parser_test_case.parser_test_case_t): |
| 14 | + global_ns = None |
| 15 | + |
| 16 | + def __init__(self, *args): |
| 17 | + parser_test_case.parser_test_case_t.__init__(self, *args) |
| 18 | + self.header = "test_deprecation.hpp" |
| 19 | + self.global_ns = None |
| 20 | + self.config.castxml_epic_version = 1 |
| 21 | + |
| 22 | + def _check_text_content(self, desired_text, deprecation_string): |
| 23 | + if deprecation_string: |
| 24 | + self.assertEqual(desired_text, deprecation_string) |
| 25 | + else: |
| 26 | + print("No text in deprecation attribute to check") |
| 27 | + |
| 28 | + def setUp(self): |
| 29 | + if not self.global_ns: |
| 30 | + decls = parser.parse([self.header], self.config) |
| 31 | + Test.global_ns = declarations.get_global_namespace(decls) |
| 32 | + Test.xml_generator_from_xml_file = \ |
| 33 | + self.config.xml_generator_from_xml_file |
| 34 | + self.xml_generator_from_xml_file = Test.xml_generator_from_xml_file |
| 35 | + |
| 36 | + self.global_ns = Test.global_ns |
| 37 | + |
| 38 | + def test(self): |
| 39 | + """ |
| 40 | + Check the comment parsing |
| 41 | + """ |
| 42 | + |
| 43 | + if self.config.castxml_epic_version != 1: |
| 44 | + # Run this test only with castxml epic version == 1 |
| 45 | + return |
| 46 | + tnamespace = self.global_ns.namespace("deprecation") |
| 47 | + |
| 48 | + tenumeration = tnamespace.enumeration("com_enum") |
| 49 | + self.assertIn("deprecation", dir(tenumeration)) |
| 50 | + self._check_text_content('Enumeration is Deprecated', |
| 51 | + tenumeration.deprecation) |
| 52 | + |
| 53 | + tclass = tnamespace.class_("test") |
| 54 | + self.assertIn("deprecation", dir(tclass)) |
| 55 | + self._check_text_content("Test class Deprecated", tclass.deprecation) |
| 56 | + |
| 57 | + tmethod = tclass.member_functions()[0] |
| 58 | + tmethod_dep = tclass.member_functions()[1] |
| 59 | + |
| 60 | + self.assertIn("deprecation", dir(tmethod)) |
| 61 | + self.assertIsNone(tmethod.deprecation) |
| 62 | + self._check_text_content("Function is deprecated", |
| 63 | + tmethod_dep.deprecation) |
| 64 | + |
| 65 | + tconstructor = tclass.constructors()[0] |
| 66 | + tconstructor_dep = tclass.constructors()[1] |
| 67 | + |
| 68 | + self.assertIsNone(tconstructor.deprecation) |
| 69 | + self.assertIn("deprecation", dir(tconstructor_dep)) |
| 70 | + self._check_text_content("One arg constructor is Deprecated", |
| 71 | + tconstructor_dep.deprecation) |
| 72 | + |
| 73 | + |
| 74 | +def create_suite(): |
| 75 | + suite = unittest.TestSuite() |
| 76 | + suite.addTest(unittest.makeSuite(Test)) |
| 77 | + return suite |
| 78 | + |
| 79 | + |
| 80 | +def run_suite(): |
| 81 | + unittest.TextTestRunner(verbosity=2).run(create_suite()) |
| 82 | + |
| 83 | + |
| 84 | +if __name__ == "__main__": |
| 85 | + run_suite() |
0 commit comments