diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index de7dd0b0..9171d76e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -96,9 +96,11 @@ jobs: - name: Setup castxml config if: matrix.compiler == 'gcc' && matrix.version == '9' run: mv unittests/configs/gcc9.cfg unittests/xml_generator.cfg; - - name: Run tests + - name: Run legacy tests run: | export PATH=~/castxml/bin:$PATH coverage run -m unittests.test_all coverage combine coverage xml + - name: Run tests + run: pytest tests diff --git a/pyproject.toml b/pyproject.toml index de3e3f10..387df727 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,7 @@ test = [ "coverage", "coveralls", "pycodestyle", + "pytest", ] docs = [ "sphinx", diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 00000000..0694ebd2 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,61 @@ +# Copyright 2014-2017 Insight Software Consortium. +# Copyright 2004-2009 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. +# See http://www.boost.org/LICENSE_1_0.txt + +import sys +import os +import unittest +import pytest + +from pygccxml import parser +from pygccxml import utils + + +def test_config(): + """Test config setup with wrong xml generator setups.""" + + # Some code to parse for the example + code = "int a;" + + # Find the location of the xml generator (castxml or gccxml) + generator_path, name = utils.find_xml_generator() + + # No xml generator path + config = parser.xml_generator_configuration_t(xml_generator=name) + with pytest.raises(RuntimeError): + parser.parse_string(code, config) + + # Invalid path + config = parser.xml_generator_configuration_t( + xml_generator_path="wrong/path", + xml_generator=name) + with pytest.raises(RuntimeError): + parser.parse_string(code, config) + + # None path + config = parser.xml_generator_configuration_t( + xml_generator_path=None, + xml_generator=name) + with pytest.raises(RuntimeError): + parser.parse_string(code, config) + + # No name + config = parser.xml_generator_configuration_t( + xml_generator_path=generator_path) + with pytest.raises(RuntimeError): + parser.parse_string(code, config) + + # Random name + config = parser.xml_generator_configuration_t( + xml_generator_path=generator_path, + xml_generator="not_a_generator") + with pytest.raises(RuntimeError): + parser.parse_string(code, config) + + # None name + config = parser.xml_generator_configuration_t( + xml_generator_path=generator_path, + xml_generator=None) + with pytest.raises(RuntimeError): + parser.parse_string(code, config) diff --git a/unittests/test_all.py b/unittests/test_all.py index cd3408ac..4ae4c66c 100644 --- a/unittests/test_all.py +++ b/unittests/test_all.py @@ -72,7 +72,6 @@ from . import test_pattern_parser from . import test_function_pointer from . import test_directory_cache -from . import test_config from . import deprecation_tester from . import test_xml_generators from . import test_non_copyable_recursive @@ -141,7 +140,6 @@ test_pattern_parser, test_function_pointer, test_directory_cache, - test_config, test_utils, test_cpp_standards, test_va_list_tag_removal, diff --git a/unittests/test_config.py b/unittests/test_config.py deleted file mode 100644 index b703d5cd..00000000 --- a/unittests/test_config.py +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright 2014-2017 Insight Software Consortium. -# Copyright 2004-2009 Roman Yakovenko. -# Distributed under the Boost Software License, Version 1.0. -# See http://www.boost.org/LICENSE_1_0.txt - -import sys -import os -import unittest - -sys.path.insert(1, os.path.join(os.curdir, '..')) -sys.path.insert(1, "../pygccxml") - -from pygccxml import parser # nopep8 -from pygccxml import utils # nopep8 - - -class Test(unittest.TestCase): - - def test_config(self): - """Test config setup with wrong xml generator setups.""" - - # Some code to parse for the example - code = "int a;" - - # Find the location of the xml generator (castxml or gccxml) - generator_path, name = utils.find_xml_generator() - - # No xml generator path - config = parser.xml_generator_configuration_t(xml_generator=name) - self.assertRaises( - RuntimeError, lambda: parser.parse_string(code, config)) - - # Invalid path - config = parser.xml_generator_configuration_t( - xml_generator_path="wrong/path", - xml_generator=name) - self.assertRaises( - RuntimeError, lambda: parser.parse_string(code, config)) - - # None path - config = parser.xml_generator_configuration_t( - xml_generator_path=None, - xml_generator=name) - self.assertRaises( - RuntimeError, lambda: parser.parse_string(code, config)) - - # No name - config = parser.xml_generator_configuration_t( - xml_generator_path=generator_path) - self.assertRaises( - RuntimeError, lambda: parser.parse_string(code, config)) - - # Random name - config = parser.xml_generator_configuration_t( - xml_generator_path=generator_path, - xml_generator="not_a_generator") - self.assertRaises( - RuntimeError, lambda: parser.parse_string(code, config)) - - # None name - config = parser.xml_generator_configuration_t( - xml_generator_path=generator_path, - xml_generator=None) - self.assertRaises( - RuntimeError, lambda: parser.parse_string(code, config)) - - -def create_suite(): - suite = unittest.TestSuite() - suite.addTest( - unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test)) - return suite - - -def run_suite(): - unittest.TextTestRunner(verbosity=2).run(create_suite()) - - -if __name__ == "__main__": - run_suite()