Repository: ambari
Updated Branches:
  refs/heads/trunk a6c86eec9 -> 114220647


AMBARI-12171 Windows unit tests: Common unit tests: fix the imports & failing 
patches

Fixed the imports. Coalesced the OS mock.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/11422064
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/11422064
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/11422064

Branch: refs/heads/trunk
Commit: 1142206476aff1fdebe4ddb72b488ad40e87472e
Parents: a6c86ee
Author: Florian Barca <fba...@hortonworks.com>
Authored: Tue Jul 21 11:34:23 2015 -0700
Committer: Florian Barca <fba...@hortonworks.com>
Committed: Tue Jul 21 13:00:34 2015 -0700

----------------------------------------------------------------------
 .../python/resource_management/TestContentSources.py     |  6 ++++--
 .../python/resource_management/TestDirectoryResource.py  |  9 ++++++---
 .../resource_management/TestExecuteHadoopResource.py     |  8 ++++++--
 .../python/resource_management/TestExecuteResource.py    |  6 ++++--
 .../test/python/resource_management/TestFileResource.py  |  9 +++++++--
 .../test/python/resource_management/TestGroupResource.py |  8 +++++---
 .../test/python/resource_management/TestLinkResource.py  |  8 ++++----
 .../resource_management/TestPropertiesFileResource.py    |  6 ++++--
 .../python/resource_management/TestRepositoryResource.py |  3 ++-
 .../python/resource_management/TestServiceResource.py    | 11 +++++++++--
 .../resource_management/TestTemplateConfigResource.py    |  9 +++++++--
 .../test/python/resource_management/TestUserResource.py  |  7 +++++--
 .../python/resource_management/TestXmlConfigResource.py  |  8 ++++++--
 ambari-agent/src/test/python/unitTests.py                |  7 +------
 14 files changed, 70 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestContentSources.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestContentSources.py 
b/ambari-agent/src/test/python/resource_management/TestContentSources.py
index 55c3300..5f4ee06 100644
--- a/ambari-agent/src/test/python/resource_management/TestContentSources.py
+++ b/ambari-agent/src/test/python/resource_management/TestContentSources.py
@@ -18,7 +18,9 @@ limitations under the License.
 
 from unittest import TestCase
 from mock.mock import patch, MagicMock
-from only_for_platform import get_platform, not_for_platform, PLATFORM_WINDOWS
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
+
+from ambari_commons.os_check import OSCheck
 
 from resource_management.core import Environment
 from resource_management.core.system import System
@@ -35,7 +37,7 @@ import urllib2
 import os
 
 
-@patch.object(System, "os_family", new = 'redhat')
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 class TestContentSources(TestCase):
 
   @patch.object(os.path, "isfile")

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestDirectoryResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestDirectoryResource.py 
b/ambari-agent/src/test/python/resource_management/TestDirectoryResource.py
index f1ca4de..011be6d 100644
--- a/ambari-agent/src/test/python/resource_management/TestDirectoryResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestDirectoryResource.py
@@ -18,7 +18,9 @@ limitations under the License.
 
 from unittest import TestCase
 from mock.mock import patch, MagicMock
-from only_for_platform import get_platform, not_for_platform, PLATFORM_WINDOWS
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
+
+from ambari_commons.os_check import OSCheck
 
 import os
 from resource_management.core.system import System
@@ -30,9 +32,10 @@ if get_platform() != PLATFORM_WINDOWS:
   import grp
 
 
-@patch.object(System, "os_family", new = 'redhat')
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 class TestDirectoryResource(TestCase):
-  
+
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch("resource_management.core.sudo.path_exists")
   @patch("resource_management.core.sudo.makedirs")
   @patch("resource_management.core.sudo.path_isdir")

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py 
b/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py
index 6bb9d0f..264398b 100644
--- 
a/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py
+++ 
b/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py
@@ -19,12 +19,16 @@ limitations under the License.
 import os
 
 from unittest import TestCase
-from mock.mock import patch
+from mock.mock import patch, MagicMock
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
+
+from ambari_commons.os_check import OSCheck
+
 from resource_management import *
 from resource_management.libraries.resources.execute_hadoop\
   import ExecuteHadoop
 
-@patch.object(System, "os_family", new = 'redhat')
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 class TestExecuteHadoopResource(TestCase):
   @patch("resource_management.core.providers.system.ExecuteProvider")
   def test_run_default_args(self, execute_mock):

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestExecuteResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestExecuteResource.py 
b/ambari-agent/src/test/python/resource_management/TestExecuteResource.py
index 2a6cd9b..7e99543 100644
--- a/ambari-agent/src/test/python/resource_management/TestExecuteResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestExecuteResource.py
@@ -18,7 +18,9 @@ limitations under the License.
 
 from unittest import TestCase
 from mock.mock import patch, MagicMock, call
-from only_for_platform import get_platform, not_for_platform, PLATFORM_WINDOWS
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
+
+from ambari_commons.os_check import OSCheck
 
 from resource_management.core.system import System
 from resource_management.core.resources.system import Execute
@@ -36,7 +38,7 @@ if get_platform() != PLATFORM_WINDOWS:
 import select
 
 
