Skip to content

Commit

Permalink
added some test and quickfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Jakab committed Mar 27, 2020
1 parent da64ef4 commit ee463ba
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
4 changes: 4 additions & 0 deletions beetsplug/yearfixer/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def func(self, lib: Library, options, arguments):

def handle_main_task(self):
items = self.retrieve_library_items()
if not items:
self._say("Your query did not produce any results.", log_only=False)
return

for item in items:
self.process_item(item)
item.try_write()
Expand Down
3 changes: 2 additions & 1 deletion beetsplug/yearfixer/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
# License: See LICENSE.txt

import logging
import os
from distutils.util import convert_path
from urllib.parse import quote_plus

from beets.library import Item

# Get values as: plg_ns['__PLUGIN_NAME__']
plg_ns = {}
about_path = convert_path('beetsplug/yearfixer/about.py')
about_path = os.path.join(os.path.dirname(__file__), u'about.py')
with open(about_path) as about_file:
exec(about_file.read(), plg_ns)

Expand Down
33 changes: 22 additions & 11 deletions test/00_completion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# Created: 2/19/20, 12:31 PM
# License: See LICENSE.txt

from test.helper import TestHelper, Assertions, PLUGIN_NAME, PLUGIN_SHORT_DESCRIPTION, capture_log, capture_stdout
from test.helper import TestHelper, Assertions, \
PLUGIN_NAME, PLUGIN_SHORT_DESCRIPTION, PACKAGE_NAME, PACKAGE_TITLE, PLUGIN_VERSION, \
capture_log


class CompletionTest(TestHelper, Assertions):
Expand All @@ -13,17 +15,26 @@ class CompletionTest(TestHelper, Assertions):
"""

def test_application(self):
with capture_stdout() as out:
self.runcli()

self.assertIn(PLUGIN_NAME, out.getvalue())
self.assertIn(PLUGIN_SHORT_DESCRIPTION, out.getvalue())
output = self.runcli()
self.assertIn(PLUGIN_NAME, output)
self.assertIn(PLUGIN_SHORT_DESCRIPTION, output)

def test_application_plugin_list(self):
with capture_stdout() as out:
self.runcli("version")

self.assertIn("plugins: {0}".format(PLUGIN_NAME), out.getvalue())
output = self.runcli("version")
self.assertIn("plugins: {0}".format(PLUGIN_NAME), output)

def test_plugin(self):
self.runcli(PLUGIN_NAME)
with capture_log('beets.yearfixer') as logs:
self.runcli(PLUGIN_NAME)
self.assertIn("Your query did not produce any results.", "\n".join(logs))

def test_plugin_version(self):
with capture_log('beets.yearfixer') as logs:
self.runcli(PLUGIN_NAME, "--version")

versioninfo = "{pt}({pn}) plugin for Beets: v{ver}".format(
pt=PACKAGE_TITLE,
pn=PACKAGE_NAME,
ver=PLUGIN_VERSION
)
self.assertIn(versioninfo, "\n".join(logs))
8 changes: 4 additions & 4 deletions test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
# Values
PLUGIN_NAME = common.plg_ns['__PLUGIN_NAME__']
PLUGIN_SHORT_DESCRIPTION = common.plg_ns['__PLUGIN_SHORT_DESCRIPTION__']
PLUGIN_VERSION = common.plg_ns['__version__']
PACKAGE_NAME = common.plg_ns['__PACKAGE_NAME__']
PACKAGE_TITLE = common.plg_ns['__PACKAGE_TITLE__']


class LogCapture(logging.Handler):
Expand All @@ -52,13 +55,10 @@ def emit(self, record):


@contextmanager
def capture_log(logger='beets', suppress_output=True):
def capture_log(logger='beets'):
capture = LogCapture()
log = logging.getLogger(logger)
log.propagate = True
if suppress_output:
# Is this too violent?
log.handlers = []
log.addHandler(capture)
try:
yield capture.messages
Expand Down

0 comments on commit ee463ba

Please sign in to comment.