Skip to content

Commit

Permalink
checking config and listing
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Jakab committed Feb 18, 2020
1 parent 8251fd8 commit ffe68d4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
5 changes: 2 additions & 3 deletions beetsplug/goingrunning.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ def _get_config_value_bubble_up(target: Subview, attrib: str):
return value

def _say(self, msg):
log.debug(msg)
if not self.quiet:
log.info(msg)
else:
log.debug(msg)
print(msg)
35 changes: 29 additions & 6 deletions test/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from beetsplug import goingrunning

_PLUGIN_NAME_ = 'goingrunning'
_PLUGIN_SHORT_DESCRIPTION_ = 'bring some music with you that matches your training'


class CompletionTest(TestHelper):
Expand All @@ -19,13 +20,17 @@ class CompletionTest(TestHelper):
"""

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

self.assertIn(_PLUGIN_NAME_, out.getvalue())
self.assertIn(_PLUGIN_SHORT_DESCRIPTION_, out.getvalue())

def test_plugin(self):
self.runcli(_PLUGIN_NAME_)


class ModuleTest(TestCase):
class ModuleTest(TestHelper):

def test_must_have_training_keys(self):
must_have_keys = ['song_bpm', 'song_len', 'duration', 'target']
Expand All @@ -42,16 +47,34 @@ def test_log_interface(self):

self.assertIn('{0}: {1}'.format(_PLUGIN_NAME_, msg), '\n'.join(logs))



def test_get_beets_global_config(self):
beets_cfg = beets_global_config
plg_cfg = goingrunning.get_beets_global_config()
self.assertEqual(beets_cfg, plg_cfg)

def test_human_readable_time(self):
s = goingrunning.get_human_readable_time(0)
self.assertEqual(s, "0:00:00", "Bad Time!")
self.assertEqual(goingrunning.get_human_readable_time(0), "0:00:00", "Bad Time!")
self.assertEqual(goingrunning.get_human_readable_time(30), "0:00:30", "Bad Time!")
self.assertEqual(goingrunning.get_human_readable_time(90), "0:01:30", "Bad Time!")
self.assertEqual(goingrunning.get_human_readable_time(600), "0:10:00", "Bad Time!")


class ConfigurationTest(TestHelper):

def test_training_listing_long(self):
with capture_stdout() as out:
self.runcli(_PLUGIN_NAME_, "--list")

self.assertIn("You have not created any trainings yet.", out.getvalue())

def test_training_listing_short(self):
with capture_stdout() as out:
self.runcli(_PLUGIN_NAME_, "-l")

self.assertIn("You have not created any trainings yet.", out.getvalue())






Expand Down
3 changes: 2 additions & 1 deletion test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def capture_log(logger='beets', suppress_output=True):


@contextmanager
def capture_stdout():
def capture_stdout(suppress_output=True):
"""Save stdout in a StringIO.
>>> with capture_stdout() as output:
... print('spam')
Expand All @@ -73,6 +73,7 @@ def capture_stdout():
yield sys.stdout
finally:
sys.stdout = org
#if not suppress_output:
print(capture.getvalue())


Expand Down

0 comments on commit ffe68d4

Please sign in to comment.