-@patch.object(System, "os_family", new='redhat')
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 class TestExecuteResource(TestCase):
   @patch.object(os, "read")
   @patch.object(select, "select")

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestFileResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestFileResource.py 
b/ambari-agent/src/test/python/resource_management/TestFileResource.py
index 7774108..8fc81e4 100644
--- a/ambari-agent/src/test/python/resource_management/TestFileResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestFileResource.py
@@ -19,7 +19,9 @@ limitations under the License.
 
 from unittest import TestCase
 from mock.mock import patch, MagicMock
-from only_for_platform import get_platform, not_for_platform, PLATFORM_WINDOWS
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
+
+from ambari_commons.os_check import OSCheck
 
 import os
 import sys
@@ -32,9 +34,12 @@ if get_platform() != PLATFORM_WINDOWS:
   import resource_management.core.providers.system
   import grp
   import pwd
+else:
+  import resource_management.core.providers.windows.system
+
 
 
-@patch.object(System, "os_family", new = 'redhat')
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 class TestFileResource(TestCase):
   @patch.object(os.path, "dirname")
   @patch("resource_management.core.sudo.path_isdir")

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestGroupResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestGroupResource.py 
b/ambari-agent/src/test/python/resource_management/TestGroupResource.py
index da982cf..8ebac39 100644
--- a/ambari-agent/src/test/python/resource_management/TestGroupResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestGroupResource.py
@@ -18,15 +18,17 @@ limitations under the License.
 
 from unittest import TestCase
 from mock.mock import patch, MagicMock
-from only_for_platform import get_platform, not_for_platform, PLATFORM_WINDOWS
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
+
+from ambari_commons.os_check import OSCheck
 
 from resource_management.core import Environment, Fail
 from resource_management.core.resources import Group
 from resource_management.core.system import System
 
-import subprocess
 import os
 import select
+import subprocess
 
 if get_platform() != PLATFORM_WINDOWS:
   import grp
@@ -35,9 +37,9 @@ if get_platform() != PLATFORM_WINDOWS:
 
 subproc_stdout = MagicMock()
 
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 @patch.object(os, "read", new=MagicMock(return_value=None))
 @patch.object(select, "select", new=MagicMock(return_value=([subproc_stdout], 
None, None)))
-@patch.object(System, "os_family", new = 'redhat')
 @patch.object(os, "environ", new = {'PATH':'/bin'})
 @patch("pty.openpty", new = MagicMock(return_value=(1,5)))
 @patch.object(os, "close", new=MagicMock())

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestLinkResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestLinkResource.py 
b/ambari-agent/src/test/python/resource_management/TestLinkResource.py
index f27b5d0..36c4401 100644
--- a/ambari-agent/src/test/python/resource_management/TestLinkResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestLinkResource.py
@@ -18,7 +18,9 @@ limitations under the License.
 
 from unittest import TestCase
 from mock.mock import patch, MagicMock
-from only_for_platform import get_platform, not_for_platform, PLATFORM_WINDOWS
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
+
+from ambari_commons.os_check import OSCheck
 
 from resource_management.core import Environment, Fail
 from resource_management.core.system import System
@@ -26,7 +28,7 @@ from resource_management.core.resources.system import Link
 
 import os
 
-@patch.object(System, "os_family", new = 'redhat')
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 class TestLinkResource(TestCase):
 
   @patch.object(os.path, "realpath")
@@ -143,5 +145,3 @@ class TestLinkResource(TestCase):
            action = "delete"
       )    
     unlink_mock.assert_called_with("/some_path")
-      
-  

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestPropertiesFileResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestPropertiesFileResource.py
 
b/ambari-agent/src/test/python/resource_management/TestPropertiesFileResource.py
index 7ca6ef8..3dd60e1 100644
--- 
a/ambari-agent/src/test/python/resource_management/TestPropertiesFileResource.py
+++ 
b/ambari-agent/src/test/python/resource_management/TestPropertiesFileResource.py
@@ -24,13 +24,15 @@ import os
 import time
 from unittest import TestCase
 from mock.mock import patch, MagicMock
-from only_for_platform import get_platform, not_for_platform, PLATFORM_WINDOWS
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
+
+from ambari_commons.os_check import OSCheck
 
 from resource_management.core import Environment
 from resource_management.core.system import System
 from resource_management.libraries import PropertiesFile
 
-@patch.object(System, "os_family", new='redhat')
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 class TestPropertiesFIleResource(TestCase):
   """
   
PropertiesFile="resource_management.libraries.providers.properties_file.PropertiesFileProvider"

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py 
b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
index 8ff0fd2..ccc9ae0 100644
--- a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
@@ -22,11 +22,12 @@ from unittest import TestCase
 from mock.mock import patch, MagicMock
 from only_for_platform import get_platform, not_for_platform, PLATFORM_WINDOWS
 
+from ambari_commons.os_check import OSCheck
+
 from resource_management.core.environment import Environment
 from resource_management.core.source import InlineTemplate
 from resource_management.core.system import System
 from resource_management.libraries.resources.repository import Repository
-from ambari_commons.os_check import OSCheck
 
 if get_platform() != PLATFORM_WINDOWS:
   from resource_management.libraries.providers import repository

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestServiceResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestServiceResource.py 
b/ambari-agent/src/test/python/resource_management/TestServiceResource.py
index cf92278..d4a5743 100644
--- a/ambari-agent/src/test/python/resource_management/TestServiceResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestServiceResource.py
@@ -18,9 +18,16 @@ limitations under the License.
 
 from unittest import TestCase
 from mock.mock import patch, MagicMock
-from resource_management import *
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
 
-@patch.object(System, "os_family", new = 'redhat')
+from ambari_commons.os_check import OSCheck
+
+from resource_management.core.environment import Environment
+from resource_management.core.exceptions import Fail
+from resource_management.core.resources.service import Service
+
+
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 class TestServiceResource(TestCase):
 
   @patch("resource_management.core.shell.call")

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestTemplateConfigResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestTemplateConfigResource.py
 
b/ambari-agent/src/test/python/resource_management/TestTemplateConfigResource.py
index 2808e63..864417a 100644
--- 
a/ambari-agent/src/test/python/resource_management/TestTemplateConfigResource.py
+++ 
b/ambari-agent/src/test/python/resource_management/TestTemplateConfigResource.py
@@ -17,12 +17,17 @@ limitations under the License.
 '''
 
 from unittest import TestCase
-from mock.mock import patch
+from mock.mock import patch, MagicMock
+
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
+
+from ambari_commons.os_check import OSCheck
+
 from resource_management import *
 from resource_management.libraries.resources.template_config \
   import TemplateConfig
 
-@patch.object(System, "os_family", new = 'redhat')
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 class TestTemplateConfigResource(TestCase):
 
   @patch("resource_management.libraries.providers.template_config.Template")

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestUserResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestUserResource.py 
b/ambari-agent/src/test/python/resource_management/TestUserResource.py
index f2c25fa..2a97676 100644
--- a/ambari-agent/src/test/python/resource_management/TestUserResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestUserResource.py
@@ -18,7 +18,10 @@ limitations under the License.
 
 from unittest import TestCase
 from mock.mock import patch, MagicMock, PropertyMock
-from only_for_platform import get_platform, not_for_platform, PLATFORM_WINDOWS
+
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
+
+from ambari_commons.os_check import OSCheck
 
 from resource_management.core import Environment, Fail
 from resource_management.core.system import System
@@ -34,9 +37,9 @@ if get_platform() != PLATFORM_WINDOWS:
 
 subproc_stdout = MagicMock()
 
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 @patch.object(os, "read", new=MagicMock(return_value=None))
 @patch.object(select, "select", new=MagicMock(return_value=([subproc_stdout], 
None, None)))
-@patch.object(System, "os_family", new = 'redhat')
 @patch.object(os, "environ", new = {'PATH':'/bin'})
 @patch("pty.openpty", new = MagicMock(return_value=(1,5)))
 @patch.object(os, "close", new=MagicMock())

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py 
b/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
index 29a22b2..7a0d52d 100644
--- a/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
@@ -24,14 +24,18 @@ import os
 import time
 from unittest import TestCase
 from mock.mock import patch, MagicMock
-from only_for_platform import get_platform, not_for_platform, PLATFORM_WINDOWS
+
+from only_for_platform import get_platform, not_for_platform, os_distro_value, 
PLATFORM_WINDOWS
+
+from ambari_commons.os_check import OSCheck
 
 from resource_management.core import Environment
 from resource_management.core.system import System
 from resource_management.libraries import XmlConfig
 
 
-@patch.object(System, "os_family", new='redhat')
+
+@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
 class TestXmlConfigResource(TestCase):
   """
   
XmlConfig="resource_management.libraries.providers.xml_config.XmlConfigProvider",

http://git-wip-us.apache.org/repos/asf/ambari/blob/11422064/ambari-agent/src/test/python/unitTests.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/unitTests.py 
b/ambari-agent/src/test/python/unitTests.py
index 83b5a0f..a7763be 100644
--- a/ambari-agent/src/test/python/unitTests.py
+++ b/ambari-agent/src/test/python/unitTests.py
@@ -50,13 +50,8 @@ LOG_FILE_NAME='tests.log'
 SELECTED_PREFIX = "_"
 PY_EXT='.py'
 
-if get_platform() == PLATFORM_WINDOWS:
-  IGNORE_FOLDERS = ["resource_management"]
-else:
-  IGNORE_FOLDERS = ["resource_management_windows"]
 
 TEST_MASK = '[Tt]est*.py'
-
 class TestAgent(unittest.TestSuite):
   def run(self, result):
     run = unittest.TestSuite.run
@@ -92,7 +87,7 @@ def get_test_files(path, mask=None, recursive=True):
       if fnmatch.fnmatch(item, mask):
         add_to_pythonpath = True
         file_list.append(item)
-    elif os.path.isdir(p)and p not in IGNORE_FOLDERS:
+    elif os.path.isdir(p):
       if recursive:
         file_list.extend(get_test_files(p, mask=mask))
     if add_to_pythonpath:

Reply via email to