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

Huge feature update of the whole library, BC-BREAK!

* Greatly improved module documentation
* Code style improvements with the use of pylint tool
* BC breaking refactoring to unify code style
* Multiple minor bugfixes

Note: I am well aware of the ugliness of such a huge commit. However all of the changes were done in a short time and as part of a single big feature upgrade and in my opinion in this case I can justify that, because all changes are related to one another.
parent 519a1a05
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Copyright (C) since 2016 Jan Mach <honza.mach.ml@gmail.com>
# Use of this source is governed by the MIT license, see LICENSE file.
# This file is part of PyZenKit package.
#
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com>
# 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
# it was developed much further and used for project of author`s employer.
#-------------------------------------------------------------------------------
import unittest
......@@ -188,4 +194,3 @@ class TestPyzenkitJsonconf(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Copyright (C) since 2016 Jan Mach <honza.mach.ml@gmail.com>
# Use of this source is governed by the MIT license, see LICENSE file.
# This file is part of PyZenKit package.
#
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com>
# 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
# it was developed much further and used for project of author`s employer.
#-------------------------------------------------------------------------------
import unittest
......
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Copyright (C) since 2016 Jan Mach <honza.mach.ml@gmail.com>
# Use of this source is governed by the MIT license, see LICENSE file.
# This file is part of PyZenKit package.
#
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com>
# 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
# it was developed much further and used for project of author`s employer.
#-------------------------------------------------------------------------------
import unittest
from unittest.mock import Mock, MagicMock, call
from pprint import pformat, pprint
......@@ -12,6 +19,8 @@ from pprint import pformat, pprint
import os
import sys
import shutil
import datetime
# Generate the path to custom 'lib' directory
lib = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../'))
......@@ -20,14 +29,15 @@ sys.path.insert(0, lib)
import pyzenkit.baseapp
import pyzenkit.zenscript
#
# Global variables
#
SCR_NAME = 'test_zenscript.py' # Name of the script process
JSON_FILE_NAME = '/tmp/daemon-state.json' # Name of the test JSON file
SCR_NAME = 'test-zenscript.py' # Name of the script process
CFG_FILE_NAME = '/tmp/{}.conf'.format(SCR_NAME) # Name of the script configuration file
CFG_DIR_NAME = '/tmp/{}'.format(SCR_NAME) # Name of the script configuration directory
class TestPyzenkitZenScript(unittest.TestCase):
def setUp(self):
......@@ -37,13 +47,9 @@ class TestPyzenkitZenScript(unittest.TestCase):
except FileExistsError:
pass
self.obj = pyzenkit.zenscript._DemoZenScript(
self.obj = pyzenkit.zenscript.DemoZenScript(
name = SCR_NAME,
path_cfg = '/tmp',
path_log = '/tmp',
path_tmp = '/tmp',
path_run = '/tmp',
description = 'DemoZenScript - generic script (DEMO)'
description = 'TestZenScript - Testing script'
)
def tearDown(self):
os.remove(CFG_FILE_NAME)
......@@ -53,16 +59,21 @@ class TestPyzenkitZenScript(unittest.TestCase):
"""
Perform the basic utility tests.
"""
self.maxDiff = None
self.obj.plugin()
# Test the interval threshold calculations
self.assertEqual(self.obj.calculate_interval_thresholds('daily', time_cur = 1454934631), (1454848231, 1454934631))
self.assertEqual(self.obj.calculate_interval_thresholds('daily', time_cur = 1454934631, flag_floor = True), (1454803200, 1454889600))
self.assertEqual(self.obj.calculate_interval_thresholds(time_high = 1454934631, interval = 'daily'), (datetime.datetime(2016, 2, 7, 13, 30, 31), datetime.datetime(2016, 2, 8, 13, 30, 31)))
self.assertEqual(self.obj.calculate_interval_thresholds(time_high = 1454934631, interval = 'daily', adjust = True), (datetime.datetime(2016, 2, 7, 1, 0), datetime.datetime(2016, 2, 8, 1, 0)))
def test_02_basic(self):
def test_02_plugin(self):
"""
Perform the basic operativity tests.
"""
self.assertTrue(True)
self.maxDiff = None
self.obj.plugin()
if __name__ == "__main__":
unittest.main()
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Copyright (C) since 2016 Jan Mach <honza.mach.ml@gmail.com>
# Use of this source is governed by the MIT license, see LICENSE file.
# This file is part of PyZenKit package.
#
# Copyright (C) since 2016 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Jan Mach <honza.mach.ml@gmail.com>
# 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
# it was developed much further and used for project of author`s employer.
#-------------------------------------------------------------------------------
# Notes:
# - The concept for dynamic module loading was taken from here
# [1] https://lextoumbourou.com/blog/posts/dynamically-loading-modules-and-classes-in-python/
......
This diff is collapsed.
This diff is collapsed.
......@@ -23,7 +23,7 @@ with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
setup(
name = 'pyzenkit',
version = '0.20',
version = '0.32',
description = 'Python 3 script and daemon toolkit',
long_description = long_description,
classifiers = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment