Skip to content

Fix importing pip_requirements_parser #21

Fix importing pip_requirements_parser

Fix importing pip_requirements_parser #21

name: Test working-directory input
on: push
jobs:
test-working-directory:
runs-on: ubuntu-latest
env:
GITHUB_ACTION_PATH: ${{ github.workspace }}
INPUT_VERSION: "@gh-action-working-directory"
steps:
- uses: actions/checkout@v4
- name: Set up test environment
run: |
mkdir -p $RUNNER_TEMP/test-repo
cd $RUNNER_TEMP/test-repo
git init
git config user.email "[email protected]"
git config user.name "Test User"
git commit --allow-empty -m "Initial empty commit"
echo 'def hello(): return "Hello, World!"' > test.py
git add test.py
git commit -m "Add test.py file"
echo 'def hello(): return "Hello, World!"' > test.py
- name: Run Darker without working-directory (should not reformat)
id: no-work-dir
run: |
python ${{ github.workspace }}/action/main.py
env:
INPUT_OPTIONS: "--check --diff"
INPUT_SRC: "test.py"
INPUT_REVISION: "HEAD"
- name: Check that test.py was not found
run: |
if [ "${{ steps.no-work-dir.outputs.exitcode }}" != "2" ]; then
echo "::error::Darker should have failed with exit code 2"
exit 1
fi
- name: Run Darker with correct working-directory
id: right-workdir
if: always()
run: |
output=$(python ${{ github.workspace }}/action/main.py)
echo "stdout<<EOF" >> $GITHUB_OUTPUT
echo "$output" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
env:
INPUT_OPTIONS: "--check --diff"
INPUT_WORKING_DIRECTORY: ${{ runner.temp }}/test-repo
INPUT_SRC: "test.py"
INPUT_REVISION: "HEAD"
- name: Verify exit code 1 when reformatting is needed
if: always() && steps.right-workdir.outputs.exitcode != '1'
run: |
echo "::error::Darker should have exited with code 1"
exit 1
- name: Verify file was reformatted
if: always() && !contains(steps.right-workdir.outputs.stdout, '@@')
run: |
echo "::error::Darker did not output a diff as expected"
exit 1
- name: Run Darker with incorrect working-directory (should not reformat)
if: always()
id: wrong-work-dir
run: |
python ${{ github.workspace }}/action/main.py
env:
INPUT_OPTIONS: "--check --diff"
INPUT_WORKING_DIRECTORY: ${{ runner.temp }}/non-existent-dir
INPUT_SRC: "test.py"
INPUT_REVISION: "HEAD"
- name: Check that Darker failed with a non-existing working-directory
if: always() && steps.wrong-work-dir.outputs.exitcode != '21'
run: |
echo "::error::Darker should have exited with code 21"
exit 1
- name: Test file not found error
id: file-not-found
if: always()
run: |
python ${{ github.workspace }}/action/main.py
env:
INPUT_OPTIONS: "--check --diff"
INPUT_WORKING_DIRECTORY: ${{ runner.temp }}/test-repo
INPUT_SRC: "non_existent_file.py"
- name: Check file not found error code
if: always() && steps.file-not-found.outputs.exitcode != '2'
run: |
echo "::error::Darker should have exited with code 2"
exit 1
- name: Test invalid arguments error
id: invalid-arguments
if: always()
run: |
python ${{ github.workspace }}/action/main.py
env:
INPUT_OPTIONS: "--invalid-option"
- name: Check invalid arguments error code
if: always() && steps.invalid-arguments.outputs.exitcode != '3'
run: |
echo "::error::Darker should have exited with code 3"
exit 1
- name: Test missing dependencies error
id: missing-deps
if: always()
run: |
python ${{ github.workspace }}/action/main.py
env:
INPUT_OPTIONS: "--isort"
INPUT_SRC: "test.py"
- name: Check missing dependencies error code
if: always() && steps.missing-deps.outputs.exitcode != '4'
run: |
echo "::error::Darker should have exited with code 4"
exit 1