diff --git a/.github/workflows/build_and_test_mac.yml b/.github/workflows/build_and_test_mac.yml new file mode 100644 index 0000000..c6032a3 --- /dev/null +++ b/.github/workflows/build_and_test_mac.yml @@ -0,0 +1,80 @@ +name: Build and Test - MacOS + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +jobs: + build: + name: Build flows2fim + + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Docker Compose + uses: docker/setup-buildx-action@v3 + + - name: Run Docker Compose + run: | + docker compose up -d + docker ps + + - name: Attach to running container and Build + run: | + CONTAINER_ID=$(docker ps -q | head -n 1) + if [ -n "$CONTAINER_ID" ]; then + docker exec $CONTAINER_ID /bin/bash -c "./scripts/build-darwin-arm64.sh" + docker compose down + else + echo "No running containers found" + exit 1 + fi + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: flows2fim + path: builds/darwin-arm64 + + test: + name: Test flows2fim + runs-on: macos-latest + needs: build + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: flows2fim + path: builds/darwin-arm64 + + - name: Add flows2fim to PATH + run: | + ls -R builds/darwin-arm64 + sudo chmod a+x ./builds/darwin-arm64/flows2fim + ./builds/darwin-arm64/flows2fim --version + echo "builds/darwin-arm64" >> $GITHUB_PATH + + - name: Install & Configure GDAL + run: | + brew install gdal + + - name: Verify gdal installation + run: | + gdalinfo --version + + - name: Issue flows2fim controls test cases + run: | + ./scripts/test_suite_mac.sh controls + + - name: Issue flows2fim fim test cases + run: | + ./scripts/test_suite_mac.sh fim diff --git a/INSTALL.md b/INSTALL.md index df6b763..14eb124 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -15,7 +15,7 @@ - The easiest way is via [**OSGeo4W**](https://trac.osgeo.org/osgeo4w/#QuickStartforOSGeo4WUsers) 2. **Setup flows2fim** - - Go to the [**Releases**](https://github.com/ar-siddiqui/flows2fim/releases) page and download the `flows2fim-windows-amd64.zip` + - Go to the [**Releases**](https://github.com/NGWPC/flows2fim/releases) page and download the `flows2fim-windows-amd64.zip` - Unzip and copy `flows2fim.exe` into `C:\OSGeo4W\bin` 3. **(Optional) Enable `gdal_ls`** @@ -45,15 +45,15 @@ There are various ways to install GDAL. See GDAL documentation for more details. If you are struggling with GDAL installation, consider using Docker. 2. **Setup flows2fim** - - **Option 1. - Download** - - Go to the [**Releases**](https://github.com/ar-siddiqui/flows2fim/releases) page and download the `flows2fim-linux-amd64.tar.gz` - - Extract it and move to a directory in PATH (e.g., `/usr/local/bin`) and make it executable: + - **Option 1 - Download** + - Go to the [**Releases**](https://github.com/NGWPC/flows2fim/releases) page and download the `flows2fim-linux-amd64.tar.gz` + - Extract it and move to a directory in `$PATH` (e.g., `/usr/local/bin`) and make it executable: ```bash tar -xvf flows2fim-linux-amd64.tar.gz sudo mv flows2fim /usr/local/bin/ sudo chmod +x /usr/local/bin/flows2fim ``` - - **Option 2. - Build from source** + - **Option 2 - Build from source** - cd into root of repository - Build container - `docker compose up -d` @@ -63,7 +63,7 @@ - `docker exec $CONTAINER_ID /bin/bash -c "./scripts/build-linux-amd64.sh"` - Shutdown container - `docker compose down` - - Move executable to $PATH + - Move executable to `$PATH` - `sudo mv builds/linux-amd64/flows2fim /usr/local/bin/` - `sudo chmod +x /usr/local/bin/flows2fim` 3. **(Optional) Enable `gdal_ls`** @@ -78,3 +78,66 @@ - Run `flows2fim --version` to confirm everything works. - Run `gdalinfo --version` to confirm everything works. - (Optional) Run `gdal_ls.py --version` if you set it up. + +## Mac + +1. **Install GDAL** + + The easiest way to install GDAL on a Mac is through homebrew. + If [homebrew](https://brew.sh/) is not on your Mac, install it: + ```bash + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + ``` + Verify homebrew installation: + ```bash + brew --version + ``` + Install GDAL: + ``` + brew install gdal + ``` + Verify: + ``` + gdalinfo --version + ``` + + There are various ways to install GDAL. See GDAL documentation for more details. If you are struggling with GDAL installation, consider using Docker. + +2. **Setup flows2fim** + - **Option 1 - Download** + - Go to the [**Releases**](https://github.com/NGWPC/flows2fim/releases) page and download (double click) `flows2fim-darwin-arm64.tar.gz` + - Open the Mac Finder application and navigate to your `Downloads` folder. + - Right click > Open the `flows2fim-darwin-arm64.tar.gz` file. This *should* avoid errors arising from Apple security settings. + - In a terminal window, move the flows2fim executable to a directory in your `$PATH` (e.g., `/usr/local/bin`), and add execute permissions: + ```bash + cd ~/Downloads + sudo mv flows2fim /usr/local/bin/ + sudo chmod a+x /usr/local/bin/flows2fim + ``` + - Verify `flows2fim` is executable and in your `$PATH`. + ```bash + flows2fim --version + ``` + - If the error `"flows2fim" can't be opened because Apple cannot check it for malicious software.` or similar comes up, you may temporarily override your Mac's security settings with the following command: + ```bash + xattr -d com.apple.quarantine /usr/local/bin/flows2fim + ``` + + - **Option 2 - Build from source** + - cd into root of repository + - Build container + - `docker compose up -d` + - Get flows2fim CONTAINER_ID + - `CONTAINER_ID=$(docker ps -q | head -n 1)` + - Issue build script + - `docker exec $CONTAINER_ID /bin/bash -c "./scripts/build-darwin-arm64.sh"` + - Shutdown container + - `docker compose down` + - Move executable to `$PATH` + - `sudo mv builds/darwin-arm64/flows2fim /usr/local/bin/` + - `sudo chmod a+x /usr/local/bin/flows2fim` + +3. **`gdal_ls` not supported on MacOS currently (gdal_ls is not included in gdal homebrew installation)** + +4. **Verify** + - Run `flows2fim --version` to confirm everything works. diff --git a/README.md b/README.md index cededf9..1bff499 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # `flows2fim` -[![Build and Test - Linux](https://github.com/ar-siddiqui/flows2fim/actions/workflows/build_and_test_linux.yml/badge.svg?event=push)](https://github.com/ar-siddiqui/flows2fim/actions/workflows/build_and_test_linux.yml) +[![Build and Test - Linux](https://github.com/NGWPC/flows2fim/actions/workflows/build_and_test_linux.yml/badge.svg?event=push)](https://github.com/NGWPC/flows2fim/actions/workflows/build_and_test_linux.yml) [![Build and Test - Mac](https://github.com/NGWPC/flows2fim/actions/workflows/build_and_test_mac.yml/badge.svg?event=push)](https://github.com/NGWPC/flows2fim/actions/workflows/build_and_test_mac.yml) ![alt text](image.png) ## Overview @@ -56,7 +56,3 @@ Run `./scripts/build-linux-amd64.sh` This will place the executable in `builds/l ## Installation [Installation](INSTALL.md) - -## Examples -[Examples](EXAMPLES.md) - diff --git a/scripts/test_suite_mac.sh b/scripts/test_suite_mac.sh new file mode 100755 index 0000000..966612d --- /dev/null +++ b/scripts/test_suite_mac.sh @@ -0,0 +1,561 @@ +#!/bin/bash + +# This script provies a comprehensive test suite of the built flows2fim executable on +# linux systems, also including regression tests. This script, as well as testdata/reference_data +# will need to be manually updated as features change. See testdata/readme.md for more information +# on how to update the /testdata directory appropriately. + +usage() { + echo " + This script tests the built flows2fim executable's methods with a combination of parameters. + It must be run from the root directory of the flows2fim repository to ensure proper pathing for + test data. + + Usage: ./scripts/test_suite_linux.sh [OPTIONS] [METHOD] + + OPTIONS: + -d, --dev Run tests using 'go run main.go' instead of compiled binary + -h, --help Show this help message + + METHODS: + controls: Only issue the controls tests. + e.g.: ./scripts/test_suite_linux.sh controls + fim: Only issue the fim tests. + e.g.: ./scripts/test_suite_linux.sh fim + validate: Only issue the validate tests. + e.g.: ./scripts/test_suite_linux.sh validate + + Providing no method, or 'all', will test all flows2fim methods, controls, fim, & validate. + " +} + +# Assign the command line argument if given, else 'all' is the default +dev_mode=false +cmd="flows2fim" +method="all" # Default to 'all' + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case "$1" in + -d|--dev) + dev_mode=true + cmd="go run main.go" + shift + ;; + -h|--help) + usage + exit 0 + ;; + -*) + echo "Invalid option: $1" + usage + exit 1 + ;; + *) + method="$1" + shift + ;; + esac +done + +# Check if this script is being issued from the repo's root to ensure consistent filepaths +if [ "$(git rev-parse --show-toplevel)" != "$(pwd)" ]; then + printf "Error: This script must be run from the root directory of the flows2fim repository." + usage + exit 1 +fi + +# Ensure flows2fim is installed, available, and executable +if $cmd --version > /dev/null; then + printf "\n\t>>>> Testing availability of flows2fim executable. Output of flows2fim --version: <<<<\n\n" + $cmd --version +else + printf "flows2fim is not available" + usage + exit 1 +fi + +# Set paths and configurable variables +data_folder=testdata +ref_dir=$data_folder/reference_data +db_path=$ref_dir/db +controls_benchmark_dir=$ref_dir/controls +fim_benchmark_dir=$ref_dir/fim +flows_files_dir=$ref_dir/flows_files +library_benchmark=$ref_dir/library +start_reaches_dir=$ref_dir/start_reaches +fim_reference_output_formats=$ref_dir/fim_output_formats_mac + +test_outputs=$data_folder/test_out +control_test_outputs=$test_outputs/controls +fim_test_outputs=$test_outputs/fim +fim_test_output_formats=$test_outputs/fim_output_formats + +# Set counter for failing tests +total_count=0 +total_passed=0 + +test_help_statement() { + printf "\n\t>>>> Test the --help usage statement <<<<\n\n" + $cmd --help +} + +exit_if_failure() { + local failed=$1 + if [ "$failed" -gt 0 ]; then + printf "\n\t>>>> ${failed} TESTS FAILED <<<<\n\n" + exit 1 + else + exit 0 + fi +} + +compare_directories() { + # Set args + local dir1=$1 + local dir2=$2 + local fim=$3 + # Loop through files in dir1 and compare with dir2 + for file in "$dir1"/*; do + filename=$(basename "$file") + filepath2="$dir2/$filename" + # Skip the one off .vrt relative test when comparing directories + if [ "$filename" = "fim_2year_test_rel_false.vrt" ]; then + continue + fi + # Check if the file exists in dir2, and if the "fim" argument was given + if [ -f "$filepath2" ] && [ "$fim" = "fim" ]; then + tempfile=$(mktemp) + if [ "${filename:10:13}" = "vrt" ]; then + temp_out=$(diff "$file" "$filepath2") + if [ "$temp_out" != "" ]; then + printf "\t Output of diff: \n "$file" "$filepath2" \n $temp_out" + # printf "\t \u274c Files differ: $filename \n" + fi + continue + fi + gdalcompare.py $file $filepath2 &> "$tempfile" + # cat "$tempfile" + gdalcompare_output=$(tail -n 1 "$tempfile" | grep -Eo "[0-9]+" | tail -n 1) + # echo "gdalcompare_output: $gdalcompare_output" + # Remove temp file + rm "$tempfile" + # Set tolerance value of gdalcompare + gdalcompare_difference_tolerance=2 + # If there are more than more differences than the tolerance value above, this test fails + if (( $gdalcompare_output > $gdalcompare_difference_tolerance )); then + printf "\n\t \u274c Files differ: $filename \n" + fi + elif [ -f "$filepath2" ]; then + # Compare the files + if ! cmp -s "$file" "$filepath2"; then + temp_out=$(cmp "$file" "$filepath2") + printf "Output of cmp -s "$file" "$filepath2" : \n\n $temp_out" + printf "\t \u274c Files differ: $filename \n" + fi + else + printf "\t \u274c File not found in dir2: $filename \n" + fi + done + # Loop through files in dir2 to find any not in dir1 + for file in "$dir2"/*; do + filename=$(basename "$file") + filepath1="$dir1/$filename" + # Check if the file does not exist in dir1 + if [ ! -f "$filepath1" ]; then + printf "\t \u274c File in $dir2 not found in $dir1: $filename \n" + fi + done +} + +# Define functions for each flows2fim method +controls_test_cases() { + local num_test_cases_controls=9 + local failed_controls_testcases=0 + total_count=$(( total_count + num_test_cases_controls)) + # If previous directory exists, remove it + if [ -d "$control_test_outputs" ]; then + rm -rf "$control_test_outputs" + fi + # Create new test output directory + mkdir -p $control_test_outputs + + printf "\n\t###### ${num_test_cases_controls} TEST CASES FOR flows2fim controls ######\n\n" + + # Define the recurrence interval array + local recurrence_interval=(2 5 10 25 50 100) + printf "(1/${num_test_cases_controls})\t>>>> Generate controls.csv files from " + printf "${recurrence_interval[*]} year recurrence interval data for Regression Testing. <<<<\n\n" + + for interval in "${recurrence_interval[@]}"; do + # Execute flows2fim with each recurrence interval + $cmd controls -db $db_path/ripple.gpkg \ + -f $flows_files_dir/flows_${interval}year.csv \ + -o $control_test_outputs/controls_${interval}year.csv \ + -scsv $start_reaches_dir/start_reaches.csv + done + + printf "\n(2/${num_test_cases_controls})\t>>>> Regression Tests for all recurrence interval controls files <<<<\n\n" + # Compare controls files from recently generated test data and benchmark data + # Capture the output of the comparison as a variable if there is no difference + diff_output=$(compare_directories "$control_test_outputs" "$controls_benchmark_dir") + + if [ -z "$diff_output" ]; then + printf "\t \u2714 No difference in controls files. \n\n" + else + printf "\t \u274c Outputs differ: \n" + printf "\t $diff_output \n" + failed_controls_testcases=$((failed_controls_testcases + 1)) + fi + + ## Assert correct errors thrown + printf "(3/${num_test_cases_controls})\t>>>> Assert Error thrown from no start reaches parameter <<<<\n\n" + # Create and assign temp file + tempfile=$(mktemp) + # Test case + $cmd controls -db $db_path/ripple.gpkg \ + -f $flows_files_dir/flows_2year.csv \ + -o $control_test_outputs/controls_2year.csv &> "$tempfile" + # Assign error string + expected_error_substring="either a CSV file or start reach IDs and control stages must be provided" + # Search (grep) for expected error substring in temporary output file + if grep -q "$expected_error_substring" "$tempfile"; then + printf "\t \u2714 Correct error thrown. \n\n" + else + printf "\t \u274c Error messaging inconsistent \n\n" + failed_controls_testcases=$((failed_controls_testcases + 1)) + fi + # Remove temp file + rm "$tempfile" + + printf "(4/${num_test_cases_controls})\t>>>> Assert Error thrown from no start reaches parameter, or output parameter <<<<\n\n" + # Create and assign temp file + tempfile=$(mktemp) + # Test case + $cmd controls -db $db_path/ripple.gpkg -f $flows_files_dir/flows_2year.csv &> "$tempfile" + # Assign error string + expected_error_substring="missing required flags" + # Search (grep) for expected error substring in temporary output file + if grep -q "$expected_error_substring" "$tempfile"; then + printf "\t \u2714 Correct error thrown. \n\n" + else + printf "\t \u274c Error messaging inconsistent \n\n" + failed_controls_testcases=$((failed_controls_testcases + 1)) + fi + # Remove temp file + rm "$tempfile" + + printf "(5/${num_test_cases_controls})\t>>>> Assert Error thrown from only providing db parameter <<<<\n\n" + # Create and assign temp file + tempfile=$(mktemp) + # Test case + $cmd controls -db $db_path/ripple.gpkg &> "$tempfile" + # Assign error string + expected_error_substring="missing required flags" + # Search (grep) for expected error substring in temporary output file + if grep -q "$expected_error_substring" "$tempfile"; then + printf "\t \u2714 Correct error thrown. \n\n" + else + printf "\t \u274c Error messaging inconsistent. \n\n" + failed_controls_testcases=$((failed_controls_testcases + 1)) + fi + # Remove temp file + rm "$tempfile" + + ## Test empty controls file created under different flows file and start reaches file inputs + printf "(6/${num_test_cases_controls})\t>>>> If start reaches file is empty, confirm controls file is empty <<<<\n\n" + # Create and assign temp file + tempfile=$(mktemp) + # Test case + $cmd controls -db $db_path/ripple.gpkg \ + -f $flows_files_dir/flows_2year.csv \ + -o $tempfile \ + -scsv $start_reaches_dir/empty_start_reaches.csv &> /dev/null + # Here we use head -n 2 to capture the first two line of the tmp file + file_contents=$(head -n 2 "$tempfile") + # Remove temp file + rm "$tempfile" + # Assign error string + assert_file_output="reach_id,flow,control_stage" + # Compare Error messaging and print + if [ "$file_contents" = "$assert_file_output" ]; then + printf "\t \u2714 Passed: Output file created and empty. \n\n" + else + printf "\t \u274c Failed: Output file not empty \n\n" + failed_controls_testcases=$((failed_controls_testcases + 1)) + fi + + printf "(7/${num_test_cases_controls})\t>>>> If flows file is empty, confirm Flow not found error thrown <<<<\n\n" + # Create and assign temp file + tempfile=$(mktemp) + temp_out=$(mktemp) + # Test case + $cmd controls -db $db_path/ripple.gpkg \ + -f $flows_files_dir/empty_file.csv \ + -o $temp_out \ + -scsv $start_reaches_dir/start_reaches.csv &> "$tempfile" + # Assign error string + expected_error_substring="Flow not found for reach" + # Search (grep) for expected error substring in temporary output file + if grep -q "$expected_error_substring" "$tempfile"; then + printf "\t \u2714 Passed: Flow not found error thrown. \n\n" + else + printf "\t \u274c Failed: Flow not found error not thrown \n\n" + failed_controls_testcases=$((failed_controls_testcases + 1)) + fi + # Remove temp files + rm "$temp_out" + rm "$tempfile" + + printf "(8/${num_test_cases_controls})\t>>>> If flows file's columns are swapped, confirm Flow not found error thrown <<<<\n\n" + # Create and assign temp file + tempfile=$(mktemp) + temp_out=$(mktemp) + # Test case + $cmd controls -db $db_path/ripple.gpkg \ + -f $flows_files_dir/columns_swapped.csv \ + -o $temp_out \ + -scsv $start_reaches_dir/start_reaches.csv &> "$tempfile" + # Assign error string + expected_error_substring="Flow not found for reach" + # Search (grep) for expected error substring in temporary output file + if grep -q "$expected_error_substring" "$tempfile"; then + printf "\t \u2714 Passed: Flow not found error thrown. \n\n" + else + printf "\t \u274c Failed: Flow not found error not thrown \n\n" + failed_controls_testcases=$((failed_controls_testcases + 1)) + fi + # Remove temp files + rm "$temp_out" + rm "$tempfile" + + printf "(9/${num_test_cases_controls})\t>>>> If flows file's values are empty, confirm Flow not found error thrown <<<<\n\n" + # Create and assign temp file + tempfile=$(mktemp) + temp_out=$(mktemp) + # Test case + $cmd controls -db $db_path/ripple.gpkg \ + -f $flows_files_dir/empty_flow_values_no_header.csv \ + -o $temp_out \ + -scsv $start_reaches_dir/start_reaches.csv &> "$tempfile" + # Assign error string + expected_error_substring="Flow not found for reach" + # Search (grep) for expected error substring in temporary output file + if grep -q "$expected_error_substring" "$tempfile"; then + printf "\t \u2714 Passed: Flow not found error thrown. \n\n" + else + printf "\t \u274c Failed: Flow not found error not thrown \n\n" + failed_controls_testcases=$((failed_controls_testcases + 1)) + fi + # Remove temp files + rm "$temp_out" + rm "$tempfile" + + controls_passed=$((num_test_cases_controls - failed_controls_testcases)) + total_passed=$(( total_passed + controls_passed)) +} + +fim_test_cases() { + local num_test_cases_fim=8 + local failed_fim_testcases=0 + total_count=$(( total_count + num_test_cases_fim)) + # If previous directories exists, remove them + if [ -d "$fim_test_outputs" ]; then + rm -rf "$fim_test_outputs" + rm -rf "$fim_test_output_formats" + fi + # Create new test output directories + mkdir -p $fim_test_outputs + mkdir -p $fim_test_output_formats + + printf "\n\t###### ${num_test_cases_fim} TEST CASES FOR flows2fim fim ######\n\n" + printf "\n\t>>>> Test flows2fim fim <<<<\n\n" + + # Define the recurrence interval array + local recurrence_interval=(2 5 10 25 50 100) + printf "(1/${num_test_cases_fim})\t>>>> Generate fim_year.tif files from " + printf "${recurrence_interval[*]} year recurrence interval data for Regression Testing. <<<<\n\n" + local fim_file_format="GTiff" + for interval in "${recurrence_interval[@]}"; do + # Execute $cmd with each recurrence interval + $cmd fim \ + -c $controls_benchmark_dir/controls_${interval}year.csv \ + -fmt $fim_file_format \ + -lib $library_benchmark \ + -type depth \ + -o $fim_test_outputs/fim_${interval}year.tif &> /dev/null + done + + printf "(2/${num_test_cases_fim})\t>>>> Regression Tests for all recurrence interval fim.tif files <<<<\n\n" + # Compare fim files from recently generated test data and benchmark data + # Capture the output of the compare_directories function as a variable + diff_output=$(compare_directories "$fim_test_outputs" "$fim_benchmark_dir" "fim") + + # If there is no differnce, test pass + if [ -z "$diff_output" ]; then + printf "\t \u2714 No significant difference in fim.tif files. \n\n" + else + printf "\t \u274c Outputs differ: \n\n" + printf "\t $diff_output \n" + failed_fim_testcases=$((failed_fim_testcases + 1)) + fi + + printf "(3/${num_test_cases_fim})\t>>>> Generate fim files in different output formats <<<<\n\n" + local file_formats=( "gtiff" "cog" "vrt" ) + + for format in "${file_formats[@]}"; do + local output_file=fim_2year.$format + # Execute flows2fim with each file format (redirecting stdout to tidy logging) + $cmd fim \ + -c $controls_benchmark_dir/controls_2year.csv \ + -fmt $format \ + -lib $library_benchmark \ + -type depth \ + -o $fim_test_output_formats/$output_file &> /dev/null + done + + printf "(4/${num_test_cases_fim})\t>>>> Regression Tests for different output formats <<<<\n\n" + # Capture the output of the comparison function as a variable + diff_output=$(compare_directories "$fim_reference_output_formats" "$fim_test_output_formats" "fim") + # If there is no difference between directories, test pass + if [ -z "$diff_output" ]; then + printf "\t \u2714 No differences in .cog, .vrt & .tif files. \n\n" + else + printf "\t \u274c Outputs differ: \n\n" + printf "$diff_output \n" + failed_fim_testcases=$((failed_fim_testcases + 1)) + fi + + printf "(5/${num_test_cases_fim})\t>>>> Assert Error thrown from no controls file parameter <<<<\n\n" + # Create and assign temp file + tempfile=$(mktemp) + # Test case + $cmd fim \ + -fmt $format \ + -lib $library_benchmark \ + -type depth \ + -o $fim_test_outputs/fim_test.tif &> "$tempfile" + # Assign error string + expected_error_substring="missing required flags" + # Search (grep) for expected error substring in temporary output file + if grep -q "$expected_error_substring" "$tempfile"; then + printf "\t \u2714 Correct error thrown. \n\n" + else + printf "\t \u274c Error messaging inconsistent \n\n" + failed_fim_testcases=$((failed_fim_testcases + 1)) + fi + # Remove temp file + rm "$tempfile" + + printf "(6/${num_test_cases_fim})\t>>>> Assert Error thrown from no library parameter <<<<\n\n" + # Create and assign temp file + tempfile=$(mktemp) + # Test case + $cmd fim \ + -c $controls_benchmark_dir/controls_2year.csv \ + -fmt "GTiff" \ + -type depth \ + -o $fim_test_outputs/fim_test.tif &> "$tempfile" + # Assign error string + expected_error_substring="missing required flags" + # Search (grep) for expected error substring in temporary output file + if grep -q "$expected_error_substring" "$tempfile"; then + printf "\t \u2714 Correct error thrown. \n\n" + else + printf "\t \u274c Error messaging inconsistent \n\n" + failed_fim_testcases=$((failed_fim_testcases + 1)) + fi + # Remove temp file + rm "$tempfile" + + printf "(7/${num_test_cases_fim})\t>>>> Assert Error thrown from no output file parameter <<<<\n\n" + # Create and assign temp file + tempfile=$(mktemp) + # Test case + $cmd fim \ + -c $controls_benchmark_dir/controls_2year.csv \ + -fmt $format \ + -type depth \ + -lib $library_benchmark &> "$tempfile" + # Assign error string + expected_error_substring="missing required flags" + # Search (grep) for expected error substring in temporary output file + if grep -q "$expected_error_substring" "$tempfile"; then + printf "\t \u2714 Correct error thrown. \n\n" + else + printf "\t \u274c Error messaging inconsistent \n\n" + failed_fim_testcases=$((failed_fim_testcases + 1)) + fi + + printf "(8/${num_test_cases_fim})\t>>>> Assert Error thrown from empty controls file <<<<\n\n" + # Create and assign temp file + tempfile=$(mktemp) + # Test case + $cmd fim \ + -c $flows_files_dir/empty_file.csv \ + -fmt $format \ + -lib $library_benchmark \ + -type depth \ + -o $fim_test_outputs/fim_test.tif &> "$tempfile" + # Assign error string + expected_error_substring="no records in control file" + # Search (grep) for expected error substring in temporary output file + if grep -q "$expected_error_substring" "$tempfile"; then + printf "\t \u2714 Correct error thrown. \n\n" + else + printf "\t \u274c Error messaging inconsistent \n\n" + failed_fim_testcases=$((failed_fim_testcases + 1)) + fi + # Remove temp file + rm "$tempfile" + + #printf "(9/${num_test_cases_fim})\t>>>> Test flows2fim fim pull from S3 <<<<\n\n" + + fim_passed=$((num_test_cases_fim - failed_fim_testcases)) + total_passed=$(( total_passed + fim_passed)) + +} + +validate_test_cases() { + local num_test_cases_validate=0 + local failed_validate_testcases=0 + total_count=$(( total_count + num_test_cases_validate)) + + printf "\n\t###### ${num_test_cases_validate} TEST CASES FOR flows2fim validate ######\n\n" + # printf "( 1/${num_test_cases_validate})\t>>>> Test validate <<<<\n\n" + # flows2fim validate + + + validate_passed=$((num_test_cases_validate - failed_validate_testcases)) + total_passed=$((total_passed + validate_passed)) +} + +# Control flow for methods and test cases +if [ "$method" = "all" ]; then + printf "\n\t>>>> TESTING ALL METHODS (controls, fim, & validate) <<<<\n" + test_help_statement + controls_test_cases + fim_test_cases + validate_test_cases + printf "\n\t>>>> (${total_passed}/${total_count}) TESTS PASSED <<<<\n\n" + total_failed=$((total_count - total_passed)) + exit_if_failure $total_failed +elif [ "$method" = "controls" ]; then + controls_test_cases + printf "\n\t>>>> (${total_passed}/${total_count}) TESTS PASSED <<<<\n\n" + total_failed=$((total_count - total_passed)) + exit_if_failure $total_failed +elif [ "$method" = "fim" ]; then + fim_test_cases + printf "\n\t>>>> (${total_passed}/${total_count}) TESTS PASSED <<<<\n\n" + total_failed=$((total_count - total_passed)) + exit_if_failure $total_failed +elif [ "$method" = "validate" ]; then + validate_test_cases + printf "\n\t>>>> (${total_passed}/${total_count}) TESTS PASSED <<<<\n\n" + total_failed=$((total_count - total_passed)) + exit_if_failure $total_failed +else + printf "\n\t>>>> NO TEST CASES WERE RUN <<<<\n\n" + usage +fi \ No newline at end of file diff --git a/testdata/reference_data/fim_output_formats_mac/fim_2year.cog b/testdata/reference_data/fim_output_formats_mac/fim_2year.cog new file mode 100644 index 0000000..d47f776 Binary files /dev/null and b/testdata/reference_data/fim_output_formats_mac/fim_2year.cog differ diff --git a/testdata/reference_data/fim_output_formats_mac/fim_2year.gtiff b/testdata/reference_data/fim_output_formats_mac/fim_2year.gtiff new file mode 100644 index 0000000..9241c5a Binary files /dev/null and b/testdata/reference_data/fim_output_formats_mac/fim_2year.gtiff differ diff --git a/testdata/reference_data/fim_output_formats_mac/fim_2year.vrt b/testdata/reference_data/fim_output_formats_mac/fim_2year.vrt new file mode 100644 index 0000000..8aad911 --- /dev/null +++ b/testdata/reference_data/fim_output_formats_mac/fim_2year.vrt @@ -0,0 +1,16 @@ + + PROJCS["NAD83 / Conus Albers",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["latitude_of_center",23],PARAMETER["longitude_of_center",-96],PARAMETER["standard_parallel_1",29.5],PARAMETER["standard_parallel_2",45.5],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","5070"]] + -1.9071349570219149e+06, 3.0000000000000000e+00, 0.0000000000000000e+00, 3.0706380139037063e+06, 0.0000000000000000e+00, -3.0000000000000000e+00 + + -9999 + Gray + + /Users/runner/work/flows2fim/flows2fim/testdata/reference_data/library/24274741/z_nd/f_17668.tif + 1 + + + + -9999 + + +