You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by sm...@apache.org on 2014/11/09 16:56:14 UTC
incubator-slider git commit: Test Commit 3
Repository: incubator-slider
Updated Branches:
refs/heads/feature/python_unittests 0cc2a39fb -> 52591a9fa
Test Commit 3
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/52591a9f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/52591a9f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/52591a9f
Branch: refs/heads/feature/python_unittests
Commit: 52591a9fabdedd7fc0058d7cdf7c8c826dfda50c
Parents: 0cc2a39
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Sun Nov 9 07:56:08 2014 -0800
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Sun Nov 9 07:56:08 2014 -0800
----------------------------------------------------------------------
slider-agent/src/test/python/agent/TestMain.py | 32 ++++++++++++--------
.../TestDirectoryResource.py | 14 +++------
.../resource_management/TestExecuteResource.py | 15 ++++-----
.../resource_management/TestFileResource.py | 20 ++----------
4 files changed, 33 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/52591a9f/slider-agent/src/test/python/agent/TestMain.py
----------------------------------------------------------------------
diff --git a/slider-agent/src/test/python/agent/TestMain.py b/slider-agent/src/test/python/agent/TestMain.py
index 7c0036b..256440e 100644
--- a/slider-agent/src/test/python/agent/TestMain.py
+++ b/slider-agent/src/test/python/agent/TestMain.py
@@ -33,6 +33,9 @@ import tempfile
from Controller import Controller
from Registry import Registry
from optparse import OptionParser
+import platform
+
+IS_WINDOWS = platform.system() == "Windows"
logger = logging.getLogger()
@@ -116,15 +119,15 @@ class TestMain(unittest.TestCase):
main.update_log_level(config, tmpoutfile)
setLevel_mock.assert_called_with(logging.INFO)
-
- @patch("signal.signal")
- def test_bind_signal_handlers(self, signal_mock):
- main.bind_signal_handlers()
- # Check if on SIGINT/SIGTERM agent is configured to terminate
- signal_mock.assert_any_call(signal.SIGINT, main.signal_handler)
- signal_mock.assert_any_call(signal.SIGTERM, main.signal_handler)
- # Check if on SIGUSR1 agent is configured to fall into debug
- signal_mock.assert_any_call(signal.SIGUSR1, main.debug)
+ if not IS_WINDOWS:
+ @patch("signal.signal")
+ def test_bind_signal_handlers(self, signal_mock):
+ main.bind_signal_handlers()
+ # Check if on SIGINT/SIGTERM agent is configured to terminate
+ signal_mock.assert_any_call(signal.SIGINT, main.signal_handler)
+ signal_mock.assert_any_call(signal.SIGTERM, main.signal_handler)
+ # Check if on SIGUSR1 agent is configured to fall into debug
+ signal_mock.assert_any_call(signal.SIGUSR1, main.debug)
@patch("os.path.exists")
@@ -201,7 +204,8 @@ class TestMain(unittest.TestCase):
# Testing normal exit
exists_mock.return_value = False
main.stop_agent()
- kill_mock.assert_called_with(int(pid), signal.SIGTERM)
+ if not IS_WINDOWS:
+ kill_mock.assert_called_with(int(pid), signal.SIGTERM)
# Restore
kill_mock.reset_mock()
@@ -210,8 +214,9 @@ class TestMain(unittest.TestCase):
# Testing exit when failed to remove pid file
exists_mock.return_value = True
main.stop_agent()
- kill_mock.assert_any_call(int(pid), signal.SIGTERM)
- kill_mock.assert_any_call(int(pid), signal.SIGKILL)
+ if not IS_WINDOWS:
+ kill_mock.assert_any_call(int(pid), signal.SIGTERM)
+ kill_mock.assert_any_call(int(pid), signal.SIGKILL)
_exit_mock.assert_called_with(1)
# Restore
@@ -253,7 +258,8 @@ class TestMain(unittest.TestCase):
main.main()
self.assertTrue(setup_logging_mock.called)
- self.assertTrue(bind_signal_handlers_mock.called)
+ if not IS_WINDOWS:
+ self.assertTrue(bind_signal_handlers_mock.called)
self.assertTrue(update_config_from_file_mock.called)
self.assertTrue(perform_prestart_checks_mock.called)
self.assertTrue(write_pid_mock.called)
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/52591a9f/slider-agent/src/test/python/resource_management/TestDirectoryResource.py
----------------------------------------------------------------------
diff --git a/slider-agent/src/test/python/resource_management/TestDirectoryResource.py b/slider-agent/src/test/python/resource_management/TestDirectoryResource.py
index 0b74708..e3282d0 100644
--- a/slider-agent/src/test/python/resource_management/TestDirectoryResource.py
+++ b/slider-agent/src/test/python/resource_management/TestDirectoryResource.py
@@ -33,11 +33,10 @@ class TestDirectoryResource(TestCase):
@patch.object(os.path, "isdir")
@patch.object(os, "stat")
@patch.object(os,"chmod")
- @patch.object(os,"chown")
@patch("resource_management.core.providers.system._coerce_uid")
@patch("resource_management.core.providers.system._coerce_gid")
def test_create_directory_recursive(self, _coerce_gid_mock, _coerce_uid_mock,
- os_chown_mock, os_chmod_mock, os_stat_mock,
+ os_chmod_mock, os_stat_mock,
isdir_mock, os_makedirs_mock,
os_path_exists_mock):
os_path_exists_mock.return_value = False
@@ -57,20 +56,17 @@ class TestDirectoryResource(TestCase):
os_makedirs_mock.assert_called_with('/a/b/c/d', 0777)
os_chmod_mock.assert_called_with('/a/b/c/d', 0777)
- ##os_chown_mock.assert_any_call('/a/b/c/d', 66, -1)
- ##os_chown_mock.assert_any_call('/a/b/c/d', -1, 77)
-
+
@patch.object(os.path, "exists")
@patch.object(os.path, "dirname")
@patch.object(os.path, "isdir")
@patch.object(os, "mkdir")
@patch.object(os, "stat")
@patch.object(os,"chmod")
- @patch.object(os,"chown")
@patch("resource_management.core.providers.system._coerce_uid")
@patch("resource_management.core.providers.system._coerce_gid")
def test_create_directory_not_recursive(self, _coerce_gid_mock, _coerce_uid_mock,
- os_chown_mock, os_chmod_mock, os_stat_mock,
+ os_chmod_mock, os_stat_mock,
mkdir_mock, isdir_mock, os_dirname_mock,
os_path_exists_mock):
os_path_exists_mock.return_value = False
@@ -90,9 +86,7 @@ class TestDirectoryResource(TestCase):
mkdir_mock.assert_called_with('/a/b/c/d', 0777)
os_chmod_mock.assert_called_with('/a/b/c/d', 0777)
- ##os_chown_mock.assert_any_call('/a/b/c/d', 66, -1)
- ##os_chown_mock.assert_any_call('/a/b/c/d', -1, 77)
-
+
@patch.object(os.path, "exists")
@patch.object(os.path, "dirname")
@patch.object(os.path, "isdir")
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/52591a9f/slider-agent/src/test/python/resource_management/TestExecuteResource.py
----------------------------------------------------------------------
diff --git a/slider-agent/src/test/python/resource_management/TestExecuteResource.py b/slider-agent/src/test/python/resource_management/TestExecuteResource.py
index 38f7aea..b7af465 100644
--- a/slider-agent/src/test/python/resource_management/TestExecuteResource.py
+++ b/slider-agent/src/test/python/resource_management/TestExecuteResource.py
@@ -83,14 +83,15 @@ class TestExecuteResource(TestCase):
self.assertTrue(popen_mock.called, 'subprocess.Popen should have been called!')
self.assertFalse(proc_communicate_mock.called, 'proc.communicate should not have been called!')
- @patch('subprocess.Popen.communicate')
- def test_attribute_wait_and_poll_and_success(self, proc_communicate_mock):
- with Environment("/") as env:
- Execute('sleep 6',
- wait_for_finish=False,
- poll_after = 2)
+ if not IS_WINDOWS:
+ @patch('subprocess.Popen.communicate')
+ def test_attribute_wait_and_poll_and_success(self, proc_communicate_mock):
+ with Environment("/") as env:
+ Execute('sleep 6',
+ wait_for_finish=False,
+ poll_after = 2)
- self.assertFalse(proc_communicate_mock.called, 'proc.communicate should not have been called!')
+ self.assertFalse(proc_communicate_mock.called, 'proc.communicate should not have been called!')
@patch.object(os.path, "exists")
@patch.object(subprocess, "Popen")
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/52591a9f/slider-agent/src/test/python/resource_management/TestFileResource.py
----------------------------------------------------------------------
diff --git a/slider-agent/src/test/python/resource_management/TestFileResource.py b/slider-agent/src/test/python/resource_management/TestFileResource.py
index 00b1c08..642412c 100644
--- a/slider-agent/src/test/python/resource_management/TestFileResource.py
+++ b/slider-agent/src/test/python/resource_management/TestFileResource.py
@@ -269,16 +269,12 @@ class TestFileResource(TestCase):
self.assertEqual(open_mock.call_count, 0)
- @patch("resource_management.core.providers.system._coerce_uid")
- @patch("resource_management.core.providers.system._coerce_gid")
- @patch.object(os, "chown")
@patch.object(os, "chmod")
@patch.object(os, "stat")
@patch("__builtin__.open")
@patch.object(os.path, "exists")
@patch.object(os.path, "isdir")
- def test_ensure_metadata(self, isdir_mock, exists_mock, open_mock, stat_mock, chmod_mock, chown_mock, gid_mock,
- uid_mock):
+ def test_ensure_metadata(self, isdir_mock, exists_mock, open_mock, stat_mock, chmod_mock):
"""
Tests if _ensure_metadata changes owner, usergroup and permissions of file to proper values
"""
@@ -292,8 +288,6 @@ class TestFileResource(TestCase):
self.st_gid = 1
stat_mock.return_value = stat()
- gid_mock.return_value = 0
- uid_mock.return_value = 0
with Environment('/') as env:
File('/directory/file',
@@ -308,15 +302,7 @@ class TestFileResource(TestCase):
open_mock.assert_called_with('/directory/file', 'wb')
self.assertEqual(open_mock.call_count, 1)
stat_mock.assert_called_with('/directory/file')
- ##self.assertEqual(chmod_mock.call_count, 1)
- ##self.assertEqual(chown_mock.call_count, 2)
- ##gid_mock.assert_called_once_with('hdfs')
- ##uid_mock.assert_called_once_with('root')
- chmod_mock.reset_mock()
- chown_mock.reset_mock()
- gid_mock.return_value = 1
- uid_mock.return_value = 1
with Environment('/') as env:
File('/directory/file',
@@ -326,7 +312,5 @@ class TestFileResource(TestCase):
owner='root',
group='hdfs'
)
-
+ self.assertTrue(chmod_mock.called)
- self.assertEqual(chmod_mock.call_count, 1)
- ##self.assertEqual(chown_mock.call_count, 0)