From a52c3e8e12ef6bc0fc7066a852e60857bb7da8ca Mon Sep 17 00:00:00 2001 From: Frank Scherrer Date: Tue, 4 Sep 2018 09:24:12 +0200 Subject: [PATCH 1/2] add further tests for which * test which for always present binary "ls" * test which for garbage input --- tests/test_util.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_util.py b/tests/test_util.py index 64c320f..1aaeaef 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -55,11 +55,19 @@ class TestUtil(unittest.TestCase): execute(self.some_command_with_args) def test_which(self): + # test for a binary that has to be somewhere + print(which("ls")) + self.assertTrue(re.search('/(ls)$', which("ls"))) + + # test for a binary that is not necessarily there program = "iwgetid" self.assertTrue( which(program) is None or re.search('/(' + program + ')$', which(program)) ) + # test if which also works with garbage input + self.assertTrue(which("qwertygarbage") is None) + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From a6eb5a43a588df6d4429ea21ef6ca77c472a6bfd Mon Sep 17 00:00:00 2001 From: Frank Scherrer Date: Tue, 4 Sep 2018 09:57:29 +0200 Subject: [PATCH 2/2] fix code for flake8 linter --- tests/test_util.py | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/test_util.py b/tests/test_util.py index 1aaeaef..07d6d3a 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,12 +1,12 @@ # pylint: disable=C0103,C0111 -import mock import unittest import re import tests.mocks as mocks -from bumblebee.util import * +import bumblebee.util as bu + class TestUtil(unittest.TestCase): def setUp(self): @@ -18,56 +18,56 @@ class TestUtil(unittest.TestCase): self.popen.cleanup() def test_bytefmt(self): - self.assertEquals(bytefmt(10), "10.00B") - self.assertEquals(bytefmt(15*1024), "15.00KiB") - self.assertEquals(bytefmt(20*1024*1024), "20.00MiB") - self.assertEquals(bytefmt(22*1024*1024*1024), "22.00GiB") - self.assertEquals(bytefmt(35*1024*1024*1024*1024), "35840.00GiB") + self.assertEquals(bu.bytefmt(10), "10.00B") + self.assertEquals(bu.bytefmt(15 * 1024), "15.00KiB") + self.assertEquals(bu.bytefmt(20 * 1024 * 1024), "20.00MiB") + self.assertEquals(bu.bytefmt(22 * 1024 * 1024 * 1024), "22.00GiB") + self.assertEquals(bu.bytefmt(35 * 1024 * 1024 * 1024 * 1024), "35840.00GiB") def test_durationfmt(self): - self.assertEquals(durationfmt(00), "00:00") - self.assertEquals(durationfmt(25), "00:25") - self.assertEquals(durationfmt(60), "01:00") - self.assertEquals(durationfmt(119), "01:59") - self.assertEquals(durationfmt(3600), "01:00:00") - self.assertEquals(durationfmt(7265), "02:01:05") + self.assertEquals(bu.durationfmt(00), "00:00") + self.assertEquals(bu.durationfmt(25), "00:25") + self.assertEquals(bu.durationfmt(60), "01:00") + self.assertEquals(bu.durationfmt(119), "01:59") + self.assertEquals(bu.durationfmt(3600), "01:00:00") + self.assertEquals(bu.durationfmt(7265), "02:01:05") def test_execute(self): - execute(self.some_command_with_args) + bu.execute(self.some_command_with_args) self.assertTrue(self.popen.mock.popen.called) self.popen.mock.popen.assert_call(self.some_command_with_args) self.assertTrue(self.popen.mock.communicate.called) def test_execute_nowait(self): - execute(self.some_command_with_args, False) + bu.execute(self.some_command_with_args, False) self.assertTrue(self.popen.mock.popen.called) self.popen.mock.popen.assert_call(self.some_command_with_args) self.assertFalse(self.popen.mock.communicate.called) def test_execute_utf8(self): - self.popen.mock.communicate.return_value = [ self.some_utf8, None ] + self.popen.mock.communicate.return_value = [self.some_utf8, None] self.test_execute() def test_execute_error(self): self.popen.mock.returncode = 1 with self.assertRaises(RuntimeError): - execute(self.some_command_with_args) + bu.execute(self.some_command_with_args) def test_which(self): # test for a binary that has to be somewhere - print(which("ls")) - self.assertTrue(re.search('/(ls)$', which("ls"))) + print(bu.which("ls")) + self.assertTrue(re.search('/(ls)$', bu.which("ls"))) # test for a binary that is not necessarily there program = "iwgetid" self.assertTrue( - which(program) is None or - re.search('/(' + program + ')$', which(program)) + bu.which(program) is None or + re.search('/(' + program + ')$', bu.which(program)) ) # test if which also works with garbage input - self.assertTrue(which("qwertygarbage") is None) + self.assertTrue(bu.which("qwertygarbage") is None) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4