Repository: incubator-slider
Updated Branches:
  refs/heads/feature/python_unittests 4c21c63a3 -> 8bc4ea989


Test Commit 5


Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/8bc4ea98
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/8bc4ea98
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/8bc4ea98

Branch: refs/heads/feature/python_unittests
Commit: 8bc4ea989737171349f44af8056319b159962765
Parents: 4c21c63
Author: Sumit Mohanty <smoha...@hortonworks.com>
Authored: Sun Nov 9 08:26:53 2014 -0800
Committer: Sumit Mohanty <smoha...@hortonworks.com>
Committed: Sun Nov 9 08:26:53 2014 -0800

----------------------------------------------------------------------
 slider-agent/src/test/python/agent/TestMain.py  | 62 ++++++++++----------
 .../resource_management/TestContentSources.py   | 14 ++++-
 2 files changed, 42 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/8bc4ea98/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 256440e..537ab1f 100644
--- a/slider-agent/src/test/python/agent/TestMain.py
+++ b/slider-agent/src/test/python/agent/TestMain.py
@@ -183,45 +183,43 @@ class TestMain(unittest.TestCase):
     main.perform_prestart_checks(main.config)
     self.assertFalse(exit_mock.called)
 
-
-  @patch("time.sleep")
-  @patch("os.kill")
-  @patch("os._exit")
-  @patch("os.path.exists")
-  def test_daemonize_and_stop(self, exists_mock, _exit_mock, kill_mock,
+  if not IS_WINDOWS:
+    @patch("time.sleep")
+    @patch("os.kill")
+    @patch("os._exit")
+    @patch("os.path.exists")
+    def test_daemonize_and_stop(self, exists_mock, _exit_mock, kill_mock,
                               sleep_mock):
-    oldpid = ProcessHelper.pidfile
-    pid = str(os.getpid())
-    _, tmpoutfile = tempfile.mkstemp()
-    ProcessHelper.pidfile = tmpoutfile
-
-    # Test daemonization
-    main.write_pid()
-    saved = open(ProcessHelper.pidfile, 'r').read()
-    self.assertEqual(pid, saved)
-
-    # Reuse pid file when testing agent stop
-    # Testing normal exit
-    exists_mock.return_value = False
-    main.stop_agent()
-    if not IS_WINDOWS:
+      oldpid = ProcessHelper.pidfile
+      pid = str(os.getpid())
+      _, tmpoutfile = tempfile.mkstemp()
+      ProcessHelper.pidfile = tmpoutfile
+
+      # Test daemonization
+      main.write_pid()
+      saved = open(ProcessHelper.pidfile, 'r').read()
+      self.assertEqual(pid, saved)
+
+      # Reuse pid file when testing agent stop
+      # Testing normal exit
+      exists_mock.return_value = False
+      main.stop_agent()
       kill_mock.assert_called_with(int(pid), signal.SIGTERM)
 
-    # Restore
-    kill_mock.reset_mock()
-    _exit_mock.reset_mock()
+      # Restore
+      kill_mock.reset_mock()
+      _exit_mock.reset_mock()
 
-    # Testing exit when failed to remove pid file
-    exists_mock.return_value = True
-    main.stop_agent()
-    if not IS_WINDOWS:
+      # 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)
-    _exit_mock.assert_called_with(1)
+      _exit_mock.assert_called_with(1)
 
-    # Restore
-    ProcessHelper.pidfile = oldpid
-    os.remove(tmpoutfile)
+      # Restore
+      ProcessHelper.pidfile = oldpid
+      os.remove(tmpoutfile)
 
   @patch.object(Registry, "readAMHostPort")
   @patch.object(main, "setup_logging")

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/8bc4ea98/slider-agent/src/test/python/resource_management/TestContentSources.py
----------------------------------------------------------------------
diff --git 
a/slider-agent/src/test/python/resource_management/TestContentSources.py 
b/slider-agent/src/test/python/resource_management/TestContentSources.py
index 3913ba1..7015c47 100644
--- a/slider-agent/src/test/python/resource_management/TestContentSources.py
+++ b/slider-agent/src/test/python/resource_management/TestContentSources.py
@@ -30,6 +30,9 @@ from resource_management.core.source import InlineTemplate
 from jinja2 import UndefinedError, TemplateNotFound
 import urllib2
 import os
+import platform
+
+IS_WINDOWS = platform.system() == "Windows"
 
 
 @patch.object(System, "os_family", new = 'redhat')
@@ -46,8 +49,12 @@ class TestContentSources(TestCase):
     file_mock.read.return_value = 'content'
     open_mock.return_value = file_mock
 
+    filepath = "/absolute/path/file"
+    if IS_WINDOWS:
+      filepath = "\\absolute\\path\\file"
+
     with Environment("/base") as env:
-      static_file = StaticFile("/absolute/path/file")
+      static_file = StaticFile(filepath)
       content = static_file.get_content()
 
     self.assertEqual('content', content)
@@ -216,4 +223,7 @@ class TestContentSources(TestCase):
     with Environment("/base") as env:
       template = InlineTemplate("{{test_arg1}} template content 
{{os.path.join(path[0],path[1])}}", [os], test_arg1 = "test", path = 
["/one","two"])
       content = template.get_content()
-    self.assertEqual(u'test template content /one/two\n', content)
+    if IS_WINDOWS:
+      self.assertEqual(u'test template content /one\\two\n', content)
+    else:
+      self.assertEqual(u'test template content /one/two\n', content)

Reply via email to