From bf1cf2b1edf107a0ad08e2a350f8db504355dd3b Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 1 Feb 2024 17:34:04 +0100 Subject: [PATCH] Adding test for BaseDPXApplication. --- test/test_10_base_app.py | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100755 test/test_10_base_app.py diff --git a/test/test_10_base_app.py b/test/test_10_base_app.py new file mode 100755 index 0000000..67c2ae4 --- /dev/null +++ b/test/test_10_base_app.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +''' +@author: Frank Brehm +@contact: frank.brehm@pixelpark.com +@copyright: © 2024 by Frank Brehm, Berlin +@license: GPL3 +@summary: test script (and module) for unit tests on base application class +''' + +import os +import sys +import logging + +from pathlib import Path + +try: + import unittest2 as unittest +except ImportError: + import unittest + +# from babel.dates import LOCALTZ + +libdir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'lib')) +sys.path.insert(0, libdir) + +from general import PpAdminToolsTestcase, get_arg_verbose, init_root_logger + +# from fb_tools.common import pp, to_str, is_sequence + +LOG = logging.getLogger('test-base-app') + +# ============================================================================= +class TestBaseApp(PpAdminToolsTestcase): + + # ------------------------------------------------------------------------- + def setUp(self): + + self.test_dir = Path(__file__).parent.resolve() + self.base_dir = self.test_dir.parent + self._appname = 'test-base-app' + + # ------------------------------------------------------------------------- + def tearDown(self): + + pass + + # ------------------------------------------------------------------------- + def test_import(self): + + LOG.info("Testing import of pp_admintools.app ...") + import pp_admintools.app + LOG.debug( + "Version of pp_admintools.app: " + pp_admintools.app.__version__) + + # ------------------------------------------------------------------------- + def test_cursor_position(self): + + LOG.info("Testing BaseDPXApplication.cursor_position() ...") + from pp_admintools.app import BaseDPXApplication + + pos = BaseDPXApplication.cursor_position() + LOG.debug("Got {}.".format(pos)) + + print('0123456789', end='', flush=True) + pos = BaseDPXApplication.cursor_position() + print() + if pos.x != -1 and pos.y != -1: + LOG.debug("Got {}.".format(pos)) + self.assertEqual(pos.x, 11) + else: + LOG.info("Could not detect position of screen cursor.") + + +# ============================================================================= +if __name__ == '__main__': + + verbose = get_arg_verbose() + if verbose is None: + verbose = 0 + init_root_logger(verbose) + + LOG.info("Starting tests ...") + + suite = unittest.TestSuite() + + suite.addTest(TestBaseApp('test_import', verbose)) + suite.addTest(TestBaseApp('test_cursor_position', verbose)) + + runner = unittest.TextTestRunner(verbosity=verbose) + + result = runner.run(suite) + + +# ============================================================================= + +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 -- 2.39.5