Skip to content

Commit

Permalink
Merge pull request #528 from thekester/github-actions
Browse files Browse the repository at this point in the history
Add GitHub Actions Workflow for Basic CoastSat Testing
  • Loading branch information
kvos authored Sep 1, 2024
2 parents c54b2a9 7aa7a07 commit 1953954
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/test-coastsat.yml
Original file line number Diff line number Diff line change
@@ -0,0 1,63 @@
on:
push:
branches:
- github-actions
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install Miniconda
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: coastsat-env
python-version: 3.12

- name: Recreate Conda Environment
shell: bash -l {0}
run: |
conda deactivate
conda remove --name coastsat-env --all -y
conda create --name coastsat-env python=3.12 -y
conda activate coastsat-env
- name: Initialize Conda and Install Dependencies
shell: bash -l {0}
run: |
echo "Initializing Conda..."
conda init bash
source ~/.bashrc
echo "Conda initialized."
echo "Activating the environment..."
conda activate coastsat-env

echo "Installing dependencies..."
conda install -c conda-forge sqlite -y
conda install -c conda-forge geopandas -y
conda install -c conda-forge earthengine-api scikit-image matplotlib astropy notebook -y
pip install pyqt5 imageio-ffmpeg

echo "Installed packages:"
conda list
pip list

- name: Run Python Test Script
shell: bash -l {0}
run: |
echo "Running the Python Test Script..."
conda activate coastsat-env
python test.py
55 changes: 55 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 1,55 @@
import os
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from datetime import datetime
from coastsat import SDS_tools

# Test 1: Verify that NumPy is working correctly
def test_numpy():
array = np.array([1, 2, 3])
assert np.sum(array) == 6, "NumPy sum test failed!"
print("Test NumPy: OK")

# Test 2: Verify that Matplotlib is working and can create a simple plot
def test_matplotlib():
plt.figure()
plt.plot([0, 1, 2], [0, 1, 4])
plt.title("Test Plot")
plt.savefig("test_plot.png")
assert os.path.exists("test_plot.png"), "Matplotlib plot test failed!"
print("Test Matplotlib: OK")

# Test 3: Verify that Pandas is working correctly
def test_pandas():
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
assert df.shape == (3, 2), "Pandas DataFrame test failed!"
print("Test Pandas: OK")

# Test 4: Verify that basic CoastSat functions are working
def test_coastsat():
polygon = [[[151.301454, -33.700754],
[151.311453, -33.702075],
[151.307237, -33.739761],
[151.294220, -33.736329],
[151.301454, -33.700754]]]

# Test the smallest_rectangle function
rectangle = SDS_tools.smallest_rectangle(polygon)

# Print the output for debugging
print("Output of smallest_rectangle:", rectangle)

# Check that the output is a list of exactly 4 vertices
assert len(rectangle[0]) == 5, "CoastSat smallest_rectangle test failed! The rectangle should have 5 points (4 vertices plus the closing point)."
assert rectangle[0][0] == rectangle[0][-1], "The first and last point should be the same to close the polygon."

print("Test CoastSat: OK")

if __name__ == "__main__":
test_numpy()
test_matplotlib()
test_pandas()
test_coastsat()

print("All tests were successfully executed.")

0 comments on commit 1953954

Please sign in to comment.