Remove unnecessary metaclass from IntervalModule
This commit is contained in:
parent
60470e4d7f
commit
41003ef702
@ -102,18 +102,10 @@ class Module(SettingsBase):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
class IntervalModuleMeta(type):
|
class IntervalModule(Module):
|
||||||
"""Add interval setting to `settings` attribute if it does not exist."""
|
settings = (
|
||||||
|
("interval", "interval in seconds between module updates"),
|
||||||
def __init__(cls, name, bases, namespace):
|
)
|
||||||
super(IntervalModuleMeta, cls).__init__(name, bases, namespace)
|
|
||||||
if not hasattr(cls, 'settings'):
|
|
||||||
cls.settings = tuple()
|
|
||||||
if 'interval' not in SettingsBase.flatten_settings(cls.settings):
|
|
||||||
cls.settings += ('interval', )
|
|
||||||
|
|
||||||
|
|
||||||
class IntervalModule(Module, metaclass=IntervalModuleMeta):
|
|
||||||
interval = 5 # seconds
|
interval = 5 # seconds
|
||||||
managers = {}
|
managers = {}
|
||||||
|
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
from i3pystatus.core.modules import IntervalModule
|
|
||||||
|
|
||||||
|
|
||||||
class IntervalModuleMetaTest(unittest.TestCase):
|
|
||||||
|
|
||||||
def test_no_settings(self):
|
|
||||||
class NoSettings(IntervalModule):
|
|
||||||
pass
|
|
||||||
for element in ('interval', ):
|
|
||||||
self.assertIn(element, NoSettings.settings)
|
|
||||||
|
|
||||||
def test_no_interval_setting(self):
|
|
||||||
class NoIntervalSetting(IntervalModule):
|
|
||||||
settings = (('option', 'desc'),)
|
|
||||||
self.assertEqual(NoIntervalSetting.settings,
|
|
||||||
(('option', 'desc'), 'interval'))
|
|
||||||
|
|
||||||
def test_settings_with_interval(self):
|
|
||||||
class SettingsInterval(IntervalModule):
|
|
||||||
settings = ('option', 'interval')
|
|
||||||
self.assertEqual(SettingsInterval.settings, ('option', 'interval'))
|
|
||||||
|
|
||||||
def test_settings_with_interval_desc(self):
|
|
||||||
class SetttingsIntervalDesc(IntervalModule):
|
|
||||||
settings = (('interval', 'desc'),)
|
|
||||||
self.assertEqual(SetttingsIntervalDesc.settings,
|
|
||||||
(('interval', 'desc'),))
|
|
Loading…
Reference in New Issue
Block a user