-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from thomas-saigre/12-set-automatic-tests
12 set automatic tests
- Loading branch information
Showing
28 changed files
with
1,709 additions
and
23 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,43 @@ | ||
name: ci | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- '*' # all branches | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repo | ||
uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.x' | ||
|
||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, macOS-latest] | ||
python-version: ["3.8", "3.9", "3.10"] | ||
steps: | ||
- uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- uses: actions/checkout@v3 | ||
# - name: Install system dependencies | ||
# run: sudo apt-get install -y texlive-latex-base texlive-latex-extra context python3-tk | ||
- name: Test with tox | ||
run: | | ||
pip install tox | ||
tox -- --cov tikzplotly --cov-report xml --cov-report term | ||
- uses: codecov/[email protected] | ||
if: ${{ matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest' }} | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
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 |
---|---|---|
|
@@ -20,3 +20,8 @@ venv/ | |
|
||
# Distribution / packaging | ||
dist/ | ||
|
||
# Tox | ||
.tox/ | ||
.coverage | ||
coverage.xml |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" | |
|
||
[project] | ||
name = "tikzplotly" | ||
version = "0.1.5" | ||
version = "0.1.6" | ||
description = "Convert plotly figures to LaTeX / tikz figures" | ||
readme = "README.md" | ||
authors = [{name = "Thomas Saigre", email = "[email protected]"}] | ||
|
@@ -13,7 +13,6 @@ classifiers = [ | |
"Development Status :: 5 - Production/Stable", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.7", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
|
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Run test | ||
|
||
This tests are only for devlopment purposes. | ||
Automatic tests are set-up in [../tests](../tests/) directory. | ||
|
||
```bash | ||
python3 -m tests.<test-name> | ||
``` |
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.1.4" | ||
__version__ = "0.1.6" |
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
Empty file.
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,20 @@ | ||
# Adapted from https://github.com/nschloe/tikzplotlib/blob/450712b4014799ec5f151f234df84335c90f4b9d/tests/helpers.py | ||
|
||
import tikzplotly | ||
|
||
|
||
# https://stackoverflow.com/a/845432/353337 | ||
def _unidiff_output(expected, actual): | ||
import difflib | ||
|
||
expected = expected.splitlines(1) | ||
actual = actual.splitlines(1) | ||
diff = difflib.unified_diff(expected, actual) | ||
return "".join(diff) | ||
|
||
def assert_equality(fig, target_file, **kwargs): | ||
tikz_code = tikzplotly.get_tikz_code(fig, include_disclamer=False, **kwargs) | ||
|
||
with open(target_file, encoding="utf-8") as f: | ||
reference = f.read() | ||
assert reference == tikz_code, target_file + "\n" + _unidiff_output(reference, tikz_code) |
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,65 @@ | ||
import plotly.express as px | ||
import plotly.graph_objects as go | ||
import numpy as np | ||
import os | ||
from .helpers import assert_equality | ||
import pathlib | ||
import datetime | ||
|
||
this_dir = pathlib.Path(__file__).resolve().parent | ||
test_name = "test_heatmap" | ||
pathlib.Path("/tmp/tikzplotly").mkdir(parents=True, exist_ok=True) | ||
|
||
def plot_1(): | ||
fig = px.imshow([[1, 20, 30], | ||
[20, 1, 60], | ||
[30, 60, 1]]) | ||
return fig | ||
|
||
def plot_2(): | ||
df = px.data.medals_wide(indexed=True) | ||
fig = px.imshow(df) | ||
return fig | ||
|
||
def plot_3(): | ||
fig = go.Figure(data=go.Heatmap( | ||
z=[[1, None, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]], | ||
x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], | ||
y=['Morning', 'Afternoon', 'Evening'], | ||
hoverongaps = False)) | ||
return fig | ||
|
||
def plot_4(): | ||
import plotly.graph_objects as go | ||
|
||
programmers = ['Alex','Nicole','Sara','Etienne','Chelsea','Jody','Marianne'] | ||
|
||
base = datetime.datetime(2021, 7, 20, 19, 30, 0) | ||
dates = base - np.arange(180) * datetime.timedelta(days=1) | ||
np.random.seed(43) | ||
z = np.random.poisson(size=(len(programmers), len(dates))) | ||
|
||
fig = go.Figure(data=go.Heatmap( | ||
z=z, | ||
x=dates, | ||
y=programmers, | ||
colorscale='Viridis')) | ||
|
||
fig.update_layout( | ||
title='GitHub commits per day', | ||
xaxis_nticks=36) | ||
|
||
return fig | ||
|
||
|
||
def test_1(): | ||
assert_equality(plot_1(), os.path.join(this_dir, test_name, test_name + "_1_reference.tex"), img_name="/tmp/tikzplotly/fig1.png") | ||
|
||
def test_2(): | ||
assert_equality(plot_2(), os.path.join(this_dir, test_name, test_name + "_2_reference.tex"), img_name="/tmp/tikzplotly/fig2.png") | ||
|
||
def test_3(): | ||
assert_equality(plot_3(), os.path.join(this_dir, test_name, test_name + "_3_reference.tex"), img_name="/tmp/tikzplotly/fig3.png") | ||
|
||
def test_4(): | ||
assert_equality(plot_4(), os.path.join(this_dir, test_name, test_name + "_4_reference.tex"), img_name="/tmp/tikzplotly/fig4.png") |
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,30 @@ | ||
\begin{tikzpicture} | ||
|
||
|
||
\begin{axis}[ | ||
y dir=reverse, | ||
colorbar, | ||
colormap={mycolor}{ | ||
rgb255(0.0cm)=(13,8,135); | ||
rgb255(0.1111111111111111cm)=(70,3,159); | ||
rgb255(0.2222222222222222cm)=(114,1,168); | ||
rgb255(0.3333333333333333cm)=(156,23,158); | ||
rgb255(0.4444444444444444cm)=(189,55,134); | ||
rgb255(0.5555555555555556cm)=(216,87,107); | ||
rgb255(0.6666666666666666cm)=(237,121,83); | ||
rgb255(0.7777777777777778cm)=(251,159,58); | ||
rgb255(0.8888888888888888cm)=(253,202,38); | ||
rgb255(1.0cm)=(240,249,33); | ||
}, | ||
point meta max=60.0, | ||
point meta min=1.0, | ||
xmin=-0.5, | ||
xmax=2.5, | ||
ymin=-0.5, | ||
ymax=2.5, | ||
tick align=outside, | ||
tick pos=left | ||
] | ||
\addplot+ graphics[includegraphics cmd=\pgfimage,xmin=-0.5, xmax=2.5, ymin=2.5, ymax=-0.5] {/tmp/tikzplotly/fig1.png}; | ||
\end{axis} | ||
\end{tikzpicture} |
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,36 @@ | ||
\begin{tikzpicture} | ||
|
||
|
||
\begin{axis}[ | ||
y dir=reverse, | ||
colorbar, | ||
xtick={0,1,2}, | ||
xticklabels={gold,silver,bronze}, | ||
ytick={0,1,2}, | ||
yticklabels={South Korea,China,Canada}, | ||
colormap={mycolor}{ | ||
rgb255(0.0cm)=(13,8,135); | ||
rgb255(0.1111111111111111cm)=(70,3,159); | ||
rgb255(0.2222222222222222cm)=(114,1,168); | ||
rgb255(0.3333333333333333cm)=(156,23,158); | ||
rgb255(0.4444444444444444cm)=(189,55,134); | ||
rgb255(0.5555555555555556cm)=(216,87,107); | ||
rgb255(0.6666666666666666cm)=(237,121,83); | ||
rgb255(0.7777777777777778cm)=(251,159,58); | ||
rgb255(0.8888888888888888cm)=(253,202,38); | ||
rgb255(1.0cm)=(240,249,33); | ||
}, | ||
point meta max=24.0, | ||
point meta min=8.0, | ||
xmin=-0.5, | ||
xmax=2.5, | ||
ymin=-0.5, | ||
ymax=2.5, | ||
tick align=outside, | ||
tick pos=left, | ||
xlabel=medal, | ||
ylabel=nation | ||
] | ||
\addplot+ graphics[includegraphics cmd=\pgfimage,xmin=-0.5, xmax=2.5, ymin=2.5, ymax=-0.5] {/tmp/tikzplotly/fig2.png}; | ||
\end{axis} | ||
\end{tikzpicture} |
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,33 @@ | ||
\begin{tikzpicture} | ||
|
||
|
||
\begin{axis}[ | ||
colorbar, | ||
xtick={0,1,2,3,4}, | ||
xticklabels={Monday,Tuesday,Wednesday,Thursday,Friday}, | ||
ytick={0,1,2}, | ||
yticklabels={Morning,Afternoon,Evening}, | ||
colormap={mycolor}{ | ||
rgb255(0.0cm)=(13,8,135); | ||
rgb255(0.1111111111111111cm)=(70,3,159); | ||
rgb255(0.2222222222222222cm)=(114,1,168); | ||
rgb255(0.3333333333333333cm)=(156,23,158); | ||
rgb255(0.4444444444444444cm)=(189,55,134); | ||
rgb255(0.5555555555555556cm)=(216,87,107); | ||
rgb255(0.6666666666666666cm)=(237,121,83); | ||
rgb255(0.7777777777777778cm)=(251,159,58); | ||
rgb255(0.8888888888888888cm)=(253,202,38); | ||
rgb255(1.0cm)=(240,249,33); | ||
}, | ||
point meta max=80, | ||
point meta min=-10, | ||
xmin=-0.5, | ||
xmax=4.5, | ||
ymin=-0.5, | ||
ymax=2.5, | ||
tick align=outside, | ||
tick pos=left | ||
] | ||
\addplot+ graphics[includegraphics cmd=\pgfimage,xmin=-0.5, xmax=4.5, ymin=2.5, ymax=-0.5] {/tmp/tikzplotly/fig3.png}; | ||
\end{axis} | ||
\end{tikzpicture} |
Oops, something went wrong.