From 0a7a4150e090204365be5ae85328a4966ea1ef75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thayn=C3=A3=20Moretti?= Date: Sun, 4 Oct 2020 15:35:13 -0300 Subject: [PATCH] Create arch-update tests --- tests/modules/contrib/test_arch-update.py | 69 +++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/modules/contrib/test_arch-update.py b/tests/modules/contrib/test_arch-update.py index b11187b..53c2941 100644 --- a/tests/modules/contrib/test_arch-update.py +++ b/tests/modules/contrib/test_arch-update.py @@ -1,7 +1,76 @@ import pytest +import util.cli +import core.config +import modules.contrib.arch_update + +@pytest.fixture +def module(): + module = modules.contrib.arch_update.Module( + config=core.config.Config([]), + theme=None + ) + + yield module + def test_load_module(): __import__("modules.contrib.arch-update") def test_load_symbolic_link_module(): __import__("modules.contrib.arch_update") + +def test_with_one_package(module, mocker): + command = mocker.patch( + 'util.cli.execute', + return_value=(0, 'bumblebee 1.0.0') + ) + + module.update() + + command.assert_called_with( + 'checkupdates', + ignore_errors=True, + return_exitcode=True + ) + + widget = module.widget() + assert widget.full_text() == 'Update Arch: 1' + assert module.state(widget) == None + assert module.hidden() == False + +def test_with_two_packages(module, mocker): + command = mocker.patch( + 'util.cli.execute', + return_value=(0, 'bumblebee 1.0.0\ni3wm 3.5.7') + ) + + module.update() + + widget = module.widget() + assert widget.full_text() == 'Update Arch: 2' + assert module.state(widget) == 'warning' + assert module.hidden() == False + +def test_with_no_packages(module, mocker): + mocker.patch('util.cli.execute', return_value=(2, '')) + + module.update() + + widget = module.widget() + assert widget.full_text() == 'Update Arch: 0' + assert module.state(widget) == None + assert module.hidden() == True + +def test_with_unknown_code(module, mocker): + mocker.patch('util.cli.execute', return_value=(99, 'error')) + logger = mocker.patch('logging.error') + + module.update() + + logger.assert_called_with('checkupdates exited with {}: {}'.format(99, 'error')) + + widget = module.widget() + assert widget.full_text() == 'Update Arch: 0' + assert module.state(widget) == 'warning' + assert module.hidden() == False +