Skip to content

Commit 0d71a41

Browse files
authored
Merge pull request #1340 from compas-dev/fix-doctests
Fix the doctests
2 parents 6e85276 + bb5258e commit 0d71a41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+438
-389
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313

1414
* Fixed bug in `compas.geometry.curves.curve.Curve.reversed` by adding missing parenthesis.
15+
* Fixed all doctests so we can run `invoke test --doctest`.
1516

1617
### Removed
1718

src/compas/colors/color.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Color(Data):
9898
By default, this class will create a color with the RGB components in the range ``[0.0, 1.0]``.
9999
100100
>>> Color(1, 0, 0)
101-
Color(1.0, 0.0, 0.0, alpha=1.0)
101+
Color(1, 0, 0, alpha=1.0)
102102
103103
Attempting to create a color with components outside of the range ``[0.0, 1.0]`` will raise a ``ValueError``.
104104

src/compas/data/coercion.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ def coerce_sequence_of_tuple(sequence):
2020
with each iterable item converted to a tuple,
2121
and non-iterable items wrapped in a tuple.
2222
23-
Examples
24-
--------
25-
>>> items = coerce_sequence_of_tuple(["a", 1, (None,), [2.0, 3.0]])
26-
>>> is_sequence_of_tuple(items)
27-
True
28-
2923
"""
3024
items = []
3125
for item in sequence:
@@ -53,12 +47,6 @@ def coerce_sequence_of_list(sequence):
5347
with each iterable item converted to a list,
5448
and non-iterable items wrapped in a list.
5549
56-
Examples
57-
--------
58-
>>> items = coerce_sequence_of_list(["a", 1, (None,), [2.0, 3.0]])
59-
>>> is_sequence_of_list(items)
60-
True
61-
6250
"""
6351
items = []
6452
for item in sequence:

src/compas/data/encoders.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,14 @@ class DataDecoder(json.JSONDecoder):
181181
182182
>>> import json
183183
>>> from compas.data import DataDecoder
184-
>>> with open("point.json", "r") as f:
185-
... point = json.load(f, cls=DataDecoder)
184+
>>> with open('point.json', 'r') as f: # doctest: +SKIP
185+
... point = json.load(f, cls=DataDecoder) # doctest: +SKIP
186+
...
186187
187188
Implicit use case.
188189
189190
>>> from compas.data import json_load
190-
>>> point = json_load("point.json")
191+
>>> point = json_load('point.json') # doctest: +SKIP
191192
192193
"""
193194

src/compas/datastructures/assembly/part.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,27 @@ class GeometricFeature(Feature):
3434
3535
Examples
3636
--------
37-
>>> def trim_brep_plane(brep, plane):
38-
>>> # trim brep with plane, return trimmed brep
37+
>>> from compas.geometry import Brep
38+
>>> from compas.datastructures import Mesh
3939
>>>
40-
>>> def trim_mesh_plane(mesh, plane):
41-
>>> # trim mesh with plane, return trimmed mesh
40+
>>> def trim_brep_plane(brep, plane):
41+
... pass
42+
...
43+
>>> def trim_mesh_plane(mesh, plane):
44+
... pass
45+
...
46+
>>> class TrimmingFeature(GeometricFeature):
47+
... OPERATIONS = {Brep: trim_brep_plane, Mesh: trim_mesh_plane}
48+
... def __init__(self, trimming_plane):
49+
... super(TrimmingFeature, self).__init__()
50+
... self._geometry = trimming_plane
51+
... def apply(self, part):
52+
... part_geometry = part.get_geometry(with_features=True)
53+
... type_ = Brep if isinstance(part_geometry, Brep) else Mesh
54+
... operation = OPERATIONS[type_]
55+
... return operation(part_geometry, self._geometry)
56+
...
4257
>>>
43-
>>> class TrimmingFeature(GeometricFeature):
44-
>>> OPERATIONS = {Brep: trim_brep_plane, Mesh: trim_mesh_plane}
45-
>>>
46-
>>> def __init__(self, trimming_plane):
47-
>>> super(TrimmingFeature, self).__init__()
48-
>>> self._geometry = trimming_plane
49-
>>>
50-
>>> def apply(self, part):
51-
>>> part_geometry = part.get_geometry(with_features=True)
52-
>>> type_ = Brep if isinstance(part_geometry, Brep) else Mesh
53-
>>> operation = OPERATIONS[type_]
54-
>>> return operation(part_geometry, self._geometry)
5558
5659
"""
5760

