Skip to content

Commit f7e283f

Browse files
committed
⚫ black
1 parent 62d54c6 commit f7e283f

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

src/compas/datastructures/assembly/assembly.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,42 @@ def __init__(self, name=None, **kwargs):
4141
@property
4242
def DATASCHEMA(self):
4343
import schema
44-
return schema.Schema({
45-
"attributes": dict,
46-
"graph": Graph,
47-
})
44+
45+
return schema.Schema(
46+
{
47+
"attributes": dict,
48+
"graph": Graph,
49+
}
50+
)
4851

4952
@property
5053
def JSONSCHEMANAME(self):
51-
return 'assembly'
54+
return "assembly"
5255

5356
@property
5457
def data(self):
5558
data = {
56-
'attributes': self.attributes,
57-
'graph': self.graph.data,
59+
"attributes": self.attributes,
60+
"graph": self.graph.data,
5861
}
5962
return data
6063

6164
@data.setter
6265
def data(self, data):
63-
self.attributes.update(data['attributes'] or {})
64-
self.graph.data = data['graph']
66+
self.attributes.update(data["attributes"] or {})
67+
self.graph.data = data["graph"]
6568

6669
# ==========================================================================
6770
# properties
6871
# ==========================================================================
6972

7073
@property
7174
def name(self):
72-
return self.attributes.get('name') or self.__class__.__name__
75+
return self.attributes.get("name") or self.__class__.__name__
7376

7477
@name.setter
7578
def name(self, value):
76-
self.attributes['name'] = value
79+
self.attributes["name"] = value
7780

7881
# ==========================================================================
7982
# customization
@@ -143,10 +146,11 @@ def add_connection(self, a, b, **kwargs):
143146
If `a` and/or `b` are not in the assembly.
144147
145148
"""
149+
error_msg = "Both parts have to be added to the assembly before a connection can be created."
146150
if a.key is None or b.key is None:
147-
raise AssemblyError('Both parts have to be added to the assembly before a connection can be created.')
151+
raise AssemblyError(error_msg)
148152
if not self.graph.has_node(a.key) or not self.graph.has_node(b.key):
149-
raise AssemblyError('Both parts have to be added to the assembly before a connection can be created.')
153+
raise AssemblyError(error_msg)
150154
return self.graph.add_edge(a.key, b.key, **kwargs)
151155

152156
def parts(self):
@@ -159,7 +163,7 @@ def parts(self):
159163
160164
"""
161165
for node in self.graph.nodes():
162-
yield self.graph.node_attribute(node, 'part')
166+
yield self.graph.node_attribute(node, "part")
163167

164168
def connections(self, data=False):
165169
"""Iterate over the connections between the parts.

tests/compas/datastructures/test_assembly.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
from compas.datastructures import Assembly, assembly
1+
import pytest
2+
3+
from compas.datastructures import Assembly
4+
from compas.datastructures import AssemblyError
25
from compas.datastructures import Part
36

47

58
def test_init():
6-
assembly = Assembly(name='abc')
7-
assert assembly.name == 'abc'
9+
assembly = Assembly(name="abc")
10+
assert assembly.name == "abc"
811

9-
assembly = Assembly(attr1='value', attr2=3.14)
10-
assert assembly.attributes['attr1'] == 'value'
11-
assert assembly.attributes['attr2'] == 3.14
12+
assembly = Assembly(attr1="value", attr2=3.14)
13+
assert assembly.attributes["attr1"] == "value"
14+
assert assembly.attributes["attr2"] == 3.14
1215

1316

1417
def test_add_parts():
@@ -20,6 +23,16 @@ def test_add_parts():
2023
assert len(list(assembly.parts())) == 3
2124

2225

26+
def test_add_duplicate_parts():
27+
assembly = Assembly()
28+
29+
part = Part()
30+
assembly.add_part(part)
31+
32+
with pytest.raises(AssemblyError):
33+
assembly.add_part(part)
34+
35+
2336
def test_add_connections():
2437
assembly = Assembly()
2538
parts = [Part() for i in range(3)]

0 commit comments

Comments
 (0)