def test_unittest_main(self) -> None: """ Tests whether `unittest_main` is called when `__name__ == '__main__'` """ self.assertEqual(type(unittest_main).__name__, "function") self.assertIsNone(unittest_main()) argparse_mock = MagicMock() with patch( "ml_params_tensorflow.tests.utils_for_tests.__name__", "__main__"), patch( "sys.stderr", new_callable=StringIO), self.assertRaises(SystemExit) as e: import ml_params_tensorflow.tests.utils_for_tests ml_params_tensorflow.tests.utils_for_tests.unittest_main() self.assertIsInstance(e.exception.code, bool) self.assertIsNone(argparse_mock.call_args) self.assertIsNone( ml_params_tensorflow.tests.utils_for_tests.unittest_main())
""" Tests for CLI parsers """ from argparse import ArgumentParser from unittest import TestCase from ml_params_tensorflow.ml_params.cli import ( load_data_parser, load_model_parser, train_parser, ) from ml_params_tensorflow.tests.utils_for_tests import unittest_main class TestCli(TestCase): """ Tests whether cli parsers return the right thing """ def test_parsers(self) -> None: """ Tests whether the CLI parsers return a collection with first element being `ArgumentParser` """ for parser in train_parser, load_data_parser, load_model_parser: self.assertIsInstance( parser(argument_parser=ArgumentParser())[0], ArgumentParser) unittest_main()