@@ -81,18 +84,17 @@ class ParametricFeature(Feature):
8184
Examples
8285
--------
8386
>>> class ExtensionFeature(ParametricFeature):
84-
>>> def __init__(self, extend_by):
85-
>>> super(ExtensionFeature, self).__init__()
86-
>>> self.extend_by = extend_by
87-
>>>
88-
>>> def apply(self, part):
89-
>>> part.length += self._extend_by
90-
>>>
91-
>>> def restore(self, part):
92-
>>> part.length -= self._extend_by
87+
... def __init__(self, extend_by):
88+
... super(ExtensionFeature, self).__init__()
89+
... self.extend_by = extend_by
90+
... def apply(self, part):
91+
... part.length += self._extend_by
92+
... def restore(self, part):
93+
... part.length -= self._extend_by
94+
... def accumulate(self, other):
95+
... return BeamExtensionFeature(max(self.extend_by, other.extend_by))
96+
...
9397
>>>
94-
>>> def accumulate(self, other):
95-
>>> return BeamExtensionFeature(max(self.extend_by, other.extend_by))
9698
9799
"""
98100

src/compas/datastructures/cell_network/cell_network.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,17 @@ class CellNetwork(Datastructure):
7474
>>> vertices = [(0, 0, 0), (0, 1, 0), (1, 1, 0), (1, 0, 0), (0, 0, 1), (1, 0, 1), (1, 1, 1), (0, 1, 1)]
7575
>>> faces = [[0, 1, 2, 3], [0, 3, 5, 4], [3, 2, 6, 5], [2, 1, 7, 6], [1, 0, 4, 7], [4, 5, 6, 7]]
7676
>>> cells = [[0, 1, 2, 3, 4, 5]]
77-
>>> [network.add_vertex(x=x, y=y, z=z) for x, y, z in vertices]
78-
>>> [cell_network.add_face(fverts) for fverts in faces]
79-
>>> [cell_network.add_cell(fkeys) for fkeys in cells]
80-
>>> cell_network
77+
>>> for x, y, z in vertices:
78+
... vertex = cell_network.add_vertex(x=x, y=y, z=z)
79+
...
80+
>>> for face_vertices in faces:
81+
... face = cell_network.add_face(face_vertices)
82+
...
83+
>>> for cell_faces in cells:
84+
... cell = cell_network.add_cell(cell_faces)
85+
...
86+
>>> print(cell_network)
87+
<CellNetwork with 8 vertices, 6 faces, 1 cells, 12 edges>
8188
8289
"""
8390

src/compas/datastructures/graph/graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,7 @@ def complement(self):
23662366
>>> from compas.datastructures import Graph
23672367
>>> graph = Graph.from_obj(compas.get("lines.obj"))
23682368
>>> complement = graph.complement()
2369-
>>> any(complement.has_edge(u, v, directed=False) for u, v in graph.edges())
2369+
>>> any(complement.has_edge((u, v), directed=False) for u, v in graph.edges())
23702370
False
23712371
23722372
"""
@@ -2381,7 +2381,7 @@ def complement(self):
23812381

23822382
for u, v in combinations(self.nodes(), 2):
23832383
if not self.has_edge((u, v), directed=False):
2384-
graph.add_edge(u, v, attr_dict=self.edge_attributes((u, v)))
2384+
graph.add_edge(u, v)
23852385

23862386
return graph
23872387

src/compas/datastructures/mesh/duality.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def mesh_dual(mesh, cls=None, include_boundary=False):
3737
>>> mesh.delete_face(6)
3838
>>> mesh.delete_face(7)
3939
>>> mesh.quads_to_triangles()
40-
>>> mesh = mesh.subdivide("corner")
40+
>>> mesh = mesh.subdivided("corner")
4141
>>> dual = mesh.dual(include_boundary=True)
4242
4343
"""
@@ -78,7 +78,7 @@ def mesh_dual(mesh, cls=None, include_boundary=False):
7878
edge_vertex = {}
7979
for boundary in mesh.edges_on_boundaries():
8080
for u, v in boundary:
81-
x, y, z = mesh.edge_midpoint(u, v)
81+
x, y, z = mesh.edge_midpoint((u, v))
8282
edge_vertex[u, v] = edge_vertex[v, u] = dual.add_vertex(x=x, y=y, z=z)
8383

8484
vertex_vertex = {}
@@ -97,7 +97,7 @@ def mesh_dual(mesh, cls=None, include_boundary=False):
9797
nbrs = mesh.vertex_neighbors(vertex, ordered=True)[::-1]
9898
vertices.append(edge_vertex[vertex, nbrs[0]])
9999
for nbr in nbrs[:-1]:
100-
vertices.append(mesh.halfedge_face(vertex, nbr))
100+
vertices.append(mesh.halfedge_face((vertex, nbr)))
101101
vertices.append(edge_vertex[vertex, nbrs[-1]])
102102
dual.add_face(vertices[::-1])
103103

