예제 #1
0
def _setup():
    """Set up configs and import paths."""
    os.environ['ROOT_DIR'] = os.path.abspath('.')

    sys.path.insert(0, os.path.abspath(os.path.join('src')))
    from python.base import modules
    modules.fix_module_search_paths()
예제 #2
0
def _setup():
    """Set up configs and import paths."""
    os.environ['ROOT_DIR'] = os.path.abspath('.')

    sys.path.insert(0, os.path.abspath(os.path.join('src')))
    sys.path.insert(0, os.path.abspath(os.path.join('src', 'third_party')))

    # Add our third_party libs before older appengine libs.
    from python.base import modules
    modules.fix_module_search_paths()
예제 #3
0
def _setup():
  """Set up configs and import paths."""
  appengine_sdk_path = appengine.find_sdk_path()
  sys.path.insert(0, appengine_sdk_path)

  # This is necessary for our local environment, where googledatastore (old
  # library used only in tests) depends on protobufs which have duplicate
  # definitions in google-cloud-datastore. The python implementation of
  # protobufs are more relaxed and allow this.
  # TODO(ochang): Remove this once we no longer depend on googledatastore.
  os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'

  os.environ['ROOT_DIR'] = os.path.abspath('.')

  sys.path.insert(0, os.path.abspath(os.path.join('src')))
  sys.path.insert(0, os.path.abspath(os.path.join('src', 'third_party')))

  # Add our third_party libs before older appengine libs.
  from python.base import modules
  modules.fix_module_search_paths()
