-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
403 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- [ main ] | ||
pull_request: | ||
branches: | ||
- [ main ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.9", "3.10", "3.11"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 pytest | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Lint with flake8 | ||
run: | | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
run: | | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import sys | ||
sys.path.append('.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
|
||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
import pytest | ||
import pandas as pd | ||
|
||
|
||
@pytest.fixture | ||
def sample_bar_data1() -> pd.DataFrame: | ||
return pd.DataFrame( | ||
{ | ||
"time": ["1960-01-01", "1961-01-01", "1962-01-01"], | ||
"Afghanistan": [1, 2, 3], | ||
"Angola": [2, 3, 4], | ||
"Albania": [1, 2, 5], | ||
"USA": [5, 3, 4], | ||
"Argentina": [1, 4, 5], | ||
} | ||
).set_index("time") | ||
|
||
|
||
@pytest.fixture | ||
def sample_bar_data2() -> pd.DataFrame: | ||
return pd.DataFrame( | ||
{ | ||
"time": ["2012", "2013", "2014"], | ||
"col1": [1, 2, 3], | ||
"col2": [3, 2, 1], | ||
} | ||
).set_index("time") | ||
|
||
|
||
@pytest.fixture | ||
def map_data() -> pd.DataFrame: | ||
map_data = pd.read_csv(dir_path + "/data/map.csv").set_index("time") | ||
return map_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from pynimate.bar import Barplot | ||
import pytest | ||
|
||
|
||
def test_barplot_set_bar_color_list(sample_bar_data1): | ||
bar = Barplot(sample_bar_data1, "%Y-%m-%d", "3MS") | ||
bar_colors_list = [ | ||
"#2a9d8f", | ||
"#e9c46a", | ||
"#e76f51", | ||
"#a7c957", | ||
"#e5989b", | ||
] | ||
bar_colors = { | ||
"Afghanistan": "#2a9d8f", | ||
"Angola": "#e9c46a", | ||
"Albania": "#e76f51", | ||
"USA": "#a7c957", | ||
"Argentina": "#e5989b", | ||
} | ||
bar.set_bar_color(bar_colors_list) | ||
assert bar.datafier.bar_colors == bar_colors | ||
|
||
|
||
def test_barplot_set_bar_color_dict(sample_bar_data1): | ||
bar = Barplot(sample_bar_data1, "%Y-%m-%d", "3MS") | ||
bar_colors = { | ||
"Afghanistan": "#2a9d8f", | ||
"Angola": "#e9c46a", | ||
"Albania": "#e76f51", | ||
"USA": "#a7c957", | ||
"Argentina": "#e5989b", | ||
} | ||
bar.set_bar_color(bar_colors) | ||
assert bar.datafier.bar_colors == bar_colors | ||
|
||
|
||
def test_barplot_set_bar_color_error_length(sample_bar_data1): | ||
with pytest.raises(AssertionError): | ||
bar = Barplot(sample_bar_data1, "%Y-%m-%d", "3MS") | ||
bar_colors = [ | ||
"#2a9d8f", | ||
"#e9c46a", | ||
"#e76f51", | ||
"#a7c957", | ||
] | ||
bar.set_bar_color(bar_colors) | ||
assert bar.datafier.bar_colors == bar_colors | ||
|
||
|
||
def test_barplot_set_bar_color_error_col_mismatch(sample_bar_data1): | ||
with pytest.raises(AssertionError): | ||
bar = Barplot(sample_bar_data1, "%Y-%m-%d", "3MS") | ||
bar_colors = { | ||
"India": "#2a9d8f", | ||
"Angola": "#e9c46a", | ||
"Albania": "#e76f51", | ||
"USA": "#a7c957", | ||
"Argentina": "#e5989b", | ||
} | ||
bar.set_bar_color(bar_colors) | ||
assert bar.datafier.bar_colors == bar_colors | ||
|
||
|
||
def test_barplot_set_test_error_empty_text(sample_bar_data1): | ||
with pytest.raises(AssertionError): | ||
bar = Barplot(sample_bar_data1, "%Y-%m-%d", "3MS") | ||
bar.set_text("text1") | ||
|
||
|
||
def test_barplot_set_test_error_text_priority(sample_bar_data1): | ||
bar = Barplot(sample_bar_data1, "%Y-%m-%d", "3MS") | ||
bar.set_text("text1", text="Test", callback=lambda *args: "Test") | ||
assert "s" not in bar.text_collection["text1"][1] | ||
|
||
|
||
def test_barplot_remove_text(sample_bar_data1): | ||
bar = Barplot(sample_bar_data1, "%Y-%m-%d", "3MS") | ||
bar.set_text("text1", text="Test1") | ||
bar.set_text("text2", text="Test2") | ||
bar.set_text("text3", text="Test3") | ||
|
||
bar.remove_text(["text1", "text2"]) | ||
assert list(bar.text_collection.keys()) == ["time", "text3"] |
Oops, something went wrong.