Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for portrait plot #26

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/build_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:

pull_request:
branches: [main]
types: [ready_for_review]

workflow_dispatch:

Expand All @@ -16,7 +15,6 @@ env:

jobs:
check-jobs-to-skip:
if: ${{ github.event.pull_request.draft != true }}
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
Expand All @@ -29,7 +27,7 @@ jobs:

pre-commit-hooks:
needs: check-jobs-to-skip
if: ${{ (needs.check-jobs-to-skip.outputs.should_skip != 'true' || github.event_name == 'push') && github.event.pull_request.draft != true }}
if: ${{ needs.check-jobs-to-skip.outputs.should_skip != 'true' }} || ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
Expand All @@ -46,7 +44,7 @@ jobs:

build:
needs: check-jobs-to-skip
if: ${{ (needs.check-jobs-to-skip.outputs.should_skip != 'true' || github.event_name == 'push') && github.event.pull_request.draft != true }}
if: ${{ needs.check-jobs-to-skip.outputs.should_skip != 'true' }} || ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest
defaults:
run:
Expand Down Expand Up @@ -100,7 +98,7 @@ jobs:


publish-docs:
if: ${{ (github.event_name == 'push' || github.event_name == 'pull_request') && github.event.pull_request.draft != true }}
if: ${{ github.event_name == 'push' }} || ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
defaults:
run:
Expand Down
71 changes: 71 additions & 0 deletions tests/test_core_portrait_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import unittest

import numpy as np
from bokeh.plotting import figure

from ESMBenchmarkViz import portrait_plot


class TestPortraitPlot(unittest.TestCase):
def test_minimal_valid_input(self):
data = np.array([[1, 2], [3, 4]])
xaxis_labels = ["A", "B"]
yaxis_labels = ["C", "D"]
plot = portrait_plot(data, xaxis_labels, yaxis_labels, show_plot=False)
self.assertIsInstance(plot, figure)

def test_3d_data_input(self):
data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
xaxis_labels = ["A", "B"]
yaxis_labels = ["C", "D"]
plot = portrait_plot(data, xaxis_labels, yaxis_labels, show_plot=False)
self.assertIsInstance(plot, figure)

def test_with_annotations(self):
data = np.array([[1, 2], [3, 4]])
annotate_data = np.array([[0.1, 0.2], [0.3, 0.4]])
xaxis_labels = ["A", "B"]
yaxis_labels = ["C", "D"]
plot = portrait_plot(
data,
xaxis_labels,
yaxis_labels,
annotate=True,
annotate_data=annotate_data,
show_plot=False,
)
self.assertIsInstance(plot, figure)

def test_clickable_urls(self):
data = np.array([[1, 2], [3, 4]])
xaxis_labels = ["A", "B"]
yaxis_labels = ["C", "D"]
img_url = [
"http://example.com/img1",
"http://example.com/img2",
"http://example.com/img3",
"http://example.com/img4",
]
plot = portrait_plot(
data,
xaxis_labels,
yaxis_labels,
clickable=True,
img_url=img_url,
show_plot=False,
)
self.assertIsInstance(plot, figure)

def test_custom_color_map_bounds(self):
data = np.array([[1, 2], [3, 4]])
xaxis_labels = ["A", "B"]
yaxis_labels = ["C", "D"]
cmap_bounds = [0, 2, 4]
plot = portrait_plot(
data, xaxis_labels, yaxis_labels, cmap_bounds=cmap_bounds, show_plot=False
)
self.assertIsInstance(plot, figure)


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion tests/test_core_scatter_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure

from ESMBenchmarkViz.core_scatter_plot import scatter_plot
from ESMBenchmarkViz import scatter_plot


class TestScatterPlot(unittest.TestCase):
Expand Down
Loading