Skip to content
Snippets Groups Projects
Commit 60e5ae92 authored by Honza Mach's avatar Honza Mach
Browse files

Coding style improvements:

* Enabled automated tests using Pylint tool.
* Fixed many coding style issues reported by Pyflakes and Pylint tools.
* Changed authorship labels to another variant of my name (the one that is conatined in my primary email address).
parent 9a5f6ad7
No related branches found
No related tags found
No related merge requests found
Showing
with 162 additions and 129 deletions
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# This file is part of PyZenKit project (https://pypi.python.org/pypi/pyzenkit). # This file is part of PyZenKit project (https://pypi.python.org/pypi/pyzenkit).
# #
# Copyright (C) since 2015 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2015 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. # This project was initially written for personal use of the original author.
...@@ -147,7 +147,7 @@ function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ ...@@ -147,7 +147,7 @@ function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
# Good variable names which should always be accepted, separated by a comma # Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_ good-names=i,j,k,ex,Run,_,maxDiff,rc
# Include a hint for the correct naming format with invalid-name # Include a hint for the correct naming format with invalid-name
include-naming-hint=no include-naming-hint=no
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# This file is part of PyZenKit project (https://pypi.python.org/pypi/pyzenkit). # This file is part of PyZenKit project (https://pypi.python.org/pypi/pyzenkit).
# #
# Copyright (C) since 2015 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2015 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. # This project was initially written for personal use of the original author.
...@@ -147,7 +147,7 @@ function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ ...@@ -147,7 +147,7 @@ function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
# Good variable names which should always be accepted, separated by a comma # Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_ good-names=i,j,k,ex,Run,_,maxDiff,rc
# Include a hint for the correct naming format with invalid-name # Include a hint for the correct naming format with invalid-name
include-naming-hint=no include-naming-hint=no
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# This file is part of PyZenKit project (https://pypi.python.org/pypi/pyzenkit). # This file is part of PyZenKit project (https://pypi.python.org/pypi/pyzenkit).
# #
# Copyright (C) since 2015 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2015 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. # This project was initially written for personal use of the original author.
...@@ -141,8 +141,7 @@ pyflakes-test: FORCE ...@@ -141,8 +141,7 @@ pyflakes-test: FORCE
@echo "\n${GREEN}*** Checking test files with pyflakes ***${NC}\n" @echo "\n${GREEN}*** Checking test files with pyflakes ***${NC}\n"
-@python3 -m pyflakes $(DIR_LIB)/tests/*.py -@python3 -m pyflakes $(DIR_LIB)/tests/*.py
pylint: FORCE pylint: pylint-lib pylint-test
@echo "\n${GREEN}*** Checking test files with pylint - DISABLED ***${NC}\n"
pylint-lib: FORCE pylint-lib: FORCE
@echo "\n${GREEN}*** Checking code with pylint ***${NC}\n" @echo "\n${GREEN}*** Checking code with pylint ***${NC}\n"
......
...@@ -4,11 +4,19 @@ ...@@ -4,11 +4,19 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
# it was developed much further and used for project of author`s employer. # it was developed much further and used for project of author`s employer.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
__version__ = "0.45"
"""
*PyZenKit* is a collection of usefull tools and utilities and framework
for creating console applications, scripts and system services (daemons) in
Python 3.
"""
__author__ = "Honza Mach <honza.mach.ml@gmail.com>"
__version__ = "0.46"
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
...@@ -347,8 +347,7 @@ used to enhance the default output of ``runlog-*`` built-in actions: ...@@ -347,8 +347,7 @@ used to enhance the default output of ``runlog-*`` built-in actions:
* :py:func:`BaseApp._sub_runlogs_format_evaluation` * :py:func:`BaseApp._sub_runlogs_format_evaluation`
""" """
__author__ = "Honza Mach <honza.mach.ml@gmail.com>"
__author__ = "Jan Mach <honza.mach.ml@gmail.com>"
import os import os
...@@ -481,7 +480,7 @@ class ZenAppPlugin: ...@@ -481,7 +480,7 @@ class ZenAppPlugin:
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class BaseApp: class BaseApp: # pylint: disable=locally-disabled,too-many-public-methods, too-many-instance-attributes
""" """
Base implementation of generic executable application. This class attempts to Base implementation of generic executable application. This class attempts to
provide robust and stable framework, which can be used to writing all kinds provide robust and stable framework, which can be used to writing all kinds
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
...@@ -43,8 +43,7 @@ code. To view the result of demonstration please execute the module directly wit ...@@ -43,8 +43,7 @@ code. To view the result of demonstration please execute the module directly wit
Python3 interpretter. Python3 interpretter.
""" """
__author__ = "Honza Mach <honza.mach.ml@gmail.com>"
__author__ = "Jan Mach <honza.mach.ml@gmail.com>"
__credits__ = "Pavel Kácha <ph@rook.cz>" __credits__ = "Pavel Kácha <ph@rook.cz>"
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
...@@ -30,7 +30,7 @@ Python3 interpretter. ...@@ -30,7 +30,7 @@ Python3 interpretter.
""" """
__author__ = "Jan Mach <honza.mach.ml@gmail.com>" __author__ = "Honza Mach <honza.mach.ml@gmail.com>"
import os import os
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
...@@ -12,19 +12,18 @@ ...@@ -12,19 +12,18 @@
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
"""
Unit test module for testing the :py:mod:`pyzenkit.baseapp` module.
"""
__author__ = "Honza Mach <honza.mach.ml@gmail.com>"
import unittest import unittest
from unittest.mock import Mock, MagicMock, call
from pprint import pformat, pprint
import os import os
import sys
import shutil import shutil
# Generate the path to custom 'lib' directory
lib = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../'))
sys.path.insert(0, lib)
import pyzenkit.baseapp import pyzenkit.baseapp
...@@ -38,6 +37,9 @@ CFG_DIR_NAME = '/tmp/{}'.format(APP_NAME) # Name of the application conf ...@@ -38,6 +37,9 @@ CFG_DIR_NAME = '/tmp/{}'.format(APP_NAME) # Name of the application conf
class TestPyzenkitBaseApp(unittest.TestCase): class TestPyzenkitBaseApp(unittest.TestCase):
"""
Unit test class for testing the :py:class:`pyzenkit.baseapp.BaseApp` class.
"""
def setUp(self): def setUp(self):
pyzenkit.baseapp.BaseApp.json_save(CFG_FILE_NAME, {'test': 'x'}) pyzenkit.baseapp.BaseApp.json_save(CFG_FILE_NAME, {'test': 'x'})
...@@ -82,8 +84,11 @@ class TestPyzenkitBaseApp(unittest.TestCase): ...@@ -82,8 +84,11 @@ class TestPyzenkitBaseApp(unittest.TestCase):
self.maxDiff = None self.maxDiff = None
# Test argument parsing. # Test argument parsing.
argp = self.obj._init_argparser() argp = self.obj._init_argparser() # pylint: disable=locally-disabled,protected-access
self.assertEqual(vars(argp.parse_args(['--verbose'])), {'action': None, self.assertEqual(
vars(argp.parse_args(['--verbose'])),
{
'action': None,
'config_dir': None, 'config_dir': None,
'config_file': None, 'config_file': None,
'debug': None, 'debug': None,
...@@ -102,7 +107,8 @@ class TestPyzenkitBaseApp(unittest.TestCase): ...@@ -102,7 +107,8 @@ class TestPyzenkitBaseApp(unittest.TestCase):
'runlog_log': None, 'runlog_log': None,
'user': None, 'user': None,
'verbosity': 1 'verbosity': 1
}) }
)
def test_03_plugin(self): def test_03_plugin(self):
""" """
...@@ -112,5 +118,9 @@ class TestPyzenkitBaseApp(unittest.TestCase): ...@@ -112,5 +118,9 @@ class TestPyzenkitBaseApp(unittest.TestCase):
self.obj.plugin() self.obj.plugin()
#-------------------------------------------------------------------------------
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -4,27 +4,26 @@ ...@@ -4,27 +4,26 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
# it was developed much further and used for project of author`s employer. # it was developed much further and used for project of author`s employer.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
"""
Unit test module for testing the :py:mod:`pyzenkit.daemonizer` module.
"""
__author__ = "Honza Mach <honza.mach.ml@gmail.com>"
import unittest import unittest
from unittest.mock import Mock, MagicMock, call
from pprint import pformat, pprint
import os import os
import sys
import shutil
import signal import signal
# Generate the path to custom 'lib' directory
lib = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../'))
sys.path.insert(0, lib)
import pyzenkit.daemonizer import pyzenkit.daemonizer
...@@ -32,6 +31,9 @@ PID_FILE = '/tmp/test.pyzenkit.daemonizer.pid' ...@@ -32,6 +31,9 @@ PID_FILE = '/tmp/test.pyzenkit.daemonizer.pid'
class TestPyzenkitDaemonizer(unittest.TestCase): class TestPyzenkitDaemonizer(unittest.TestCase):
"""
Unit test class for testing the :py:mod:`pyzenkit.daemonizer` module.
"""
def test_01_basic(self): def test_01_basic(self):
""" """
...@@ -51,13 +53,16 @@ class TestPyzenkitDaemonizer(unittest.TestCase): ...@@ -51,13 +53,16 @@ class TestPyzenkitDaemonizer(unittest.TestCase):
""" """
Perform lite daemonization tests. Perform lite daemonization tests.
""" """
def hnd_sig_hup(signum, frame): def hnd_sig_hup(signum, frame): # pylint: disable=locally-disabled,unused-argument
"""Test signal handler."""
print("HANDLER CALLBACK: Received signal HUP ({})".format(signum)) print("HANDLER CALLBACK: Received signal HUP ({})".format(signum))
def hnd_sig_usr1(signum, frame): def hnd_sig_usr1(signum, frame): # pylint: disable=locally-disabled,unused-argument
"""Test signal handler."""
print("HANDLER CALLBACK: Received signal USR1 ({})".format(signum)) print("HANDLER CALLBACK: Received signal USR1 ({})".format(signum))
def hnd_sig_usr2(signum, frame): def hnd_sig_usr2(signum, frame): # pylint: disable=locally-disabled,unused-argument
"""Test signal handler."""
print("HANDLER CALLBACK: Received signal USR2 ({})".format(signum)) print("HANDLER CALLBACK: Received signal USR2 ({})".format(signum))
self.assertFalse(os.path.isfile(PID_FILE)) self.assertFalse(os.path.isfile(PID_FILE))
...@@ -78,5 +83,8 @@ class TestPyzenkitDaemonizer(unittest.TestCase): ...@@ -78,5 +83,8 @@ class TestPyzenkitDaemonizer(unittest.TestCase):
self.assertEqual(os.getcwd(), '/tmp') self.assertEqual(os.getcwd(), '/tmp')
#-------------------------------------------------------------------------------
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -4,25 +4,25 @@ ...@@ -4,25 +4,25 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
# it was developed much further and used for project of author`s employer. # it was developed much further and used for project of author`s employer.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
"""
Unit test module for testing the :py:mod:`pyzenkit.jsonconf` module.
"""
__author__ = "Honza Mach <honza.mach.ml@gmail.com>"
import unittest import unittest
from unittest.mock import Mock, MagicMock, call
from pprint import pformat, pprint
import os import os
import sys
import shutil import shutil
import collections
# Generate the path to custom 'lib' directory
lib = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../'))
sys.path.insert(0, lib)
import pyzenkit.jsonconf import pyzenkit.jsonconf
...@@ -73,18 +73,21 @@ TEST_DATA = [ ...@@ -73,18 +73,21 @@ TEST_DATA = [
] ]
class TestPyzenkitJsonconf(unittest.TestCase): class TestPyzenkitJsonconf(unittest.TestCase):
"""
Unit test class for testing the :py:mod:`pyzenkit.jsonconf` module.
"""
def setUp(self): def setUp(self):
try: try:
os.mkdir(SPOOL_DIR) os.mkdir(SPOOL_DIR)
for t in TEST_DATA: for tst in TEST_DATA:
pyzenkit.jsonconf.json_save( pyzenkit.jsonconf.json_save(
os.path.join(SPOOL_DIR, t['f']), os.path.join(SPOOL_DIR, tst['f']),
t['d'] tst['d']
) )
pyzenkit.jsonconf.json_save( pyzenkit.jsonconf.json_save(
os.path.join(SPOOL_DIR, '{}.schema'.format(t['f'])), os.path.join(SPOOL_DIR, '{}.schema'.format(tst['f'])),
t['s'] tst['s']
) )
except FileExistsError: except FileExistsError:
pass pass
...@@ -127,7 +130,9 @@ class TestPyzenkitJsonconf(unittest.TestCase): ...@@ -127,7 +130,9 @@ class TestPyzenkitJsonconf(unittest.TestCase):
schema = TEST_DATA[0]['s'] schema = TEST_DATA[0]['s']
)) ))
# Test validation of invalid data structure # Test validation of invalid data structure
self.assertRaises(pyzenkit.jsonconf.JSONSchemaException, pyzenkit.jsonconf.config_validate, self.assertRaises(
pyzenkit.jsonconf.JSONSchemaException,
pyzenkit.jsonconf.config_validate,
{ {
"x": 1, "x": 1,
"y": 2 "y": 2
...@@ -192,5 +197,9 @@ class TestPyzenkitJsonconf(unittest.TestCase): ...@@ -192,5 +197,9 @@ class TestPyzenkitJsonconf(unittest.TestCase):
self.assertEqual(pyzenkit.jsonconf.config_load_dir(SPOOL_DIR, schema = SPOOL_DIR, extension = '.json'), {"hello": 1, "world": 2}) self.assertEqual(pyzenkit.jsonconf.config_load_dir(SPOOL_DIR, schema = SPOOL_DIR, extension = '.json'), {"hello": 1, "world": 2})
self.assertEqual(pyzenkit.jsonconf.config_load_dir(SPOOL_DIR, schema = True, extension = '.json'), {"hello": 1, "world": 2}) self.assertEqual(pyzenkit.jsonconf.config_load_dir(SPOOL_DIR, schema = True, extension = '.json'), {"hello": 1, "world": 2})
#-------------------------------------------------------------------------------
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -4,25 +4,26 @@ ...@@ -4,25 +4,26 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
# it was developed much further and used for project of author`s employer. # it was developed much further and used for project of author`s employer.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
"""
Unit test module for testing the :py:mod:`pyzenkit.zendaemon` module.
"""
__author__ = "Honza Mach <honza.mach.ml@gmail.com>"
import unittest import unittest
from unittest.mock import Mock, MagicMock, call
from pprint import pformat, pprint
import os import os
import sys
import shutil import shutil
# Generate the path to custom 'lib' directory
lib = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../'))
sys.path.insert(0, lib)
import pyzenkit.baseapp import pyzenkit.baseapp
import pyzenkit.zendaemon import pyzenkit.zendaemon
...@@ -35,6 +36,9 @@ CFG_FILE_NAME = '/tmp/{}.conf'.format(DMN_NAME) # Name of the daemon configura ...@@ -35,6 +36,9 @@ CFG_FILE_NAME = '/tmp/{}.conf'.format(DMN_NAME) # Name of the daemon configura
CFG_DIR_NAME = '/tmp/{}'.format(DMN_NAME) # Name of the daemon configuration directory CFG_DIR_NAME = '/tmp/{}'.format(DMN_NAME) # Name of the daemon configuration directory
class TestPyzenkitZenDaemon(unittest.TestCase): class TestPyzenkitZenDaemon(unittest.TestCase):
"""
Unit test class for testing the :py:class:`pyzenkit.zendaemon.ZenDaemon` class.
"""
def setUp(self): def setUp(self):
pyzenkit.baseapp.BaseApp.json_save(CFG_FILE_NAME, {'test': 'x'}) pyzenkit.baseapp.BaseApp.json_save(CFG_FILE_NAME, {'test': 'x'})
...@@ -49,13 +53,7 @@ class TestPyzenkitZenDaemon(unittest.TestCase): ...@@ -49,13 +53,7 @@ class TestPyzenkitZenDaemon(unittest.TestCase):
os.remove(CFG_FILE_NAME) os.remove(CFG_FILE_NAME)
shutil.rmtree(CFG_DIR_NAME) shutil.rmtree(CFG_DIR_NAME)
def test_01_basic(self): def test_01_calc_statistics(self):
"""
Perform the basic operativity tests.
"""
self.assertTrue(True)
def test_02_calc_statistics(self):
""" """
Perform the test of statistics calculation. Perform the test of statistics calculation.
""" """
...@@ -66,13 +64,20 @@ class TestPyzenkitZenDaemon(unittest.TestCase): ...@@ -66,13 +64,20 @@ class TestPyzenkitZenDaemon(unittest.TestCase):
{}, {},
50 50
) )
self.assertEqual(result, { self.assertEqual(
result,
{
'cnt_test_a1': {'cnt': 50, 'inc': 50, 'pct': 100.0, 'spd': 1.0}, 'cnt_test_a1': {'cnt': 50, 'inc': 50, 'pct': 100.0, 'spd': 1.0},
'cnt_test_a2': {'cnt': 100, 'inc': 100, 'pct': 100.0, 'spd': 2.0}, 'cnt_test_a2': {'cnt': 100, 'inc': 100, 'pct': 100.0, 'spd': 2.0},
'sub': { 'sub': {
'cnt_test_b1': {'cnt': 500, 'inc': 500, 'pct': 100.0, 'spd': 10.0}, 'cnt_test_b1': {'cnt': 500, 'inc': 500, 'pct': 100.0, 'spd': 10.0},
'cnt_test_b2': {'cnt': 1000, 'inc': 1000, 'pct': 100.0, 'spd': 20.0}}} 'cnt_test_b2': {'cnt': 1000, 'inc': 1000, 'pct': 100.0, 'spd': 20.0}}
}
) )
#-------------------------------------------------------------------------------
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
...@@ -16,12 +16,10 @@ ...@@ -16,12 +16,10 @@
Unit test module for testing the :py:mod:`pyzenkit.zenscript` module. Unit test module for testing the :py:mod:`pyzenkit.zenscript` module.
""" """
__author__ = "Honza Mach <honza.mach.ml@gmail.com>"
__author__ = "Jan Mach <honza.mach.ml@gmail.com>"
import unittest import unittest
from unittest.mock import Mock, MagicMock, call
import os import os
import shutil import shutil
...@@ -41,7 +39,7 @@ CFG_DIR_NAME = '/tmp/{}'.format(SCR_NAME) # Name of the script configurat ...@@ -41,7 +39,7 @@ CFG_DIR_NAME = '/tmp/{}'.format(SCR_NAME) # Name of the script configurat
class TestPyzenkitZenScript(unittest.TestCase): class TestPyzenkitZenScript(unittest.TestCase):
""" """
Unit test class for testing the :py:mod:`pyzenkit.zenscript.ZenScript` class. Unit test class for testing the :py:class:`pyzenkit.zenscript.ZenScript` class.
""" """
def setUp(self): def setUp(self):
...@@ -67,7 +65,7 @@ class TestPyzenkitZenScript(unittest.TestCase): ...@@ -67,7 +65,7 @@ class TestPyzenkitZenScript(unittest.TestCase):
self.obj.plugin() self.obj.plugin()
def test_02_calculate_interval_thresholds(self): def test_02_calc_int_thrs(self):
""" """
Perform tests of interval thresholds calculations. Perform tests of interval thresholds calculations.
""" """
...@@ -137,7 +135,7 @@ class TestPyzenkitZenScript(unittest.TestCase): ...@@ -137,7 +135,7 @@ class TestPyzenkitZenScript(unittest.TestCase):
(datetime.datetime(2016, 2, 8, 12, 25), datetime.datetime(2016, 2, 8, 12, 30)) (datetime.datetime(2016, 2, 8, 12, 25), datetime.datetime(2016, 2, 8, 12, 30))
) )
def test_03_calculate_upper_threshold(self): def test_03_calc_upper_thrs(self):
""" """
Perform tests of upper threshold calculations. Perform tests of upper threshold calculations.
""" """
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
......
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Copyright (C) 2015-2016 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) 2015-2016 Honza Mach <honza.mach.ml@gmail.com>
# Use of this source is governed by the MIT license, see LICENSE file. # Use of this source is governed by the MIT license, see LICENSE file.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
......
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Copyright (C) 2015-2016 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) 2015-2016 Honza Mach <honza.mach.ml@gmail.com>
# Use of this source is governed by the MIT license, see LICENSE file. # Use of this source is governed by the MIT license, see LICENSE file.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
...@@ -162,8 +162,7 @@ Programming API ...@@ -162,8 +162,7 @@ Programming API
* :py:func:`ZenDaemon.wait` - Pause the processing for given amount of time. * :py:func:`ZenDaemon.wait` - Pause the processing for given amount of time.
""" """
__author__ = "Honza Mach <honza.mach.ml@gmail.com>"
__author__ = "Jan Mach <honza.mach.ml@gmail.com>"
import os import os
...@@ -300,7 +299,7 @@ class EventQueueManager: ...@@ -300,7 +299,7 @@ class EventQueueManager:
len1 = len(self.events_at) len1 = len(self.events_at)
if len1: if len1:
if self.events_at[0][0] <= time.time(): if self.events_at[0][0] <= time.time():
(tstamp, event, args) = heapq.heappop(self.events_at) (tstamp, event, args) = heapq.heappop(self.events_at) # pylint: disable=locally-disabled,unused-variable
return (event, args) return (event, args)
len2 = len(self.events) len2 = len(self.events)
if len2: if len2:
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# This file is part of PyZenKit package. # This file is part of PyZenKit package.
# #
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/) # Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com> # Copyright (C) since 2015 Honza Mach <honza.mach.ml@gmail.com>
# Use of this package is governed by the MIT license, see LICENSE file. # Use of this package is governed by the MIT license, see LICENSE file.
# #
# This project was initially written for personal use of the original author. Later # This project was initially written for personal use of the original author. Later
...@@ -132,8 +132,7 @@ Programming API ...@@ -132,8 +132,7 @@ Programming API
* get a name of a default command: :py:func:`ZenScript.get_default_command` * get a name of a default command: :py:func:`ZenScript.get_default_command`
""" """
__author__ = "Honza Mach <honza.mach.ml@gmail.com>"
__author__ = "Jan Mach <honza.mach.ml@gmail.com>"
import os import os
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment