gmock_test_utils.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2006, Google Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are
00008 # met:
00009 #
00010 #     * Redistributions of source code must retain the above copyright
00011 # notice, this list of conditions and the following disclaimer.
00012 #     * Redistributions in binary form must reproduce the above
00013 # copyright notice, this list of conditions and the following disclaimer
00014 # in the documentation and/or other materials provided with the
00015 # distribution.
00016 #     * Neither the name of Google Inc. nor the names of its
00017 # contributors may be used to endorse or promote products derived from
00018 # this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00023 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00024 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00026 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00027 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00028 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00030 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 
00032 """Unit test utilities for Google C++ Mocking Framework."""
00033 
00034 __author__ = 'wan@google.com (Zhanyong Wan)'
00035 
00036 import os
00037 import sys
00038 
00039 
00040 # Determines path to gtest_test_utils and imports it.
00041 SCRIPT_DIR = os.path.dirname(__file__) or '.'
00042 
00043 # isdir resolves symbolic links.
00044 gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../gtest/test')
00045 if os.path.isdir(gtest_tests_util_dir):
00046   GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir
00047 else:
00048   GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../gtest/test')
00049 
00050 sys.path.append(GTEST_TESTS_UTIL_DIR)
00051 import gtest_test_utils  # pylint: disable-msg=C6204
00052 
00053 
00054 def GetSourceDir():
00055   """Returns the absolute path of the directory where the .py files are."""
00056 
00057   return gtest_test_utils.GetSourceDir()
00058 
00059 
00060 def GetTestExecutablePath(executable_name):
00061   """Returns the absolute path of the test binary given its name.
00062 
00063   The function will print a message and abort the program if the resulting file
00064   doesn't exist.
00065 
00066   Args:
00067     executable_name: name of the test binary that the test script runs.
00068 
00069   Returns:
00070     The absolute path of the test binary.
00071   """
00072 
00073   return gtest_test_utils.GetTestExecutablePath(executable_name)
00074 
00075 
00076 def GetExitStatus(exit_code):
00077   """Returns the argument to exit(), or -1 if exit() wasn't called.
00078 
00079   Args:
00080     exit_code: the result value of os.system(command).
00081   """
00082 
00083   if os.name == 'nt':
00084     # On Windows, os.WEXITSTATUS() doesn't work and os.system() returns
00085     # the argument to exit() directly.
00086     return exit_code
00087   else:
00088     # On Unix, os.WEXITSTATUS() must be used to extract the exit status
00089     # from the result of os.system().
00090     if os.WIFEXITED(exit_code):
00091       return os.WEXITSTATUS(exit_code)
00092     else:
00093       return -1
00094 
00095 
00096 # Suppresses the "Invalid const name" lint complaint
00097 # pylint: disable-msg=C6409
00098 
00099 # Exposes utilities from gtest_test_utils.
00100 Subprocess = gtest_test_utils.Subprocess
00101 TestCase = gtest_test_utils.TestCase
00102 environ = gtest_test_utils.environ
00103 SetEnvVar = gtest_test_utils.SetEnvVar
00104 PREMATURE_EXIT_FILE_ENV_VAR = gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR
00105 
00106 # pylint: enable-msg=C6409
00107 
00108 
00109 def Main():
00110   """Runs the unit test."""
00111 
00112   gtest_test_utils.Main()


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:43