Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test subcommand #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ def test_bad_year_range_def_nodigits(self):
with self.assertRaises(ui.UserError):
self._setup_config(bucket_year=['nodigits'])

def check_span_from_str(self, sstr, dfrom, dto):
d = bucket.span_from_str(sstr)
self.assertEqual(dfrom, d['from'])
self.assertEqual(dto, d['to'])

def test_span_from_str(self):
self.check_span_from_str("1980 2000", 1980, 2000)
self.check_span_from_str("1980 00", 1980, 2000)
self.check_span_from_str("1930 00", 1930, 2000)
self.check_span_from_str("1930 50", 1930, 1950)


def suite():
return unittest.TestLoader().loadTestsFromName(__name__)
Expand Down
3 changes: 3 additions & 0 deletions test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def test_logging_management(self):
l5 = l3.getChild("shalala")
self.assertEqual(l5.__class__, blog.BeetsLogger)

l6 = log.getLogger()
self.assertNotEqual(l1, l6)

def test_str_format_logging(self):
l = blog.getLogger("baz123")
stream = StringIO()
Expand Down
40 changes: 40 additions & 0 deletions test/test_ui_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

"""Test module for file ui/__init__.py
"""
import textwrap

from test import _common
from test._common import unittest

Expand Down Expand Up @@ -60,6 +62,44 @@ 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
# Following is just a workaround for FLAKE8 rule F841
root_parser = root_parser


def suite():
return unittest.TestLoader().loadTestsFromName(__name__)

Expand Down