Skip to content

Commit 3f8e282

Browse files
authored
Black (#50)
* black * update boxes_to -> to methods * black
1 parent 35e8538 commit 3f8e282

File tree

5 files changed

+46
-53
lines changed

5 files changed

+46
-53
lines changed

pymathics/graph/boxes.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,47 @@
88

99
import base64
1010
import tempfile
11-
12-
1311
from typing import Tuple
1412

1513
from mathics.core.element import BaseElement, BoxElementMixin
1614

17-
1815
from pymathics.graph.format import png_format_graph, svg_format_graph
1916

2017
no_doc = True
2118

19+
2220
class GraphBox(BoxElementMixin):
2321
def __init__(self, G, **options):
2422
self.G = G
2523
self.options = options
2624

27-
def boxes_to_b64text(
28-
self, elements: Tuple[BaseElement] = None, **options
29-
) -> Tuple[bytes, Tuple[int, int]]:
25+
def to_b64text(self, **options) -> Tuple[bytes, Tuple[int, int]]:
3026
"""
3127
Produces a base64 png representation and a tuple with the size of the pillow image
3228
associated to the object.
3329
"""
34-
contents, size = self.boxes_to_png(elements, **options)
30+
contents, size = self.to_png(**options)
3531
encoded = base64.b64encode(contents)
3632
encoded = b"data:image/png;base64," + encoded
3733
return encoded, size
3834

39-
def boxes_to_png(self, elements=None, **options) -> Tuple[bytes, Tuple[int, int]]:
35+
def to_png(self, **options) -> Tuple[bytes, Tuple[int, int]]:
4036
"""
4137
returns a tuple with the set of bytes with a png representation of the image
4238
and the scaled size.
4339
"""
4440
return png_format_graph(self.G, **self.options), (800, 600)
4541

46-
def boxes_to_svg(self, elements=None, **options):
42+
def to_svg(self, **options):
4743
return svg_format_graph(self.G, **self.options), (400, 300)
4844

49-
def boxes_to_tex(self, elements=None, **options) -> str:
45+
def to_tex(self, **options) -> str:
5046
"""
5147
Store the associated image as a png file and return
5248
a LaTeX command for including it.
5349
"""
5450

55-
data, size = self.boxes_to_png(elements, **options)
51+
data, size = self.to_png(elements, **options)
5652
res = 100 # pixels/cm
5753
width_str, height_str = (str(n / res).strip() for n in size)
5854
head = rf"\includegraphics[width={width_str}cm,height={height_str}cm]"
@@ -69,11 +65,11 @@ def boxes_to_tex(self, elements=None, **options) -> str:
6965

7066
return head + "{" + format(path) + "}"
7167

72-
def boxes_to_text(self, elements=None, **options):
68+
def to_text(self, **options):
7369
return "-Graph-"
7470

75-
def boxes_to_mathml(self, elements=None, **options):
76-
encoded, size = self.boxes_to_b64text(elements, **options)
71+
def to_mathml(self, **options):
72+
encoded, size = self.to_b64text(**options)
7773
decoded = encoded.decode("utf8")
7874
# see https://tools.ietf.org/html/rfc2397
7975
return f'<mglyph src="{decoded}" width="50%" height="50%" />'

pymathics/graph/format.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ def get_png_graph() -> BytesIO:
115115
def hierarchy_pos(
116116
G, root=None, width=1.0, vert_gap=0.2, vert_loc=0, leaf_vs_root_factor=0.5
117117
):
118-
119118
"""Position nodes in tree layout. The root is at the top.
120119
121120
Based on Joel's answer at https://stackoverflow.com/a/29597209/2966723,

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[build-system]
22
requires = [
33
"setuptools", # CVE-2024-38335 recommends this
4-
"Mathics3>9.0.0",
4+
"mathics-core >= 9.0.1",
55
"Mathics3-Module-Base",
66
"networkx>=3.0.0",
77
"matplotlib",
8-
"Mathics3-Module-Base",
98
]
109
build-backend = "setuptools.build_meta"
1110

test/helper.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
# Set up a Mathics session with definitions.
1313
# For consistency set the character encoding ASCII which is
1414
# the lowest common denominator available on all systems.
15-
session = MathicsSession(
16-
character_encoding="ASCII"
17-
)
15+
session = MathicsSession(character_encoding="ASCII")
1816

1917

2018
def reset_session(add_builtin=True, catch_interrupt=False):
@@ -115,7 +113,7 @@ def check_evaluation(
115113
assert (
116114
expected_len == got_len
117115
), f"expected {expected_len}; got {got_len}. Messages: {outs}"
118-
for (out, msg) in zip(outs, msgs):
116+
for out, msg in zip(outs, msgs):
119117
if out != msg:
120118
print(f"out:<<{out}>>")
121119
print(" and ")

test/test_fixme.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,78 @@
55
from test.helper import check_evaluation, evaluate, evaluate_value
66
import pytest
77

8+
89
def setup_module(module):
910
"""Load pymathics.graph"""
1011
assert evaluate_value('LoadModule["pymathics.graph"]') == "pymathics.graph"
1112
evaluate("SortList[list_] := Sort[Map[Sort, list]]")
1213

1314

14-
1515
@pytest.mark.skip("Wrong result. Investigate me.")
1616
def test_EdgeList():
1717
check_evaluation(
18-
"EdgeList[{1 -> 2, 2 <-> 3}]",
19-
"{DirectedEdge[1, 2], UndirectedEdge[2, 3]}"
20-
)
18+
"EdgeList[{1 -> 2, 2 <-> 3}]", "{DirectedEdge[1, 2], UndirectedEdge[2, 3]}"
19+
)
2120

2221

23-
2422
@pytest.mark.skip("Wrong result. Investigate me.")
2523
def test_FindShortestPath():
26-
check_evaluation(
27-
(
28-
"g = Graph[{1 -> 2, 2 -> 3, 1 -> 3}, EdgeWeight -> {0.5, a, 3}];"
29-
"a = 0.5; FindShortestPath[g, 1, 3]'"),
30-
"{1, 2, 3}")
31-
check_evaluation("a = 10; FindShortestPath[g, 1, 3]", "{1, 3}")
32-
check_evaluation("a = .;", "Null")
33-
34-
24+
check_evaluation(
25+
(
26+
"g = Graph[{1 -> 2, 2 -> 3, 1 -> 3}, EdgeWeight -> {0.5, a, 3}];"
27+
"a = 0.5; FindShortestPath[g, 1, 3]'"
28+
),
29+
"{1, 2, 3}",
30+
)
31+
check_evaluation("a = 10; FindShortestPath[g, 1, 3]", "{1, 3}")
32+
check_evaluation("a = .;", "Null")
3533

3634

3735
@pytest.mark.skip("This finds d<->a in the position 4 instead 2.")
3836
def test_EdgeIndex():
39-
check_evaluation("EdgeIndex[{c <-> d, d <-> a, a -> e}, d <-> a]",
40-
"2")
37+
check_evaluation("EdgeIndex[{c <-> d, d <-> a, a -> e}, d <-> a]", "2")
38+
4139

42-
4340
@pytest.mark.parametrize(
4441
("str_expr", "str_expect"),
4542
[
4643
(
47-
("g = Graph[{1 -> 2, 2 -> 3}, DirectedEdges -> True];"
48-
"EdgeCount[g, _DirectedEdge]"),
49-
"2"
44+
(
45+
"g = Graph[{1 -> 2, 2 -> 3}, DirectedEdges -> True];"
46+
"EdgeCount[g, _DirectedEdge]"
47+
),
48+
"2",
5049
),
5150
(
5251
(
5352
"g = Graph[{1 -> 2, 2 -> 3}, DirectedEdges -> False];"
54-
"EdgeCount[g, _DirectedEdge]"),
55-
"0"
53+
"EdgeCount[g, _DirectedEdge]"
54+
),
55+
"0",
5656
),
57-
("EdgeCount[g, _UndirectedEdge]","2")
58-
]
57+
("EdgeCount[g, _UndirectedEdge]", "2"),
58+
],
5959
)
6060
@pytest.mark.skip("This finds d<->a in the position 4 instead 2.")
6161
def test_edgecount(str_expr, str_expect):
6262
check_evaluation(str_expr, str_expect)
6363

64-
64+
6565
@pytest.mark.skip("This finds d<->a in the position 4 instead 2.")
6666
def test_EdgeIndex():
67-
check_evaluation("EdgeIndex[{c <-> d, d <-> a, a -> e}, d <-> a]",
68-
"2")
67+
check_evaluation("EdgeIndex[{c <-> d, d <-> a, a -> e}, d <-> a]", "2")
68+
6969

7070
@pytest.mark.skip("This is not properly evaluated. Investigate me")
7171
def test_HITSCentrality():
72-
check_evaluation("g = Graph[{a -> d, b -> c, d -> c, d -> a, e -> c}]; HITSCentrality[g]",
73-
"{{0.292893, 0., 0., 0.707107, 0.}, {0., 1., 0.707107, 0., 0.707107}}")
72+
check_evaluation(
73+
"g = Graph[{a -> d, b -> c, d -> c, d -> a, e -> c}]; HITSCentrality[g]",
74+
"{{0.292893, 0., 0., 0.707107, 0.}, {0., 1., 0.707107, 0., 0.707107}}",
75+
)
76+
7477

7578
@pytest.mark.skip("Investigate me.")
7679
def test_EdgeRules():
7780
check_evaluation(
78-
"EdgeRules[{1 <-> 2, 2 -> 3, 3 <-> 4}]",
79-
"{1 -> 2, 2 -> 3, 3 -> 4}"
81+
"EdgeRules[{1 <-> 2, 2 -> 3, 3 <-> 4}]", "{1 -> 2, 2 -> 3, 3 -> 4}"
8082
)
81-

0 commit comments

Comments
 (0)