src/compas/datastructures/mesh/mesh.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,6 +2855,9 @@ def remove_duplicate_vertices(self, precision=None):
28552855
36
28562856
>>> for x, y, z in mesh.vertices_attributes("xyz", keys=list(mesh.vertices())[:5]):
28572857
... mesh.add_vertex(x=x, y=y, z=z)
2858+
...
2859+
36
2860+
37
28582861
38
28592862
39
28602863
40
@@ -4791,9 +4794,9 @@ def transform_numpy(self, T):
47914794
Examples
47924795
--------
47934796
>>> from compas.datastructures import Mesh
4794-
>>> from compas.geometry import matrix_from_axis_and_angle_numpy
4797+
>>> from compas.geometry import matrix_from_axis_and_angle
47954798
>>> mesh = Mesh.from_polyhedron(6)
4796-
>>> T = matrix_from_axis_and_angle_numpy([0, 0, 1], math.pi / 4)
4799+
>>> T = matrix_from_axis_and_angle([0, 0, 1], math.pi / 4)
47974800
>>> mesh.transform_numpy(T)
47984801
47994802
"""
@@ -4906,9 +4909,9 @@ def face_matrix(self, rtype="array"):
49064909
>>> type(F)
49074910
<class 'numpy.ndarray'>
49084911
4909-
>>> from numpy import allclose
4912+
>>> from numpy import allclose, asarray
49104913
>>> xyz = asarray(mesh.vertices_attributes('xyz'))
4911-
>>> F = mesh.face_matrix(mesh, rtype='csr')
4914+
>>> F = mesh.face_matrix(rtype='csr')
49124915
>>> c1 = F.dot(xyz) / F.sum(axis=1)
49134916
>>> c2 = [mesh.face_centroid(fkey) for fkey in mesh.faces()]
49144917
>>> allclose(c1, c2)
@@ -4963,10 +4966,11 @@ def laplacian_matrix(self, rtype="array"):
49634966
--------
49644967
>>> from compas.datastructures import Mesh
49654968
>>> mesh = Mesh.from_polyhedron(6)
4966-
>>> L = mesh.laplacian_matrix(mesh, rtype='array')
4969+
>>> L = mesh.laplacian_matrix(rtype='array')
49674970
>>> type(L)
49684971
<class 'numpy.ndarray'>
49694972
4973+
>>> from numpy import asarray
49704974
>>> xyz = asarray(mesh.vertices_attributes('xyz'))
49714975
>>> L = mesh.laplacian_matrix(mesh)
49724976
>>> d = L.dot(xyz)
@@ -5005,11 +5009,11 @@ def offset(self, distance=1.0):
50055009
50065010
Examples
50075011
--------
5008-
>>> from compas.datastructures import Mesh, mesh_offset
5012+
>>> from compas.datastructures import Mesh
50095013
>>> from compas.geometry import distance_point_point as dist
50105014
>>> mesh = Mesh.from_vertices_and_faces([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], [[0, 1, 2, 3]])
5011-
>>> mesh.offset()
5012-
<compas.datastructures.mesh.mesh.Mesh object at 0x109eaad60>
5015+
>>> mesh.offset() # doctest: +ELLIPSIS
5016+
<compas.datastructures.mesh.mesh.Mesh object at ...>
50135017
50145018
"""
50155019
offset = self.copy()
@@ -5047,8 +5051,8 @@ def thickened(self, thickness=1.0, both=True):
50475051
--------
50485052
>>> from compas.datastructures import Mesh
50495053
>>> mesh = Mesh.from_vertices_and_faces([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], [[0, 1, 2, 3]])
5050-
>>> mesh.thicken(mesh)
5051-
<compas.datastructures.mesh.mesh.Mesh object at 0x109eaad60>
5054+
>>> mesh.thickened() # doctest: +ELLIPSIS
5055+
<compas.datastructures.mesh.mesh.Mesh object at ...>
50525056
50535057
"""
50545058
if thickness <= 0:

src/compas/datastructures/mesh/operations/merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def mesh_merge_faces(mesh, faces):
2121
--------
2222
>>> from compas.datastructures import Mesh
2323
>>> mesh = Mesh.from_vertices_and_faces([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], [[0, 1, 2, 3]])
24-
>>> mesh = mesh.subdivide(scheme="quad")
24+
>>> mesh = mesh.subdivided(scheme='quad')
2525
>>> mesh_merge_faces(mesh, [1, 2])
2626
5
2727
>>> mesh_merge_faces(mesh, [3, 5])

0 commit comments

Comments
 (0)