Skip to content

Commit 58c16b7

Browse files
committed
updated tests
1 parent 6329144 commit 58c16b7

3 files changed

Lines changed: 30 additions & 14 deletions

File tree

tests/helper_functions.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
#!/usr/bin/env python3
22
import numpy as np
33
import matplotlib
4+
import matplotlib.pyplot as plt
45
from PIL import Image
6+
matplotlib.use('Agg')
7+
plt.rcParams.update({
8+
'font.family': 'DejaVu Sans', # Or another reliable cross-platform font
9+
'figure.dpi': 100 # Set a fixed DPI
10+
})
511

612

713
def compare_images(f1, f2, tol):
@@ -10,8 +16,8 @@ def compare_images(f1, f2, tol):
1016

1117
f1arr_sub = f1arr[500:1500, 500:1500, :]
1218
f2arr_sub = f2arr[500:1500, 500:1500, :]
13-
im1 = Image.fromarray((f1arr_sub* 255).astype(np.uint8))
14-
im2 = Image.fromarray((f2arr_sub* 255).astype(np.uint8))
19+
im1 = Image.fromarray((f1arr_sub * 255).astype(np.uint8))
20+
im2 = Image.fromarray((f2arr_sub * 255).astype(np.uint8))
1521
size1 = np.shape(f1arr)
1622
size2 = np.shape(f2arr)
1723
t1 = compare_floats(size1[0], size2[0])

tests/test_amend_tree.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
import ete3
99
import pickle
1010
import helper_functions
11+
import matplotlib
12+
matplotlib.use('Agg')
13+
14+
15+
plt.rcParams.update({
16+
'font.family': 'DejaVu Sans',
17+
'figure.dpi': 100 # Set a fixed DPI
18+
})
1119

1220

1321
@pytest.mark.parametrize(test_rev_align_vars,

tests/test_plot_phylo.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
test_plot_phylo_nams)
88
import os
99
import shutil
10-
import helper_functions
10+
import matplotlib
11+
from matplotlib.testing.compare import compare_images
12+
matplotlib.use('Agg')
13+
14+
15+
plt.rcParams.update({
16+
'font.family': 'DejaVu Sans',
17+
'figure.dpi': 100 # Set a fixed DPI
18+
})
1119

1220

1321
# Tests all parameters with plot_phylo with three different trees
@@ -45,8 +53,6 @@ def test_plot_phylo_params(xpos,
4553

4654
f = plt.figure(figsize=(10, 20))
4755
a = f.add_subplot(111)
48-
a.set_xlim(-10, 20)
49-
a.set_ylim(-1, ylim)
5056
plot_phylo.plot_phylo(tree=tree, ax=a,
5157
xpos=xpos,
5258
ypos=ypos,
@@ -80,14 +86,12 @@ def test_plot_phylo_params(xpos,
8086

8187
exp = expected_figure.replace(".png", "_%s.png" % tree_stem)
8288
# Compare the Matplotlib figures as images
83-
result, f1, f2 = helper_functions.compare_images(
84-
"test_temp/%s_%s.png" % (ID, tree_stem),
85-
exp, tol=1)
86-
f1.save(f"test_temp/f1_{ID}_{tree_stem}_frag.png")
87-
f2.save(f"test_temp/f2_{ID}_{tree_stem}_frag.png")
88-
# shutil.rmtree("test_temp")
89+
result = compare_images("test_temp/%s_%s.png" % (ID, tree_stem),
90+
exp, tol=0.01)
91+
92+
shutil.rmtree("test_temp")
8993
# Assert that the images are similar
90-
assert result
94+
assert result is None
9195

9296

9397
@pytest.mark.parametrize(test_plot_phylo_vars,
@@ -119,8 +123,6 @@ def test_bad_tree(xpos,
119123
auto_ax):
120124
f = plt.figure(figsize=(10, 20))
121125
a = f.add_subplot(111)
122-
a.set_xlim(-10, 20)
123-
a.set_ylim(-1, ylim)
124126
with pytest.raises(RuntimeError,
125127
match="Error in parsing Newick"):
126128
plot_phylo.plot_phylo(tree=tree, ax=a,

0 commit comments

Comments
 (0)