From 003676e10fffff257137cd60bf806d61ad4071e2 Mon Sep 17 00:00:00 2001 From: Adam Jakab Date: Wed, 18 Mar 2020 19:37:19 +0100 Subject: [PATCH] moving logging around --- beetsplug/goingrunning/command.py | 67 ++++----- beetsplug/goingrunning/common.py | 13 +- test/functional/000_basic_test.py | 29 ++-- test/functional/001_configuration_test.py | 5 +- test/functional/002_command_test.py | 159 +++++++++------------- test/helper.py | 12 +- test/unit/000_common_test.py | 21 ++- 7 files changed, 138 insertions(+), 168 deletions(-) diff --git a/beetsplug/goingrunning/command.py b/beetsplug/goingrunning/command.py index cbf4cd4..564d49a 100644 --- a/beetsplug/goingrunning/command.py +++ b/beetsplug/goingrunning/command.py @@ -6,15 +6,14 @@ # import operator -import random import os +import random import string -from sys import stdout +from glob import glob from optparse import OptionParser from pathlib import Path - from shutil import copyfile -from glob import glob + from beets.dbcore.db import Results from beets.dbcore.queryparse import parse_query_part from beets.library import Library, Item, parse_query_string @@ -30,7 +29,6 @@ class GoingRunningCommand(Subcommand): - log = None config: Subview = None lib: Library = None query = None @@ -42,7 +40,6 @@ class GoingRunningCommand(Subcommand): def __init__(self, cfg): self.config = cfg - self.log = common.get_beets_logger() self.parser = OptionParser(usage='beet goingrunning [training] [options] [QUERY...]') @@ -110,14 +107,11 @@ def func(self, lib: Library, options, arguments): self._say("* I promise it will not happen again ;)") self._say("* " + str(e)) self._say("* The plugin will exit now.") - self._say("*" * 80) + common.say("*" * 80) return # You must either pass a training name or request listing if len(self.query) < 1 and not (options.list or options.version): - self.log.warning( - "You can either pass the name of a training or request a " - "listing (--list)!") self.parser.print_help() return @@ -208,7 +202,7 @@ def _clean_target_path(self, training: Subview): os.path.join(dst_path, "*.{}".format(ext))) for f in target_file_list: - self.log.debug("Deleting: {}".format(f)) + self._say("Deleting: {}".format(f), log_only=True) os.remove(f) additional_files = self._get_target_attribute_for_training(training, @@ -225,11 +219,10 @@ def _clean_target_path(self, training: Subview): dst_path = os.path.realpath(root.joinpath(path)) if not os.path.isfile(dst_path): - self.log.debug( - "The file to delete does not exist: {0}".format(path)) + self._say("The file to delete does not exist: {0}".format(path), log_only=True) continue - self.log.debug("Deleting: {}".format(dst_path)) + self._say("Deleting: {}".format(dst_path), log_only=True) os.remove(dst_path) def _copy_items_to_target(self, training: Subview, rnd_items): @@ -246,20 +239,20 @@ def random_string(length=6): src = os.path.realpath(item.get("path").decode("utf-8")) if not os.path.isfile(src): # todo: this is bad enough to interrupt! create option for this - self.log.warning("File does not exist: {}".format(src)) + self._say("File does not exist: {}".format(src)) continue fn, ext = os.path.splitext(src) gen_filename = "{0}_{1}{2}".format(str(cnt).zfill(6), random_string(), ext) dst = "{0}/{1}".format(dst_path, gen_filename) - self.log.debug("Copying[{1}]: {0}".format(src, gen_filename)) + self._say("Copying[{1}]: {0}".format(src, gen_filename), log_only=True) copyfile(src, dst) cnt += 1 def _get_target_for_training(self, training: Subview): target_name = common.get_training_attribute(training, "target") - self.log.debug("Finding target: {0}".format(target_name)) + self._say("Finding target: {0}".format(target_name), log_only=True) if not self.config["targets"][target_name].exists(): self._say("The target name[{0}] is not defined!".format(target_name)) @@ -269,8 +262,8 @@ def _get_target_for_training(self, training: Subview): def _get_target_attribute_for_training(self, training: Subview, attrib: str = "name"): target_name = common.get_training_attribute(training, "target") - self.log.debug("Getting attribute[{0}] for target: {1}".format(attrib, - target_name)) + self._say("Getting attribute[{0}] for target: {1}".format(attrib, + target_name), log_only=True) target = self._get_target_for_training(training) if not target: return @@ -286,8 +279,8 @@ def _get_target_attribute_for_training(self, training: Subview, attrib: str = "n else: attrib_val = common.get_target_attribute(target, attrib) - self.log.debug( - "Found target[{0}] attribute[{1}] path: {2}".format(target_name, attrib, attrib_val)) + self._say( + "Found target[{0}] attribute[{1}] path: {2}".format(target_name, attrib, attrib_val), log_only=True) return attrib_val @@ -313,8 +306,8 @@ def _get_destination_path_for_training(self, training: Subview): dst_path)) return - self.log.debug( - "Found target[{0}] path: {0}".format(target_name, dst_path)) + self._say( + "Found target[{0}] path: {0}".format(target_name, dst_path), log_only=True) return dst_path @@ -333,8 +326,8 @@ def _get_items_for_duration(self, items, duration): else: bin_size = 0 - self.log.debug("Estimated number of songs: {}".format(est_num_songs)) - self.log.debug("Bin Size: {}".format(bin_size)) + self._say("Estimated number of songs: {}".format(est_num_songs), log_only=True) + self._say("Bin Size: {}".format(bin_size), log_only=True) for i in range(0, est_num_songs): bin_start = round(i * bin_size) @@ -368,12 +361,12 @@ def _gather_query_elements(self, training: Subview): flavour: Subview = self.config["flavours"][flavour_name] flavour_query += common.get_flavour_elements(flavour) - self.log.debug("Command query elements: {}".format(command_query)) - self.log.debug("Training query elements: {}".format(training_query)) - self.log.debug("Flavour query elements: {}".format(flavour_query)) + self._say("Command query elements: {}".format(command_query), log_only=True) + self._say("Training query elements: {}".format(training_query), log_only=True) + self._say("Flavour query elements: {}".format(flavour_query), log_only=True) raw_combined_query = command_query + training_query + flavour_query - self.log.debug("Raw combined query elements: {}".format(raw_combined_query)) + self._say("Raw combined query elements: {}".format(raw_combined_query), log_only=True) # Remove duplicate keys combined_query = [] @@ -384,14 +377,14 @@ def _gather_query_elements(self, training: Subview): used_keys.append(key) combined_query.append(query_part) - self.log.debug("Clean combined query elements: {}".format(combined_query)) + self._say("Clean combined query elements: {}".format(combined_query), log_only=True) return combined_query def _retrieve_library_items(self, training: Subview): full_query = self._gather_query_elements(training) parsed_query = parse_query_string(" ".join(full_query), Item)[0] - self.log.debug("Song selection query: {}".format(parsed_query)) + self._say("Song selection query: {}".format(parsed_query), log_only=True) return self.lib.items(parsed_query) @@ -429,7 +422,7 @@ def list_trainings(self): def list_training_attributes(self, training_name: str): if not self.config["trainings"].exists() or not self.config["trainings"][training_name].exists(): - self.log.debug("Training[{0}] does not exist.".format(training_name)) + self._say("Training[{0}] does not exist.".format(training_name), log_only=True) return training: Subview = self.config["trainings"][training_name] @@ -465,10 +458,6 @@ def verify_configuration_upgrade(self): if tkey in ["song_bpm", "song_len"]: raise RuntimeError("Offending key in training({}): {}".format(training_name, tkey)) - def _say(self, msg): - """Log and write to stdout - """ - self.log.debug(msg) - if not self.cfg_quiet: - print(msg) - # stdout.write(msg + "\n") + def _say(self, msg, log_only=False): + log_only = True if self.cfg_quiet else log_only + common.say(msg, log_only) diff --git a/beetsplug/goingrunning/common.py b/beetsplug/goingrunning/common.py index f95fcd6..b6b4f33 100644 --- a/beetsplug/goingrunning/common.py +++ b/beetsplug/goingrunning/common.py @@ -6,6 +6,7 @@ # import logging +import sys from beets.library import Item from beets.util.confit import Subview @@ -20,15 +21,23 @@ KNOWN_TEXTUAL_FLEX_ATTRIBUTES = ["gender", "genre_rosamerica", "rhythm", "voice_instrumental", "chords_key", "chords_scale"] +__logger__ = logging.getLogger('beets.goingrunning') + + +def say(msg, log_only=False): + """Log and write to stdout + """ + __logger__.debug(msg) + if not log_only: + sys.stdout.write(msg + "\n") -def get_beets_logger(): - return logging.getLogger('beets.goingrunning') def get_human_readable_time(seconds): m, s = divmod(seconds, 60) h, m = divmod(m, 60) return "%d:%02d:%02d" % (h, m, s) + def get_beet_query_formatted_string(key, val): quote_val = type(val) == str and " " in val fmt = "{k}:'{v}'" if quote_val else "{k}:{v}" diff --git a/test/functional/000_basic_test.py b/test/functional/000_basic_test.py index e6c1669..733cc9d 100644 --- a/test/functional/000_basic_test.py +++ b/test/functional/000_basic_test.py @@ -7,8 +7,7 @@ from test.helper import ( FunctionalTestHelper, Assertions, - PLUGIN_NAME, PLUGIN_SHORT_NAME, PLUGIN_SHORT_DESCRIPTION, - capture_log, capture_stdout + PLUGIN_NAME, PLUGIN_SHORT_NAME, PLUGIN_SHORT_DESCRIPTION ) @@ -18,28 +17,20 @@ class BasicTest(FunctionalTestHelper, 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()) + stdout = self.run_with_output() + self.assertIn(PLUGIN_NAME, stdout) + self.assertIn(PLUGIN_SHORT_DESCRIPTION, stdout) def test_application_version(self): - with capture_stdout() as out: - self.runcli("version") - - self.assertIn("plugins: {0}".format(PLUGIN_NAME), out.getvalue()) + stdout = self.run_with_output("version") + self.assertIn("plugins: {0}".format(PLUGIN_NAME), stdout) def test_plugin_no_arguments(self): self.reset_beets(config_file=b"empty.yml") - with capture_stdout() as out: - self.runcli(PLUGIN_NAME) - - self.assertIn("Usage: beet goingrunning [training] [options] [QUERY...]", out.getvalue()) + stdout = self.run_with_output(PLUGIN_NAME) + self.assertIn("Usage: beet goingrunning [training] [options] [QUERY...]", stdout) def test_plugin_shortname_no_arguments(self): self.reset_beets(config_file=b"empty.yml") - with capture_stdout() as out: - self.runcli(PLUGIN_SHORT_NAME) - - self.assertIn("Usage: beet goingrunning [training] [options] [QUERY...]", out.getvalue()) + stdout = self.run_with_output(PLUGIN_SHORT_NAME) + self.assertIn("Usage: beet goingrunning [training] [options] [QUERY...]", stdout) diff --git a/test/functional/001_configuration_test.py b/test/functional/001_configuration_test.py index 4e481fd..30613ec 100644 --- a/test/functional/001_configuration_test.py +++ b/test/functional/001_configuration_test.py @@ -7,8 +7,7 @@ from beets.util.confit import Subview -from test.helper import FunctionalTestHelper, Assertions, PLUGIN_NAME, PLUGIN_SHORT_DESCRIPTION, capture_log, \ - capture_stdout +from test.helper import FunctionalTestHelper, Assertions, PLUGIN_NAME class ConfigurationTest(FunctionalTestHelper, Assertions): @@ -27,9 +26,7 @@ def test_plugin_no_config(self): def test_obsolete_config(self): self.reset_beets(config_file=b"obsolete.yml") - stdout = self.run_with_output(PLUGIN_NAME) - self.assertIn("INCOMPATIBLE PLUGIN CONFIGURATION", stdout) self.assertIn("Offending key in training(training-1): song_bpm", stdout) diff --git a/test/functional/002_command_test.py b/test/functional/002_command_test.py index 91b8e9a..56af20a 100644 --- a/test/functional/002_command_test.py +++ b/test/functional/002_command_test.py @@ -5,10 +5,8 @@ # License: See LICENSE.txt # -from beets.util.confit import Subview - -from test.helper import FunctionalTestHelper, Assertions, PLUGIN_NAME, PLUGIN_SHORT_DESCRIPTION, capture_log, \ - capture_stdout, get_single_line_from_output, get_value_separated_from_output, convert_time_to_seconds +from test.helper import FunctionalTestHelper, Assertions, PLUGIN_NAME, get_single_line_from_output, \ + get_value_separated_from_output, convert_time_to_seconds class CommandTest(FunctionalTestHelper, Assertions): @@ -16,77 +14,63 @@ class CommandTest(FunctionalTestHelper, Assertions): """ def test_plugin_version(self): - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, "--version") - from beetsplug.goingrunning.version import __version__ - self.assertIn("Goingrunning(beets-{})".format(PLUGIN_NAME), out.getvalue()) - self.assertIn("v{}".format(__version__), out.getvalue()) + + stdout = self.run_with_output(PLUGIN_NAME, "--version") + self.assertIn("Goingrunning(beets-{})".format(PLUGIN_NAME), stdout) + self.assertIn("v{}".format(__version__), stdout) + + stdout = self.run_with_output(PLUGIN_NAME, "-v") + self.assertIn("Goingrunning(beets-{})".format(PLUGIN_NAME), stdout) + self.assertIn("v{}".format(__version__), stdout) def test_training_listing_empty(self): self.reset_beets(config_file=b"empty.yml") - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, "--list") - self.assertIn("You have not created any trainings yet.", out.getvalue()) + stdout = self.run_with_output(PLUGIN_NAME, "--list") + self.assertIn("You have not created any trainings yet.", stdout) - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, "-l") - self.assertIn("You have not created any trainings yet.", out.getvalue()) + stdout = self.run_with_output(PLUGIN_NAME, "-l") + self.assertIn("You have not created any trainings yet.", stdout) def test_training_listing_default(self): - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, "--list") - - output = out.getvalue() - self.assertIn("::: training-1", output) - self.assertIn("::: training-2", output) - self.assertIn("::: training-3", output) + stdout = self.run_with_output(PLUGIN_NAME, "--list") + self.assertIn("::: training-1", stdout) + self.assertIn("::: training-2", stdout) + self.assertIn("::: training-3", stdout) def test_training_handling_inexistent(self): training_name = "sitting_on_the_sofa" - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, training_name) - - self.assertIn("There is no training[{0}] registered with this name!".format(training_name), out.getvalue()) + stdout = self.run_with_output(PLUGIN_NAME, training_name) + self.assertIn("There is no training[{0}] registered with this name!".format(training_name), stdout) def test_training_song_count(self): training_name = "training-1" - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, training_name, "--count") - self.assertIn("Number of songs available: {}".format(0), out.getvalue()) + stdout = self.run_with_output(PLUGIN_NAME, training_name, "--count") + self.assertIn("Number of songs available: {}".format(0), stdout) - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, training_name, "-c") - self.assertIn("Number of songs available: {}".format(0), out.getvalue()) + stdout = self.run_with_output(PLUGIN_NAME, training_name, "-c") + self.assertIn("Number of songs available: {}".format(0), stdout) def test_training_no_songs(self): training_name = "training-1" - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, training_name) - - self.assertIn("Handling training: {0}".format(training_name), out.getvalue()) - self.assertIn("There are no songs in your library that match this training!", out.getvalue()) + stdout = self.run_with_output(PLUGIN_NAME, training_name) + self.assertIn("Handling training: {0}".format(training_name), stdout) + self.assertIn("There are no songs in your library that match this training!", stdout) def test_training_undefined_target(self): self.add_single_item_to_library() - training_name = "bad-target-1" - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, training_name) - + stdout = self.run_with_output(PLUGIN_NAME, training_name) target_name = "inexistent_target" - self.assertIn("The target name[{0}] is not defined!".format(target_name), out.getvalue()) + self.assertIn("The target name[{0}] is not defined!".format(target_name), stdout) def test_training_bad_target(self): self.add_single_item_to_library() - training_name = "bad-target-2" - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, training_name) - + stdout = self.run_with_output(PLUGIN_NAME, training_name) target_name = "MPD_3" target_path = "/media/this/probably/does/not/exist/" - self.assertIn("The target[{0}] path does not exist: {1}".format(target_name, target_path), out.getvalue()) + self.assertIn("The target[{0}] path does not exist: {1}".format(target_name, target_path), stdout) def test_handling_training_1(self): """Simple query based song selection @@ -98,8 +82,7 @@ def test_handling_training_1(self): self.ensure_training_target_path(training_name) - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, training_name) + stdout = self.run_with_output(PLUGIN_NAME, training_name) """ Output for "training-1": @@ -117,40 +100,38 @@ def test_handling_training_1(self): """ - output = out.getvalue() - prefix = "Handling training:" - self.assertIn(prefix, output) - value = get_value_separated_from_output(output, prefix) + self.assertIn(prefix, stdout) + value = get_value_separated_from_output(stdout, prefix) self.assertEqual(training_name, value) prefix = "Available songs:" - self.assertIn(prefix, output) - value = int(get_value_separated_from_output(output, prefix)) + self.assertIn(prefix, stdout) + value = int(get_value_separated_from_output(stdout, prefix)) self.assertEqual(10, value) prefix = "Selected songs:" - self.assertIn(prefix, output) - value = int(get_value_separated_from_output(output, prefix)) + self.assertIn(prefix, stdout) + value = int(get_value_separated_from_output(stdout, prefix)) self.assertGreater(value, 0) self.assertLessEqual(value, 10) prefix = "Planned training duration:" - self.assertIn(prefix, output) - value = get_value_separated_from_output(output, prefix) + self.assertIn(prefix, stdout) + value = get_value_separated_from_output(stdout, prefix) seconds = convert_time_to_seconds(value) self.assertEqual("0:10:00", value) self.assertEqual(600, seconds) # Do not test for efficiency here prefix = "Total song duration:" - self.assertIn(prefix, output) - value = get_value_separated_from_output(output, prefix) + self.assertIn(prefix, stdout) + value = get_value_separated_from_output(stdout, prefix) seconds = convert_time_to_seconds(value) self.assertGreater(seconds, 0) prefix = "Run!" - line = get_single_line_from_output(output, prefix) + line = get_single_line_from_output(stdout, prefix) self.assertEqual(prefix, line) def test_handling_training_2(self): @@ -176,8 +157,7 @@ def test_handling_training_2(self): self.ensure_training_target_path(training_name) - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, training_name) + stdout = self.run_with_output(PLUGIN_NAME, training_name) """ Output for "training-2": @@ -196,40 +176,38 @@ def test_handling_training_2(self): """ - output = out.getvalue() - prefix = "Handling training:" - self.assertIn(prefix, output) - value = get_value_separated_from_output(output, prefix) + self.assertIn(prefix, stdout) + value = get_value_separated_from_output(stdout, prefix) self.assertEqual(training_name, value) prefix = "Available songs:" - self.assertIn(prefix, output) - value = int(get_value_separated_from_output(output, prefix)) + self.assertIn(prefix, stdout) + value = int(get_value_separated_from_output(stdout, prefix)) self.assertEqual(10, value) prefix = "Selected songs:" - self.assertIn(prefix, output) - value = int(get_value_separated_from_output(output, prefix)) + self.assertIn(prefix, stdout) + value = int(get_value_separated_from_output(stdout, prefix)) self.assertGreater(value, 0) self.assertLessEqual(value, 10) prefix = "Planned training duration:" - self.assertIn(prefix, output) - value = get_value_separated_from_output(output, prefix) + self.assertIn(prefix, stdout) + value = get_value_separated_from_output(stdout, prefix) seconds = convert_time_to_seconds(value) self.assertEqual("0:10:00", value) self.assertEqual(600, seconds) # Do not test for efficiency here prefix = "Total song duration:" - self.assertIn(prefix, output) - value = get_value_separated_from_output(output, prefix) + self.assertIn(prefix, stdout) + value = get_value_separated_from_output(stdout, prefix) seconds = convert_time_to_seconds(value) self.assertGreater(seconds, 0) prefix = "Run!" - line = get_single_line_from_output(output, prefix) + line = get_single_line_from_output(stdout, prefix) self.assertEqual(prefix, line) def test_handling_training_3(self): @@ -259,8 +237,7 @@ def test_handling_training_3(self): self.ensure_training_target_path(training_name) - with capture_stdout() as out: - self.runcli(PLUGIN_NAME, training_name) + stdout = self.run_with_output(PLUGIN_NAME, training_name) """ Output for "training-2": @@ -279,38 +256,36 @@ def test_handling_training_3(self): """ - output = out.getvalue() - prefix = "Handling training:" - self.assertIn(prefix, output) - value = get_value_separated_from_output(output, prefix) + self.assertIn(prefix, stdout) + value = get_value_separated_from_output(stdout, prefix) self.assertEqual(training_name, value) prefix = "Available songs:" - self.assertIn(prefix, output) - value = int(get_value_separated_from_output(output, prefix)) + self.assertIn(prefix, stdout) + value = int(get_value_separated_from_output(stdout, prefix)) self.assertEqual(10, value) prefix = "Selected songs:" - self.assertIn(prefix, output) - value = int(get_value_separated_from_output(output, prefix)) + self.assertIn(prefix, stdout) + value = int(get_value_separated_from_output(stdout, prefix)) self.assertGreater(value, 0) self.assertLessEqual(value, 10) prefix = "Planned training duration:" - self.assertIn(prefix, output) - value = get_value_separated_from_output(output, prefix) + self.assertIn(prefix, stdout) + value = get_value_separated_from_output(stdout, prefix) seconds = convert_time_to_seconds(value) self.assertEqual("0:10:00", value) self.assertEqual(600, seconds) # Do not test for efficiency here prefix = "Total song duration:" - self.assertIn(prefix, output) - value = get_value_separated_from_output(output, prefix) + self.assertIn(prefix, stdout) + value = get_value_separated_from_output(stdout, prefix) seconds = convert_time_to_seconds(value) self.assertGreater(seconds, 0) prefix = "Run!" - line = get_single_line_from_output(output, prefix) + line = get_single_line_from_output(stdout, prefix) self.assertEqual(prefix, line) diff --git a/test/helper.py b/test/helper.py index f3a30f1..f2aa8d7 100644 --- a/test/helper.py +++ b/test/helper.py @@ -6,7 +6,6 @@ # # References: https://docs.python.org/3/library/unittest.html # -import json import os import shutil import sys @@ -25,7 +24,6 @@ from beets.library import Item # from beets.mediafile import MediaFile from beets.util import ( - MoveOperation, syspath, bytestring_path, displayable_path, @@ -60,9 +58,9 @@ def capture_log(logger='beets', suppress_output=True): capture = LogCapture() log = logging.getLogger(logger) log.propagate = True - if suppress_output: - # Is this too violent? - log.handlers = [] + # if suppress_output: + # Is this too violent? + # log.handlers = [] log.addHandler(capture) try: yield capture.messages @@ -243,7 +241,7 @@ def _setup_beets(self, config_file: bytes, beet_files: list = None): self.config.read() self.config['plugins'] = [] - self.config['verbose'] = False + self.config['verbose'] = True self.config['ui']['color'] = False self.config['threaded'] = False self.config['import']['copy'] = False @@ -398,7 +396,7 @@ def create_item(self, **values): item = Item(**values_) if 'path' not in values: - item['path'] = 'audio.' + item['format'].lower() + item['path'] = 'test/fixtures/song.' + item['format'].lower() # mtime needs to be set last since other assignments reset it. item.mtime = 12345 diff --git a/test/unit/000_common_test.py b/test/unit/000_common_test.py index 5982031..28415c1 100644 --- a/test/unit/000_common_test.py +++ b/test/unit/000_common_test.py @@ -5,11 +5,11 @@ # License: See LICENSE.txt # -from test.helper import UnitTestHelper, Assertions, get_plugin_configuration -from beetsplug.goingrunning import common - from logging import Logger +from beetsplug.goingrunning import common +from test.helper import UnitTestHelper, Assertions, get_plugin_configuration, capture_stdout + class CommonTest(UnitTestHelper, Assertions): """Test methods in the beetsplug.goingrunning.common module @@ -20,9 +20,20 @@ def test_module_values(self): self.assertTrue(hasattr(common, "MUST_HAVE_TARGET_KEYS")) self.assertTrue(hasattr(common, "KNOWN_NUMERIC_FLEX_ATTRIBUTES")) self.assertTrue(hasattr(common, "KNOWN_TEXTUAL_FLEX_ATTRIBUTES")) + self.assertTrue(hasattr(common, "__logger__")) + self.assertIsInstance(common.__logger__, Logger) + + def test_say(self): + test_message = "one two three" + + with capture_stdout() as out: + common.say(test_message) + self.assertIn(test_message, out.getvalue()) - def test_get_beets_logger(self): - self.assertIsInstance(common.get_beets_logger(), Logger) + # todo: make it work + # with capture_log() as logs: + # common.say(test_message) + # self.assertIn(test_message, '\n'.join(logs)) def test_get_beets_global_config(self): self.assertEqual("0:00:00", common.get_human_readable_time(0), "Bad time format!")