Skip to content

Commit

Permalink
Merge pull request #2488 from dhermes/allow-local-env-for-unit-tests
Browse files Browse the repository at this point in the history
Allowing local env. vars. to be used for running unit tests.
  • Loading branch information
dhermes authored Oct 4, 2016
2 parents 2acda27 + 56c1af2 commit 1828fb2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions scripts/run_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from script_utils import get_changed_packages
from script_utils import in_travis
from script_utils import in_travis_pr
from script_utils import local_diff_branch
from script_utils import travis_branch


Expand Down Expand Up @@ -119,6 +120,8 @@ def get_test_packages():
Filters the package list in the following order:
* Check command line for packages passed in as positional arguments
* Check if the the local remote and local branch environment variables
have been set to specify a remote branch to diff against.
* Check if in Travis, then limit the subset based on changes
in a Pull Request ("push" builds to branches may not have
any filtering)
Expand All @@ -129,12 +132,15 @@ def get_test_packages():
need be run.
"""
all_packages = get_package_directories()
local_diff = local_diff_branch()

parser = get_parser()
args = parser.parse_args()
if args.packages is not UNSET_SENTINEL:
verify_packages(args.packages, all_packages)
return sorted(args.packages)
elif local_diff is not None:
return get_changed_packages('HEAD', local_diff, all_packages)
elif in_travis():
return get_travis_directories(all_packages)
else:
Expand Down
23 changes: 18 additions & 5 deletions scripts/script_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ def get_changed_packages(blob_name1, blob_name2, package_list):
return sorted(result)


def local_diff_branch():
"""Get a remote branch to diff against in a local checkout.
Checks if the the local remote and local branch environment
variables specify a remote branch.
:rtype: str
:returns: The diffbase `{remote}/{branch}` if the environment
variables are defined. If not, returns ``None``.
"""
# Only allow specified remote and branch in local dev.
remote = os.getenv(LOCAL_REMOTE_ENV)
branch = os.getenv(LOCAL_BRANCH_ENV)
if remote is not None and branch is not None:
return '%s/%s' % (remote, branch)


def get_affected_files(allow_limited=True):
"""Gets a list of files in the repository.
Expand Down Expand Up @@ -195,11 +212,7 @@ def get_affected_files(allow_limited=True):
if in_travis_pr():
diff_base = travis_branch()
else:
# Only allow specified remote and branch in local dev.
remote = os.getenv(LOCAL_REMOTE_ENV)
branch = os.getenv(LOCAL_BRANCH_ENV)
if remote is not None and branch is not None:
diff_base = '%s/%s' % (remote, branch)
diff_base = local_diff_branch()

if diff_base is not None and allow_limited:
result = subprocess.check_output(['git', 'diff', '--name-only',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ skip_install =
py34: True
py35: True
isolated-cover: True
passenv = TRAVIS*
passenv = TRAVIS* GOOGLE_CLOUD_*

[testenv:isolated-cover]
commands =
Expand Down

0 comments on commit 1828fb2

Please sign in to comment.