예제 #4
0
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""libFuzzer launcher."""
from __future__ import print_function
# pylint: disable=g-statement-before-imports
from builtins import object
from builtins import range
try:
    # ClusterFuzz dependencies.
    from python.base import modules
    modules.fix_module_search_paths()
except ImportError:
    pass

import atexit
import multiprocessing
import os
import random
import re
import shutil
import signal
import stat
import string
import sys
import time
예제 #5
0
def execute(args):
    """Run Python unit tests. For unittests involved appengine, sys.path needs
  certain modification."""
    os.environ['PY_UNITTESTS'] = 'True'
    os.environ['CLOUDSDK_PYTHON'] = 'python2'

    if os.getenv('INTEGRATION') or os.getenv('UNTRUSTED_RUNNER_TESTS'):
        # Set up per-user buckets used by integration tests.
        os.environ['CORPUS_BUCKET'] = common.test_bucket('TEST_CORPUS_BUCKET')
        os.environ['QUARANTINE_BUCKET'] = common.test_bucket(
            'TEST_QUARANTINE_BUCKET')
        os.environ['BACKUP_BUCKET'] = common.test_bucket('TEST_BACKUP_BUCKET')
        os.environ['COVERAGE_BUCKET'] = common.test_bucket(
            'TEST_COVERAGE_BUCKET')

    # Kill leftover instances of emulators and dev appserver.
    common.kill_leftover_emulators()

    # Don't use absolute paths to make it easier to compare results in tests.
    os.environ['CONFIG_DIR_OVERRIDE'] = os.path.join('.', 'configs', 'test')

    top_level_dir = os.path.join('src', 'python')
    if args.target == 'appengine':
        # Build template files.
        appengine.build_templates()

        test_directory = APPENGINE_TEST_DIRECTORY
        sys.path.insert(0, os.path.abspath(os.path.join('src', 'appengine')))

        for i, path in enumerate(sys.path):
            if 'third_party' in path:
                # Replace third_party with App Engine third_party/.
                sys.path[i] = os.path.abspath(
                    os.path.join('src', 'appengine', 'third_party'))

        if sys.version_info.major == 2:
            # TODO(ochang): Remove once migrated to Python 3.
            appengine_sdk_path = appengine.find_sdk_path()
            sys.path.insert(0, appengine_sdk_path)

            # Get additional App Engine third party imports.
            import dev_appserver
            dev_appserver.fix_google_path()
            sys.path.extend(dev_appserver.EXTRA_PATHS)

            # Loading appengine_main from the current project ensures that any
            # changes to configuration there are available to all tests (e.g.
            # sys.path modifications, namespaces, etc.)
            try:
                from src.appengine import main as appengine_main
                (appengine_main)  # pylint: disable=pointless-statement
            except ImportError:
                print('Note: unable to import appengine_main.')

            # google.auth uses App Engine credentials based on importability of
            # google.appengine.api.app_identity.
            try:
                from google.auth import app_engine as auth_app_engine
                if auth_app_engine.app_identity:
                    auth_app_engine.app_identity = None
            except ImportError:
                pass
    elif args.target == 'core':
        test_directory = CORE_TEST_DIRECTORY
    else:
        # Config module tests.
        os.environ['CONFIG_DIR_OVERRIDE'] = args.config_dir
        test_directory = os.path.join(args.config_dir, 'modules')
        top_level_dir = None

        # Modules may use libs from our App Engine directory.
        sys.path.insert(0, os.path.abspath(os.path.join('src', 'appengine')))

        # Fix paths again to get config modules added to the import path.
        from python.base import modules
        modules.fix_module_search_paths()

    # Set expected environment variables.
    local_config.ProjectConfig().set_environment()

    # Needed for NDB to work with cloud datastore emulator.
    os.environ['DATASTORE_USE_PROJECT_ID_AS_APP_ID'] = 'true'

    if args.verbose:
        # Force logging to console for this process and child processes.
        os.environ['LOG_TO_CONSOLE'] = 'True'
    else:
        # Disable logging.
        logging.disable(logging.CRITICAL)

    if args.pattern is None:
        args.pattern = '*_test.py'

    if args.parallel:
        # TODO(tanin): Support coverage.
        run_tests_parallel(args, test_directory, top_level_dir)
    else:
        run_tests_single_core(args, test_directory, top_level_dir)
예제 #6
0
def execute(args):
    """Run Python unit tests. For unittests involved appengine, sys.path needs
    certain modification."""
    os.environ["PY_UNITTESTS"] = "True"

    if os.getenv("INTEGRATION") or os.getenv("UNTRUSTED_RUNNER_TESTS"):
        # Set up per-user buckets used by integration tests.
        os.environ["CORPUS_BUCKET"] = common.test_bucket("TEST_CORPUS_BUCKET")
        os.environ["QUARANTINE_BUCKET"] = common.test_bucket(
            "TEST_QUARANTINE_BUCKET")
        os.environ["BACKUP_BUCKET"] = common.test_bucket("TEST_BACKUP_BUCKET")
        os.environ["COVERAGE_BUCKET"] = common.test_bucket(
            "TEST_COVERAGE_BUCKET")

    # Kill leftover instances of emulators and dev appserver.
    common.kill_leftover_emulators()

    # Don't use absolute paths to make it easier to compare results in tests.
    os.environ["CONFIG_DIR_OVERRIDE"] = os.path.join(".", "configs", "test")

    top_level_dir = os.path.join("src", "python")
    if args.target == "appengine":
        # Build template files.
        appengine.build_templates()

        test_directory = APPENGINE_TEST_DIRECTORY
        sys.path.insert(0, os.path.abspath(os.path.join("src", "appengine")))

        # Get additional App Engine third party imports.
        import dev_appserver

        sys.path.extend(dev_appserver.EXTRA_PATHS)

        # Loading appengine_config from the current project ensures that any
        # changes to configuration there are available to all tests (e.g.
        # sys.path modifications, namespaces, etc.)
        try:
            from src.appengine import appengine_config

            (appengine_config)  # pylint: disable=pointless-statement
        except ImportError:
            print("Note: unable to import appengine_config.")
    elif args.target == "core":
        test_directory = CORE_TEST_DIRECTORY
    else:
        # Config module tests.
        os.environ["CONFIG_DIR_OVERRIDE"] = args.config_dir
        test_directory = os.path.join(args.config_dir, "modules")
        top_level_dir = None

        # Modules may use libs from our App Engine directory.
        sys.path.insert(0, os.path.abspath(os.path.join("src", "appengine")))

        # Fix paths again to get config modules added to the import path.
        from python.base import modules

        modules.fix_module_search_paths()

    # Set expected environment variables.
    local_config.ProjectConfig().set_environment()

    # Needed for NDB to work with cloud datastore emulator.
    os.environ["DATASTORE_USE_PROJECT_ID_AS_APP_ID"] = "true"

    if args.verbose:
        # Force logging to console for this process and child processes.
        os.environ["LOG_TO_CONSOLE"] = "True"
    else:
        # Disable logging.
        logging.disable(logging.CRITICAL)

    if args.pattern is None:
        args.pattern = "*_test.py"

    if args.parallel:
        # TODO(tanin): Support coverage.
        run_tests_parallel(args, test_directory, top_level_dir)
    else:
        run_tests_single_core(args, test_directory, top_level_dir)