Skip to content

Commit

Permalink
make flynt incremental (#3905)
Browse files Browse the repository at this point in the history
Fixes #3901.
  • Loading branch information
balopat committed Mar 11, 2021
1 parent 745790e commit bfb7aa3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
14 changes: 10 additions & 4 deletions check/format-incremental
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$(git rev-parse --show-toplevel)"

# TODO: Remove '-e cirq/ops/pauli_string.py' once the line is covered (https://github.com/quantumlib/Cirq/issues/3804)
flynt cirq dev_tools examples -f -e cirq/ops/pauli_string.py

FLYNTSTATUS=$?

# Parse arguments.
only_print=1
Expand Down Expand Up @@ -109,6 +105,16 @@ if (( any_files == 0 )); then
exit 0
fi

flynt_args=("--quiet" "-f")
if (( only_print == 1 )); then
flynt_args+=("--dry-run")
fi

# TODO: Remove '-e cirq/ops/pauli_string.py' once the line is covered (https://github.com/quantumlib/Cirq/issues/3804)
flynt ${format_files} "${flynt_args[@]}" -e cirq/ops/pauli_string.py
FLYNTSTATUS=$?

echo "Running the black formatter..."

args=("--color")
if (( only_print == 1 )); then
Expand Down
17 changes: 4 additions & 13 deletions dev_tools/bash_scripts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,7 @@ def test_incremental_format_branch_selection(tmpdir_factory):
script_file='check/format-incremental', tmpdir_factory=tmpdir_factory, arg='HEAD~9999'
)
assert result.exit_code == 1
assert (
result.out
== """Running flynt v.0.60
`cirq` not found
"""
)
assert result.out == ''
assert "No revision 'HEAD~9999'." in result.err

result = run(script_file='check/format-incremental', tmpdir_factory=tmpdir_factory)
Expand Down Expand Up @@ -555,12 +550,8 @@ def test_incremental_format_branch_selection(tmpdir_factory):
setup='git checkout -b other --quiet\ngit branch -D master --quiet\n',
)
assert result.exit_code == 1
assert (
result.out
== """Running flynt v.0.60
`cirq` not found
"""
)
assert result.out == ''

assert 'No default revision found to compare against' in result.err

# Works when ambiguous between revision and file.
Expand Down Expand Up @@ -598,7 +589,7 @@ def test_incremental_format_branch_selection(tmpdir_factory):
'git add -A\n'
'git commit -q -m test3 --no-gpg-sign\n',
)
assert result.exit_code == 1
assert result.exit_code == 0
assert 'INTERCEPTED black --color --check --diff alt.py' in result.out
assert result.err.startswith("Comparing against revision 'master' (merge base ")

Expand Down

0 comments on commit bfb7aa3

Please sign in to comment.