Skip to content

Commit

Permalink
Add test for builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
dagwieers committed Oct 29, 2019
1 parent de1b970 commit 2c185bc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coverage:
range: 50..100
range: 0..100
round: nearest
status:
project:
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ install:
script:
- tox
- tox -e flake8
- pylint screensaver.py
- pylint screensaver.py test/
#- msgcmp resources/language/resource.language.{nl_nl,en_gb}/strings.po
#- kodi-addon-checker . --branch=krypton
#- kodi-addon-checker . --branch=leia
Expand Down
18 changes: 9 additions & 9 deletions screensaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@
dict(name='do-nothing', title='Do nothing',
function='log', args=[1, 'Do nothing to power off system']),
dict(name='suspend-builtin', title='Suspend (built-in)',
function='jsonrpc', kwargs=dict(method='System.Suspend')),
function='jsonrpc', kwargs_off=dict(method='System.Suspend')),
dict(name='hibernate-builtin', title='Hibernate (built-in)',
function='jsonrpc', kwargs=dict(method='System.Hibernate')),
function='jsonrpc', kwargs_off=dict(method='System.Hibernate')),
dict(name='quit-builtin', title='Quit (built-in)',
function='jsonrpc', kwargs=dict(method='Application.Quit')),
function='jsonrpc', kwargs_off=dict(method='Application.Quit')),
dict(name='shutdown-builtin', title='ShutDown action (built-in)',
function='jsonrpc', kwargs=dict(method='System.Shutdown')),
function='jsonrpc', kwargs_off=dict(method='System.Shutdown')),
dict(name='reboot-builtin', title='Reboot (built-in)',
function='jsonrpc', kwargs=dict(method='System.Reboot')),
function='jsonrpc', kwargs_off=dict(method='System.Reboot')),
dict(name='powerdown-builtin', title='Powerdown (built-in)',
function='jsonrpc', kwargs=dict(method='System.Powerdown')),
function='jsonrpc', kwargs_off=dict(method='System.Powerdown')),
]


Expand Down Expand Up @@ -190,9 +190,9 @@ def run_command(command, shell=False):
sys.exit(2)


def func(function, *args):
def func(function, *args, **kwargs):
''' Execute a global function with arguments '''
return globals()[function](*args)
return globals()[function](*args, **kwargs)


class TurnOffMonitor(Monitor, object):
Expand Down Expand Up @@ -260,7 +260,7 @@ def onInit(self): # pylint: disable=invalid-name
# Power off system
if self.power.get('name') != 'do-nothing':
log(1, msg="Turn system off using method '{power_method}'", power_method=self.power.get('name'))
func(self.power.get('function'), *self.power.get('args', []), **self.power.get('kwargs', {}))
func(self.power.get('function'), **self.power.get('kwargs_off', {}))

def resume(self):
''' Perform this when the Screensaver is stopped '''
Expand Down
21 changes: 17 additions & 4 deletions test/test_screensaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,26 @@


class TestScreensaver(unittest.TestCase):
turnoff = screensaver.TurnOffDialog('gui.xml', screensaver.ADDON_PATH, 'default')

def test_screensaver(self):
@staticmethod
def test_screensaver_log():
''' Test enabling screensaver '''
self.turnoff.onInit()
screensaver.ADDON.settings['display_method'] = '0'
screensaver.ADDON.settings['power_method'] = '0'
turnoff = screensaver.TurnOffDialog('gui.xml', screensaver.ADDON_PATH, 'default')
turnoff.onInit()
time.sleep(5)
self.turnoff.resume()
turnoff.resume()

@staticmethod
def test_screensaver_builtin():
''' Test enabling screensaver '''
screensaver.ADDON.settings['display_method'] = '1'
screensaver.ADDON.settings['power_method'] = '1'
turnoff = screensaver.TurnOffDialog('gui.xml', screensaver.ADDON_PATH, 'default')
turnoff.onInit()
time.sleep(5)
turnoff.resume()


if __name__ == '__main__':
Expand Down

0 comments on commit 2c185bc

Please sign in to comment.