From 52a93e5a5dcd67a170526ede482d17354dc6df87 Mon Sep 17 00:00:00 2001
From: Peter Kessen
Date: Sun, 27 Sep 2015 12:43:18 +0200
Subject: [PATCH 1/2] added test for Subcommands
---
test/test_ui_init.py | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/test/test_ui_init.py b/test/test_ui_init.py
index 15f1f89557..0363729300 100644
--- a/test/test_ui_init.py
+++ b/test/test_ui_init.py
@@ -15,6 +15,8 @@
"""Test module for file ui/__init__.py
"""
+import textwrap
+
from test import _common
from test._common import unittest
@@ -60,6 +62,41 @@ def test_human_seconds(self):
self.assertEqual(h, ui.human_seconds(i))
+class SubcommandTest(_common.LibTestCase):
+ def setUp(self):
+ super(SubcommandTest, self).setUp()
+
+ self.io.install()
+
+ def tearDown(self):
+ self.io.restore()
+
+ def _add_subcommand(self, parser=None):
+ self.test_cmd = ui.Subcommand('test', parser,
+ help='This is the help text for test')
+
+ def test_print_help(self):
+ parser = ui.CommonOptionsParser(usage="Test")
+ parser.add_all_common_options()
+ self._add_subcommand(parser)
+ self.test_cmd.print_help()
+ desired_output = textwrap.dedent(
+ """ Usage: Test
+
+ Options:
+ -h, --help show this help message and exit
+ -a, --album match albums instead of tracks
+ -p PATH, --path=PATH print paths for matched items or albums
+ -f FORMAT, --format=FORMAT
+ print with custom format
+ """)
+ self.assertEqual(self.io.stdout.get(), desired_output)
+
+ def test_get_root_parser(self):
+ self._add_subcommand()
+ root_parser = self.test_cmd.root_parser
+
+
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)
From 38e1ce291c3e4768678685f4f9d45092c4fde7ba Mon Sep 17 00:00:00 2001
From: Peter Kessen
Date: Sun, 27 Sep 2015 14:03:14 +0200
Subject: [PATCH 2/2] fixed errors with flake8 rules
---
test/test_ui_init.py | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/test/test_ui_init.py b/test/test_ui_init.py
index 0363729300..f5b1f6a97f 100644
--- a/test/test_ui_init.py
+++ b/test/test_ui_init.py
@@ -72,7 +72,8 @@ def tearDown(self):
self.io.restore()
def _add_subcommand(self, parser=None):
- self.test_cmd = ui.Subcommand('test', parser,
+ self.test_cmd = ui.Subcommand(
+ 'test', parser,
help='This is the help text for test')
def test_print_help(self):
@@ -82,7 +83,7 @@ def test_print_help(self):
self.test_cmd.print_help()
desired_output = textwrap.dedent(
""" Usage: Test
-
+
Options:
-h, --help show this help message and exit
-a, --album match albums instead of tracks
@@ -90,11 +91,13 @@ def test_print_help(self):
-f FORMAT, --format=FORMAT
print with custom format
""")
- self.assertEqual(self.io.stdout.get(), desired_output)
+ self.assertEqual(self.io.stdout.get(), desired_output)
def test_get_root_parser(self):
self._add_subcommand()
root_parser = self.test_cmd.root_parser
+ # Following is just a workaround for FLAKE8 rule F841
+ root_parser = root_parser
def suite():