Skip to content

Commit

Permalink
Make bash_scripts_test more tolerant to different git tool versions (#…
Browse files Browse the repository at this point in the history
…1141)

On my machine the `test_pytest_changed_files_file_selection` was failing because command added whitespaces before counts ("`Found        0 differing`").

The `test_pytest_and_incremental_coverage_branch_selection` has additional usage lines.
  • Loading branch information
mrwojtek authored and CirqBot committed Nov 23, 2018
1 parent 4b0a622 commit f944102
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion check/pytest-and-incremental-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ PYTHONPATH="$(pwd)" python dev_tools/run_pytest_and_incremental_coverage.py "${r
result=$?

# Clean up generated coverage files.
find | grep "\.py,cover$" | xargs rm -f
find . | grep "\.py,cover$" | xargs rm -f

exit ${result}
66 changes: 39 additions & 27 deletions dev_tools/bash_scripts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def test_pytest_changed_files_file_selection():
'git commit -m test --quiet --no-gpg-sign\n')
assert result.exit_code == 0
assert result.out == ''
assert result.err == ("Comparing against revision 'HEAD~1'.\n"
"Found 0 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'HEAD~1'.\n"
"Found 0 differing files with associated tests.\n").split()

result = run(script_file='check/pytest-changed-files',
arg='HEAD~1',
Expand All @@ -88,8 +89,9 @@ def test_pytest_changed_files_file_selection():
'git commit -m test --quiet --no-gpg-sign\n')
assert result.exit_code == 0
assert result.out == 'INTERCEPTED pytest file_test.py\n'
assert result.err == ("Comparing against revision 'HEAD~1'.\n"
"Found 1 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'HEAD~1'.\n"
"Found 1 differing files with associated tests.\n").split()

result = run(script_file='check/pytest-changed-files',
arg='HEAD~1',
Expand All @@ -98,8 +100,9 @@ def test_pytest_changed_files_file_selection():
'git commit -m test --quiet --no-gpg-sign\n')
assert result.exit_code == 0
assert result.out == 'INTERCEPTED pytest file_test.py\n'
assert result.err == ("Comparing against revision 'HEAD~1'.\n"
"Found 1 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'HEAD~1'.\n"
"Found 1 differing files with associated tests.\n").split()

result = run(script_file='check/pytest-changed-files',
arg='HEAD',
Expand All @@ -109,8 +112,9 @@ def test_pytest_changed_files_file_selection():
'echo x > file_test.py\n')
assert result.exit_code == 0
assert result.out == 'INTERCEPTED pytest file_test.py\n'
assert result.err == ("Comparing against revision 'HEAD'.\n"
"Found 1 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'HEAD'.\n"
"Found 1 differing files with associated tests.\n").split()

result = run(script_file='check/pytest-changed-files',
arg='HEAD',
Expand All @@ -120,8 +124,9 @@ def test_pytest_changed_files_file_selection():
'echo x > file.py\n')
assert result.exit_code == 0
assert result.out == 'INTERCEPTED pytest file_test.py\n'
assert result.err == ("Comparing against revision 'HEAD'.\n"
"Found 1 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'HEAD'.\n"
"Found 1 differing files with associated tests.\n").split()


@only_in_python3_on_posix
Expand All @@ -130,8 +135,9 @@ def test_pytest_changed_files_branch_selection():
result = run(script_file='check/pytest-changed-files', arg='HEAD')
assert result.exit_code == 0
assert result.out == ''
assert result.err == ("Comparing against revision 'HEAD'.\n"
"Found 0 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'HEAD'.\n"
"Found 0 differing files with associated tests.\n").split()

result = run(script_file='check/pytest-changed-files', arg='HEAD~9999')
assert result.exit_code == 1
Expand All @@ -141,29 +147,33 @@ def test_pytest_changed_files_branch_selection():
result = run(script_file='check/pytest-changed-files')
assert result.exit_code == 0
assert result.out == ''
assert result.err == ("Comparing against revision 'master'.\n"
"Found 0 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'master'.\n"
"Found 0 differing files with associated tests.\n").split()

result = run(script_file='check/pytest-changed-files',
setup='git branch origin/master')
assert result.exit_code == 0
assert result.out == ''
assert result.err == ("Comparing against revision 'origin/master'.\n"
"Found 0 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'origin/master'.\n"
"Found 0 differing files with associated tests.\n").split()

result = run(script_file='check/pytest-changed-files',
setup='git branch upstream/master')
assert result.exit_code == 0
assert result.out == ''
assert result.err == ("Comparing against revision 'upstream/master'.\n"
"Found 0 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'upstream/master'.\n"
"Found 0 differing files with associated tests.\n").split()

result = run(script_file='check/pytest-changed-files',
setup='git branch upstream/master; git branch origin/master')
assert result.exit_code == 0
assert result.out == ''
assert result.err == ("Comparing against revision 'upstream/master'.\n"
"Found 0 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'upstream/master'.\n"
"Found 0 differing files with associated tests.\n").split()

result = run(script_file='check/pytest-changed-files',
arg='file',
Expand Down Expand Up @@ -191,17 +201,19 @@ def test_pytest_changed_files_branch_selection():
'git commit -m test --quiet --no-gpg-sign\n')
assert result.exit_code == 0
assert result.out == ''
assert result.err == ("Comparing against revision 'HEAD'.\n"
"Found 0 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'HEAD'.\n"
"Found 0 differing files with associated tests.\n").split()

result = run(script_file='check/pytest-changed-files',
setup='touch master\n'
'git add -A\n'
'git commit -m test --quiet --no-gpg-sign\n')
assert result.exit_code == 0
assert result.out == ''
assert result.err == ("Comparing against revision 'master'.\n"
"Found 0 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'master'.\n"
"Found 0 differing files with associated tests.\n").split()

# Works on remotes.
result = run(script_file='check/pytest-changed-files',
Expand All @@ -214,13 +226,13 @@ def test_pytest_changed_files_branch_selection():
'git fetch origin master --quiet 2> /dev/null\n')
assert result.exit_code == 0
assert result.out == ''
assert result.err == ("Comparing against revision 'origin/master'.\n"
"Found 0 differing files with associated tests.\n")
assert result.err.split() == (
"Comparing against revision 'origin/master'.\n"
"Found 0 differing files with associated tests.\n").split()


@only_in_python3_on_posix
def test_pytest_and_incremental_coverage_branch_selection():

result = run(script_file='check/pytest-and-incremental-coverage',
arg='HEAD')
assert result.exit_code == 0
Expand Down

0 comments on commit f944102

Please sign in to comment.