Skip to content

Commit

Permalink
Add logger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thatsIch committed Dec 12, 2016
1 parent 95deb76 commit bc74d09
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
13 changes: 6 additions & 7 deletions logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
# Is required now due to async call and ignoring sublime.* from main routine
'''

setting_key = "rainmeter_enable_logging"

def plugin_loaded():
global __log

key = "rainmeter_enable_logging"

settings = sublime.load_settings("Rainmeter.sublime-settings")
__log = settings.get(key, False)
settings.add_on_change(key, __load_settings)
def plugin_loaded():
settings = __load_settings()
settings.add_on_change(setting_key, __load_settings)

info(__file__, "plugin_loaded()", "Logger succesfully loaded.")

Expand All @@ -30,6 +27,8 @@ def __load_settings():
global __log
__log = settings.get(key, False)

return settings


def info(file_path, function, string):
if __log:
Expand Down
34 changes: 34 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys

from unittest import TestCase

logger = sys.modules["Rainmeter.logger"]


class TestFunctions(TestCase):

def test_info(self):
"""
info should not through exceptions due to settings
"""
try:
logger.info(
__file__,
"test_info(self)",
"info test"
)
except Exception as error:
self.fail("logger.info() raised exception '" + error + "'")

def test_error(self):
"""
error should not through exception due to settings
"""
try:
logger.error(
__file__,
"test_error(self)",
"error test"
)
except Exception as error:
self.fail("logger.error() raised exception '" + error + "'")

0 comments on commit bc74d09

Please sign in to comment.