From b293d6ad88559db08f249d58e72bfab78277dd83 Mon Sep 17 00:00:00 2001 From: Peter Kessen Date: Fri, 25 Sep 2015 17:41:12 +0200 Subject: [PATCH 1/7] added test for human_seconds --- test/test_ui_commands.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/test_ui_commands.py b/test/test_ui_commands.py index 08f44eb573..e9616ca6ff 100644 --- a/test/test_ui_commands.py +++ b/test/test_ui_commands.py @@ -84,6 +84,32 @@ def test_query_album(self): self.check_do_query(0, 2, album=True, also_items=False) +class InitTest(_common.LibTestCase): + def setUp(self): + super(InitTest, self).setUp() + + self.io.install() + + def tearDown(self): + self.io.restore() + + def test_human_seconds(self): + tests = [ + (0, '0.0 seconds'), + (30, '30.0 seconds'), + (60, '1.0 minutes'), + (90, '1.5 minutes'), + (125, '2.1 minutes'), + (3600, '1.0 hours'), + (86400, '1.0 days'), + (604800, '1.0 weeks'), + (31449600, '1.0 years'), + (314496000, '1.0 decades'), + ] + for i, h in tests: + self.assertEqual(h, ui.human_seconds(i)) + + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) From 40ec848133cad85ed816498b20bab08a2377cb5a Mon Sep 17 00:00:00 2001 From: Peter Kessen Date: Sun, 27 Sep 2015 11:27:07 +0200 Subject: [PATCH 2/7] moved test to other file moved the tests of ui/__init__ to a new test file --- test/test_ui_commands.py | 26 ------------------ test/test_ui_init.py | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 test/test_ui_init.py diff --git a/test/test_ui_commands.py b/test/test_ui_commands.py index b44227edb3..dd8eb47a33 100644 --- a/test/test_ui_commands.py +++ b/test/test_ui_commands.py @@ -113,32 +113,6 @@ def test_fields_func(self): self.assertEqual(len(albums), 0) -class InitTest(_common.LibTestCase): - def setUp(self): - super(InitTest, self).setUp() - - self.io.install() - - def tearDown(self): - self.io.restore() - - def test_human_seconds(self): - tests = [ - (0, '0.0 seconds'), - (30, '30.0 seconds'), - (60, '1.0 minutes'), - (90, '1.5 minutes'), - (125, '2.1 minutes'), - (3600, '1.0 hours'), - (86400, '1.0 days'), - (604800, '1.0 weeks'), - (31449600, '1.0 years'), - (314496000, '1.0 decades'), - ] - for i, h in tests: - self.assertEqual(h, ui.human_seconds(i)) - - def suite(): return unittest.TestLoader().loadTestsFromName(__name__) diff --git a/test/test_ui_init.py b/test/test_ui_init.py new file mode 100644 index 0000000000..19f0b2a047 --- /dev/null +++ b/test/test_ui_init.py @@ -0,0 +1,58 @@ +# -*- coding: utf8 -*- +# This file is part of beets. +# Copyright 2015, Adrian Sampson. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. + +"""Test module for file ui/__init__.py +""" +import os +import shutil + +from test import _common +from test._common import unittest + +from beets import library +from beets import ui + + +class InitTest(_common.LibTestCase): + def setUp(self): + super(InitTest, self).setUp() + + self.io.install() + + def tearDown(self): + self.io.restore() + + def test_human_seconds(self): + tests = [ + (0, '0.0 seconds'), + (30, '30.0 seconds'), + (60, '1.0 minutes'), + (90, '1.5 minutes'), + (125, '2.1 minutes'), + (3600, '1.0 hours'), + (86400, '1.0 days'), + (604800, '1.0 weeks'), + (31449600, '1.0 years'), + (314496000, '1.0 decades'), + ] + for i, h in tests: + self.assertEqual(h, ui.human_seconds(i)) + + +def suite(): + return unittest.TestLoader().loadTestsFromName(__name__) + +if __name__ == b'__main__': + unittest.main(defaultTest='suite') From 8202658706caa0a86e0e277c1a9699e7133f9c79 Mon Sep 17 00:00:00 2001 From: Peter Kessen Date: Sun, 27 Sep 2015 11:51:21 +0200 Subject: [PATCH 3/7] added test for human_bytes --- test/test_ui_init.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test_ui_init.py b/test/test_ui_init.py index 19f0b2a047..3879c75fbd 100644 --- a/test/test_ui_init.py +++ b/test/test_ui_init.py @@ -34,6 +34,24 @@ def setUp(self): def tearDown(self): self.io.restore() + def test_human_bytes(self): + tests = [ + (0, '0.0 B'), + (30, '30.0 B'), + (pow(2, 10), '1.0 KB'), + (pow(2, 20), '1.0 MB'), + (pow(2, 30), '1.0 GB'), + (pow(2, 40), '1.0 TB'), + (pow(2, 50), '1.0 PB'), + (pow(2, 60), '1.0 EB'), + (pow(2, 70), '1.0 ZB'), + (pow(2, 80), '1.0 YB'), + (pow(2, 90), '1.0 HB'), + (pow(2, 100), 'big'), + ] + for i, h in tests: + self.assertEqual(h, ui.human_bytes(i)) + def test_human_seconds(self): tests = [ (0, '0.0 seconds'), From 770e89ab656c826ca8ac1b84e53e9edb2698219e Mon Sep 17 00:00:00 2001 From: Peter Kessen Date: Sun, 27 Sep 2015 12:04:42 +0200 Subject: [PATCH 4/7] fixed suggestions by travis --- test/test_ui_init.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/test_ui_init.py b/test/test_ui_init.py index 3879c75fbd..fa205a306e 100644 --- a/test/test_ui_init.py +++ b/test/test_ui_init.py @@ -15,13 +15,9 @@ """Test module for file ui/__init__.py """ -import os -import shutil - from test import _common from test._common import unittest -from beets import library from beets import ui From 9adb398198aa790067ffbb53debfd4dc63949ada Mon Sep 17 00:00:00 2001 From: Peter Kessen Date: Sun, 27 Sep 2015 12:16:15 +0200 Subject: [PATCH 5/7] removed useless io handler in test --- test/test_ui_init.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/test_ui_init.py b/test/test_ui_init.py index fa205a306e..15f1f89557 100644 --- a/test/test_ui_init.py +++ b/test/test_ui_init.py @@ -25,11 +25,6 @@ class InitTest(_common.LibTestCase): def setUp(self): super(InitTest, self).setUp() - self.io.install() - - def tearDown(self): - self.io.restore() - def test_human_bytes(self): tests = [ (0, '0.0 B'), From fffb72703305392fdf184bb76c31b695094e0c0e Mon Sep 17 00:00:00 2001 From: Peter Kessen Date: Tue, 29 Sep 2015 17:33:54 +0200 Subject: [PATCH 6/7] corrected output of file size using unit e.g. 5.4 KiB instead of 5.4 KB now --- beets/ui/__init__.py | 8 +++++--- test/test_ui_init.py | 18 +++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 9afe5d6ab6..768eb76c78 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -329,11 +329,13 @@ def input_yn(prompt, require=False): def human_bytes(size): """Formats size, a number of bytes, in a human-readable way.""" - suffices = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB', 'HB'] - for suffix in suffices: + powers = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'H'] + unit = 'B' + for power in powers: if size < 1024: - return "%3.1f %s" % (size, suffix) + return "%3.1f %s%s" % (size, power, unit) size /= 1024.0 + unit = 'iB' return "big" diff --git a/test/test_ui_init.py b/test/test_ui_init.py index 15f1f89557..f31deefe77 100644 --- a/test/test_ui_init.py +++ b/test/test_ui_init.py @@ -29,15 +29,15 @@ def test_human_bytes(self): tests = [ (0, '0.0 B'), (30, '30.0 B'), - (pow(2, 10), '1.0 KB'), - (pow(2, 20), '1.0 MB'), - (pow(2, 30), '1.0 GB'), - (pow(2, 40), '1.0 TB'), - (pow(2, 50), '1.0 PB'), - (pow(2, 60), '1.0 EB'), - (pow(2, 70), '1.0 ZB'), - (pow(2, 80), '1.0 YB'), - (pow(2, 90), '1.0 HB'), + (pow(2, 10), '1.0 KiB'), + (pow(2, 20), '1.0 MiB'), + (pow(2, 30), '1.0 GiB'), + (pow(2, 40), '1.0 TiB'), + (pow(2, 50), '1.0 PiB'), + (pow(2, 60), '1.0 EiB'), + (pow(2, 70), '1.0 ZiB'), + (pow(2, 80), '1.0 YiB'), + (pow(2, 90), '1.0 HiB'), (pow(2, 100), 'big'), ] for i, h in tests: From b980c609412f46507102e1f4b4e49d30f0cc7321 Mon Sep 17 00:00:00 2001 From: Peter Kessen Date: Tue, 29 Sep 2015 17:40:57 +0200 Subject: [PATCH 7/7] corrected another testcase for previous commit --- test/test_ui.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_ui.py b/test/test_ui.py index 0685742ec1..c1c853e035 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -1012,14 +1012,14 @@ def test_summarize_items(self): i2 = deepcopy(self.item) summary = commands.summarize_items([self.item, i2], False) - self.assertEqual(summary, "2 items, F, 4kbps, 21:48, 1.9 KB") + self.assertEqual(summary, "2 items, F, 4kbps, 21:48, 1.9 KiB") i2.format = "G" summary = commands.summarize_items([self.item, i2], False) - self.assertEqual(summary, "2 items, F 1, G 1, 4kbps, 21:48, 1.9 KB") + self.assertEqual(summary, "2 items, F 1, G 1, 4kbps, 21:48, 1.9 KiB") summary = commands.summarize_items([self.item, i2, i2], False) - self.assertEqual(summary, "3 items, G 2, F 1, 4kbps, 32:42, 2.9 KB") + self.assertEqual(summary, "3 items, G 2, F 1, 4kbps, 32:42, 2.9 KiB") class PathFormatTest(_common.TestCase):