From e5936c93d265bbf978c36ab874e01076fd6ea60a Mon Sep 17 00:00:00 2001 From: Robbi Bishop-Taylor Date: Fri, 2 Aug 2024 10:00:26 +1000 Subject: [PATCH] Finally fix validation bug --- .github/workflows/dea-coastlines-image.yaml | 45 ++++++++--------- coastlines/validation.py | 2 +- tests/test_coastline.py | 56 ++++++++++----------- 3 files changed, 49 insertions(+), 54 deletions(-) diff --git a/.github/workflows/dea-coastlines-image.yaml b/.github/workflows/dea-coastlines-image.yaml index 7c9ed25..399b2d8 100644 --- a/.github/workflows/dea-coastlines-image.yaml +++ b/.github/workflows/dea-coastlines-image.yaml @@ -98,31 +98,26 @@ jobs: --volume ${GITHUB_WORKSPACE}/tide_models:/var/share/tide_models \ dea_coastlines pytest -v --cov=coastlines --cov-report=xml tests - ls -l . - ls -l ./data/validation/processed/ - ls -l ./tests/ - git status - - # # Commit validation results produced by integration tests back into repo - # - name: Commit validation results into repository - # uses: stefanzweifel/git-auto-commit-action@v4 - # if: github.event_name == 'pull_request' - # continue-on-error: true - # with: - # commit_message: Automatically update integration test validation results - # file_pattern: 'tests/stats_tests.png tests/stats_tests.csv tests/README.md' + # Commit validation results produced by integration tests back into repo + - name: Commit validation results into repository + uses: stefanzweifel/git-auto-commit-action@v4 + if: github.event_name == 'pull_request' + continue-on-error: true + with: + commit_message: Automatically update integration test validation results + file_pattern: 'tests/stats_tests.png tests/stats_tests.csv tests/README.md' - # # Post validation tesults as comment on PR - # - name: Post validation results as comment - # uses: mshick/add-pr-comment@v2 - # if: github.event_name == 'pull_request' - # with: - # message: | - # ![](https://github.com/GeoscienceAustralia/dea-coastlines/blob/${{ github.head_ref }}/tests/stats_tests.png?raw=true") + # Post validation tesults as comment on PR + - name: Post validation results as comment + uses: mshick/add-pr-comment@v2 + if: github.event_name == 'pull_request' + with: + message: | + ![](https://github.com/GeoscienceAustralia/dea-coastlines/blob/${{ github.head_ref }}/tests/stats_tests.png?raw=true") - # For full integration test results, refer to the [Tests directory README](https://github.com/GeoscienceAustralia/dea-coastlines/tree/${{ github.head_ref }}/tests). + For full integration test results, refer to the [Tests directory README](https://github.com/GeoscienceAustralia/dea-coastlines/tree/${{ github.head_ref }}/tests). - # - name: Upload coverage reports to Codecov - # uses: codecov/codecov-action@v3 - # env: - # CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/coastlines/validation.py b/coastlines/validation.py index 1c0a6ff..7605d8b 100644 --- a/coastlines/validation.py +++ b/coastlines/validation.py @@ -2295,7 +2295,7 @@ def deacl_validation( lambda x: pd.Series.mode(x).iloc[0] ) count_vals = val_df.groupby(["year", "id"]).year.count().rename("n") - median_vals = val_df.groupby(["year", "id"]).median() + median_vals = val_df.groupby(["year", "id"]).median(numeric_only=True) # Combine all aggregated stats into one dataframe val_df = pd.concat( diff --git a/tests/test_coastline.py b/tests/test_coastline.py index 1ebe466..13ce47b 100644 --- a/tests/test_coastline.py +++ b/tests/test_coastline.py @@ -76,34 +76,34 @@ def test_generate_continental_cli(): # assert result.output == '' # for debugging assert result.exit_code == 0 -# @pytest.mark.dependency(depends=["test_generate_continental_cli"]) -# def test_validation_cli(capsys): -# runner = CliRunner() -# result = runner.invoke( -# validation_cli, -# [ -# "--inputs_path", -# "data/validation/interim/wrl_narrabeen", -# "--deacl_path", -# "data/processed/tests/coastlines_tests.gpkg", -# "--prefix", -# "tests", -# "--append_stats", -# "True", -# "--markdown_report", -# "True", -# ], -# ) +@pytest.mark.dependency(depends=["test_generate_continental_cli"]) +def test_validation_cli(capsys): + runner = CliRunner() + result = runner.invoke( + validation_cli, + [ + "--inputs_path", + "data/validation/interim/wrl_narrabeen", + "--deacl_path", + "data/processed/tests/coastlines_tests.gpkg", + "--prefix", + "tests", + "--append_stats", + "True", + "--markdown_report", + "True", + ], + ) -# # Prepare detailed error information -# error_info = { -# "exit_code": result.exit_code, -# "output": result.output, -# "exception": str(result.exception) if result.exception else None, -# } + # Prepare detailed error information + error_info = { + "exit_code": result.exit_code, + "output": result.output, + "exception": str(result.exception) if result.exception else None, + } -# # Convert error_info to a formatted string -# error_details = json.dumps(error_info, indent=2) + # Convert error_info to a formatted string + error_details = json.dumps(error_info, indent=2) -# # Use the detailed error information in the assertion message -# assert result.exit_code == 0, f"Command failed. Error details:\n{error_details}" + # Use the detailed error information in the assertion message + assert result.exit_code == 0, f"Command failed. Error details:\n{error_details}"