[all] pylint refinements

Improve code by bringing up the pylint score a bit.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-09 08:43:14 +01:00
parent 252260c249
commit 0c7884d170
4 changed files with 10 additions and 8 deletions

View file

@ -7,7 +7,7 @@ import importlib
import bumblebee.error import bumblebee.error
import bumblebee.modules import bumblebee.modules
def modules(): def all_modules():
"""Return a list of available modules""" """Return a list of available modules"""
result = [] result = []
path = os.path.dirname(bumblebee.modules.__file__) path = os.path.dirname(bumblebee.modules.__file__)
@ -28,7 +28,7 @@ class Module(object):
def __init__(self, engine, config={}, widgets=[]): def __init__(self, engine, config={}, widgets=[]):
self.name = self.__module__.split(".")[-1] self.name = self.__module__.split(".")[-1]
self._config = config self._config = config
if not "name" in self._config: if "name" not in self._config:
self._config["name"] = self.name self._config["name"] = self.name
self._widgets = [] self._widgets = []
if widgets: if widgets:
@ -68,7 +68,7 @@ class Engine(object):
def load_module(self, module_name, config_name=None): def load_module(self, module_name, config_name=None):
"""Load specified module and return it as object""" """Load specified module and return it as object"""
if config_name == None: if config_name is None:
config_name = module_name config_name = module_name
try: try:
module = importlib.import_module("bumblebee.modules.{}".format(module_name)) module = importlib.import_module("bumblebee.modules.{}".format(module_name))

View file

@ -6,13 +6,16 @@ this module
""" """
class Store(object): class Store(object):
"""Interface for storing and retrieving simple values"""
def __init__(self): def __init__(self):
self._data = {} self._data = {}
def set(self, key, value): def set(self, key, value):
"""Set 'key' to 'value', overwriting 'key' if it exists already"""
self._data[key] = value self._data[key] = value
def get(self, key, default=None): def get(self, key, default=None):
"""Return the current value of 'key', or 'default' if 'key' is not set"""
return self._data.get(key, default) return self._data.get(key, default)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -3,8 +3,7 @@
import unittest import unittest
import importlib import importlib
from bumblebee.modules.cpu import Module from bumblebee.engine import all_modules
from bumblebee.engine import modules
from bumblebee.config import Config from bumblebee.config import Config
from tests.util import assertWidgetAttributes, MockEngine from tests.util import assertWidgetAttributes, MockEngine
@ -13,7 +12,7 @@ class TestGenericModules(unittest.TestCase):
engine = MockEngine() engine = MockEngine()
config = Config() config = Config()
self.objects = {} self.objects = {}
for mod in modules(): for mod in all_modules():
cls = importlib.import_module("bumblebee.modules.{}".format(mod["name"])) cls = importlib.import_module("bumblebee.modules.{}".format(mod["name"]))
self.objects[mod["name"]] = getattr(cls, "Module")(engine, {"config": config}) self.objects[mod["name"]] = getattr(cls, "Module")(engine, {"config": config})