Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pytest-changed-files include api tests when an __init__ file is changed #2575

Merged
merged 6 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions check/pytest-changed-files
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ changed=$(git diff --name-only ${rev} -- \
| sort \
| uniq \
)
num_changed=$(echo -e "${changed}" | wc -w)
if git diff --name-only "${rev}" -- | grep "__init__\.py$" > /dev/null; then
# Include global API tests when an __init__ file is touched.
changed+=('docs/docs_coverage_test.py')
changed+=('cirq/protocols/json_test.py')
fi
num_changed=$(echo -e "${changed[@]}" | wc -w)

# Run it.
echo "Found ${num_changed} differing files with associated tests." >&2
if [ -z "${changed}" ]; then
echo "Found ${num_changed} test files associated with changes." >&2
if [ "${num_changed}" -eq 0 ]; then
exit 0
fi
pytest ${rest} ${changed}
pytest ${rest} ${changed[@]}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think [@] has any effect unless you place the variable in double quotes: "${changed[@]}".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored. Broke tests.

5 changes: 5 additions & 0 deletions check/pytest-changed-files-and-incremental-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ changed_python_tests=$(git diff --name-only "${rev}" -- \
| sort \
| uniq \
)
if git diff --name-only "${rev}" -- | grep "__init__\.py$" > /dev/null; then
# Include global API tests when an __init__ file is touched.
changed_python_tests+=('docs/docs_coverage_test.py')
changed_python_tests+=('cirq/protocols/json_test.py')
fi
if [ "${#changed_python_tests[@]}" -eq 0 ]; then
echo -e "\033[33mNo changed files with associated python tests.\033[0m" >&2
exit 0
Expand Down
42 changes: 28 additions & 14 deletions dev_tools/bash_scripts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_pytest_changed_files_file_selection(tmpdir_factory):
assert result.out == ''
assert result.err.split() == (
"Comparing against revision 'HEAD~1'.\n"
"Found 0 differing files with associated tests.\n").split()
"Found 0 test files associated with changes.\n").split()

result = run(script_file='check/pytest-changed-files',
tmpdir_factory=tmpdir_factory,
Expand All @@ -101,7 +101,7 @@ def test_pytest_changed_files_file_selection(tmpdir_factory):
assert result.out == 'INTERCEPTED pytest file_test.py\n'
assert result.err.split() == (
"Comparing against revision 'HEAD~1'.\n"
"Found 1 differing files with associated tests.\n").split()
"Found 1 test files associated with changes.\n").split()

result = run(script_file='check/pytest-changed-files',
tmpdir_factory=tmpdir_factory,
Expand All @@ -113,7 +113,7 @@ def test_pytest_changed_files_file_selection(tmpdir_factory):
assert result.out == 'INTERCEPTED pytest file_test.py\n'
assert result.err.split() == (
"Comparing against revision 'HEAD~1'.\n"
"Found 1 differing files with associated tests.\n").split()
"Found 1 test files associated with changes.\n").split()

result = run(script_file='check/pytest-changed-files',
tmpdir_factory=tmpdir_factory,
Expand All @@ -126,7 +126,7 @@ def test_pytest_changed_files_file_selection(tmpdir_factory):
assert result.out == 'INTERCEPTED pytest file_test.py\n'
assert result.err.split() == (
"Comparing against revision 'HEAD'.\n"
"Found 1 differing files with associated tests.\n").split()
"Found 1 test files associated with changes.\n").split()

result = run(script_file='check/pytest-changed-files',
tmpdir_factory=tmpdir_factory,
Expand All @@ -139,7 +139,21 @@ def test_pytest_changed_files_file_selection(tmpdir_factory):
assert result.out == 'INTERCEPTED pytest file_test.py\n'
assert result.err.split() == (
"Comparing against revision 'HEAD'.\n"
"Found 1 differing files with associated tests.\n").split()
"Found 1 test files associated with changes.\n").split()

