ya2 · news · projects · code · about

unit test (main module): logging
authorFlavio Calva <f.calva@gmail.com>
Mon, 5 Sep 2022 18:02:14 +0000 (19:02 +0100)
committerFlavio Calva <f.calva@gmail.com>
Mon, 5 Sep 2022 18:02:14 +0000 (19:02 +0100)
prj.org
tests/test_main.py [new file with mode: 0644]
ya2/utils/log.py

diff --git a/prj.org b/prj.org
index 483097584f399f608929073cb74e0a687f18fa37..0500ea3bb96362c3398cdf3aa611f7887f3ea0dc 100644 (file)
--- a/prj.org
+++ b/prj.org
@@ -1,9 +1,11 @@
 #+STARTUP: indent
-#+TODO: BACKLOG READY RED GREEN REFACTOR LINT L10N BUILD BLOG | DONE
+#+TODO: BACKLOG READY DOING | DONE
 #+CATEGORY: pmachines
 #+TAGS: bug(b) calendar(c) waiting(w)
 
-* BLOG write the blog post for q3
+* DOING unit test main.py
+* READY unit test: completeness of l10n
+* READY unit test: no errors from pyflakes
 * BACKLOG intro animation (from target item to start position)
 * BACKLOG buttons of the scenes enabled sequentially
 - [ ] each scene has a version
diff --git a/tests/test_main.py b/tests/test_main.py
new file mode 100644 (file)
index 0000000..3b479f0
--- /dev/null
@@ -0,0 +1,38 @@
+from pathlib import Path
+import sys
+if '' in sys.path: sys.path.remove('')
+sys.path.append(str(Path(__file__).parent.parent.parent))
+from os import remove
+from os.path import exists
+from unittest import TestCase
+from setuptools.dist import Distribution
+from setup import AbsCmd
+from ya2.build.build import exec_cmd
+from main import Main
+import logging
+from ya2.utils.dictfile import DctFile
+import importlib
+import main
+
+
+class MainTests(TestCase):
+
+    def setUp(self):
+        self.__optfile = DctFile('options.ini')
+        self.__verbose_val = self.__optfile['development']['verbose_log']
+
+    def tearDown(self):
+        self.__optfile['development']['verbose_log'] = self.__verbose_val
+        self.__optfile.store()
+
+    def test_logging(self):
+        self.assertEqual(logging.root.handlers[0].formatter._fmt, '%(asctime)s %(message)s')
+        self.assertEqual(logging.root.handlers[0].formatter.datefmt, '%H:%M:%S')
+        self.__optfile['development']['verbose_log'] = 0
+        self.__optfile.store()
+        importlib.reload(main)
+        self.assertEqual(logging.root.level, logging.INFO)
+        self.__optfile['development']['verbose_log'] = 1
+        self.__optfile.store()
+        importlib.reload(main)
+        self.assertEqual(logging.root.level, logging.DEBUG)
index 8a38e1985ca8236087b7a610cef2a80078fa3bbe..ab9d43ac587b9f6ad17db342d746e0236848b042 100755 (executable)
@@ -33,7 +33,7 @@ class LogMgrBase:  # headless log manager
             opt_path = str(Filename.get_user_appdata_directory()) + '/pmachines'
         opath = LibP3d.fixpath(opt_path + '/options.ini') if opt_path else \
                 'options.ini'
-        return opt_path
+        return opath
 
     @staticmethod
     def __log_info_debug_messages(opath):