From 9a350ddc2aa4e6e9c52a5f3c28d3eee64778f48f Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sat, 17 Dec 2016 08:42:23 +0100 Subject: [PATCH] [tests/config] Add tests for helptexts Ensure that each theme is listed in the helptext and that there is a helptext entry for every module. --- bumblebee/config.py | 3 ++- tests/test_config.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/bumblebee/config.py b/bumblebee/config.py index 92472e5..e3b24aa 100644 --- a/bumblebee/config.py +++ b/bumblebee/config.py @@ -4,6 +4,7 @@ This module provides configuration information (loaded modules, module parameters, etc.) to all other components """ +import sys import argparse import textwrap import importlib @@ -26,7 +27,7 @@ class print_usage(argparse.Action): self.print_themes() else: parser.print_help() - parser.exit() + sys.exit(0) def print_themes(self): print(textwrap.fill(", ".join(bumblebee.theme.themes()), diff --git a/tests/test_config.py b/tests/test_config.py index 90e9816..e7a05f9 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,7 +1,15 @@ # pylint: disable=C0103,C0111 + import unittest +import mock +try: + from StringIO import StringIO +except ImportError: + from io import StringIO from bumblebee.config import Config +from bumblebee.theme import themes +from bumblebee.engine import all_modules class TestConfig(unittest.TestCase): def setUp(self): @@ -25,4 +33,20 @@ class TestConfig(unittest.TestCase): "name": x.split(":")[1], } for x in self.someAliasModules]) + @mock.patch("sys.stdout", new_callable=StringIO) + @mock.patch("sys.exit") + def test_list_themes(self, exit, stdout): + cfg = Config(["-l", "themes"]) + result = stdout.getvalue() + for theme in themes(): + self.assertTrue(theme in result) + + @mock.patch("sys.stdout", new_callable=StringIO) + @mock.patch("sys.exit") + def test_list_modules(self, exit, stdout): + cfg = Config(["-l", "modules"]) + result = stdout.getvalue() + for module in all_modules(): + self.assertTrue(module["name"] in result) + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4