result = run(script_file='check/pytest-changed-files',
tmpdir_factory=tmpdir_factory,
arg='HEAD',
setup='touch __init__.py\n'
'git add -A\n'
'git commit -m test --quiet --no-gpg-sign\n'
'echo x > __init__.py\n')
assert result.exit_code == 0
assert result.out == ('INTERCEPTED pytest docs/docs_coverage_test.py '
'cirq/protocols/json_test.py\n')
assert result.err.split() == (
"Comparing against revision 'HEAD'.\n"
"Found 2 test files associated with changes.\n").split()


@only_on_posix
Expand All @@ -152,7 +166,7 @@ def test_pytest_changed_files_branch_selection(tmpdir_factory):
assert result.out == ''
assert result.err.split() == (
"Comparing against revision 'HEAD'.\n"
"Found 0 differing files with associated tests.\n").split()
"Found 0 test files associated with changes.\n").split()

result = run(script_file='check/pytest-changed-files',
tmpdir_factory=tmpdir_factory,
Expand All @@ -167,7 +181,7 @@ def test_pytest_changed_files_branch_selection(tmpdir_factory):
assert result.out == ''
assert result.err.split() == (
"Comparing against revision 'master'.\n"
"Found 0 differing files with associated tests.\n").split()
"Found 0 test files associated with changes.\n").split()

result = run(script_file='check/pytest-changed-files',
tmpdir_factory=tmpdir_factory,
Expand All @@ -176,7 +190,7 @@ def test_pytest_changed_files_branch_selection(tmpdir_factory):
assert result.out == ''
assert result.err.split() == (
"Comparing against revision 'origin/master'.\n"
"Found 0 differing files with associated tests.\n").split()
"Found 0 test files associated with changes.\n").split()

result = run(script_file='check/pytest-changed-files',
tmpdir_factory=tmpdir_factory,
Expand All @@ -185,7 +199,7 @@ def test_pytest_changed_files_branch_selection(tmpdir_factory):
assert result.out == ''
assert result.err.split() == (
"Comparing against revision 'upstream/master'.\n"
"Found 0 differing files with associated tests.\n").split()
"Found 0 test files associated with changes.\n").split()

result = run(script_file='check/pytest-changed-files',
tmpdir_factory=tmpdir_factory,
Expand All @@ -194,7 +208,7 @@ def test_pytest_changed_files_branch_selection(tmpdir_factory):
assert result.out == ''
assert result.err.split() == (
"Comparing against revision 'upstream/master'.\n"
"Found 0 differing files with associated tests.\n").split()
"Found 0 test files associated with changes.\n").split()

result = run(script_file='check/pytest-changed-files',
tmpdir_factory=tmpdir_factory,
Expand Down Expand Up @@ -226,8 +240,8 @@ def test_pytest_changed_files_branch_selection(tmpdir_factory):
assert result.exit_code == 0
assert result.out == ''
assert result.err.split() == (
"Comparing against revision 'HEAD'.\n"
"Found 0 differing files with associated tests.\n").split()
"Comparing against revision 'HEAD'.\n"
"Found 0 test files associated with changes.\n").split()

result = run(script_file='check/pytest-changed-files',
tmpdir_factory=tmpdir_factory,
Expand All @@ -238,7 +252,7 @@ def test_pytest_changed_files_branch_selection(tmpdir_factory):
assert result.out == ''
assert result.err.split() == (
"Comparing against revision 'master'.\n"
"Found 0 differing files with associated tests.\n").split()
"Found 0 test files associated with changes.\n").split()

# Works on remotes.
result = run(script_file='check/pytest-changed-files',
Expand All @@ -254,7 +268,7 @@ def test_pytest_changed_files_branch_selection(tmpdir_factory):
assert result.out == ''
assert result.err.split() == (
"Comparing against revision 'origin/master'.\n"
"Found 0 differing files with associated tests.\n").split()
"Found 0 test files associated with changes.\n").split()


@only_on_posix
Expand Down