Skip to content

Commit 23936e1

Browse files
committed
Fix tests
1 parent ee19e69 commit 23936e1

4 files changed

Lines changed: 28 additions & 22 deletions

File tree

.github/workflows/pythonapp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ jobs:
3636
- name: Test with pytest
3737
run: |
3838
pip install pytest pytest-cov pyecore==0.12.2
39-
pytest --cov=pylasu --cov-fail-under=40 tests
39+
pytest --cov=pylasu --cov-fail-under=50 tests

pylasu/emf/model.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ def to_eobject(self: Node, resource: Resource, mappings=None):
4040
raise Exception("Unknown classifier for " + str(type(self)))
4141
eobject = eclass()
4242
mappings[id(self)] = eobject
43-
for (p, v) in self.properties:
43+
for p in self.properties:
44+
v = p.value
4445
ev = translate_value(v, resource, mappings)
4546
if isinstance(v, list):
46-
eobject.eGet(p).extend(ev)
47+
eobject.eGet(p.name).extend(ev)
4748
else:
48-
eobject.eSet(p, ev)
49+
eobject.eSet(p.name, ev)
4950
return eobject
5051

5152

pylasu/model/processing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def assign_parents(self: Node):
2121

2222

2323
def children(self: Node):
24-
yield from nodes_in(v for _, v in self.properties)
24+
yield from nodes_in(p.value for p in self.properties)
2525

2626

2727
Node.children = internal_property(children)
@@ -44,7 +44,9 @@ def search_by_type(self: Node, target_type, walker=walk):
4444

4545
@extension_method(Node)
4646
def transform_children(self: Node, operation: Callable[[Node], Node]):
47-
for name, value in self.properties:
47+
for prop in self.properties:
48+
name = prop.name
49+
value = prop.value
4850
if isinstance(value, Node):
4951
new_value = operation(value)
5052
if new_value != value:

tests/test_model.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@dataclasses.dataclass
1111
class SomeNode(Node, Named):
1212
foo = 3
13+
bar: int = dataclasses.field(init=False)
1314
__private__ = 4
1415
ref: Node = None
1516
multiple: List[Node] = dataclasses.field(default_factory=list)
@@ -66,17 +67,17 @@ def test_node_with_position(self):
6667

6768
def test_node_properties(self):
6869
node = SomeNode("n").with_position(Position(Point(1, 0), Point(2, 1)))
69-
self.assertIsNotNone(next(n for n, _ in node.properties if n == 'foo'))
70-
self.assertIsNotNone(next(n for n, _ in node.properties if n == 'bar'))
71-
self.assertIsNotNone(next(n for n, _ in node.properties if n == "name"))
70+
self.assertIsNotNone(next(n for n in node.properties if n.name == 'foo'))
71+
self.assertIsNotNone(next(n for n in node.properties if n.name == 'bar'))
72+
self.assertIsNotNone(next(n for n in node.properties if n.name == "name"))
7273
with self.assertRaises(StopIteration):
73-
next(n for n, _ in node.properties if n == '__private__')
74+
next(n for n in node.properties if n.name == '__private__')
7475
with self.assertRaises(StopIteration):
75-
next(n for n, _ in node.properties if n == 'non_existent')
76+
next(n for n in node.properties if n.name == 'non_existent')
7677
with self.assertRaises(StopIteration):
77-
next(n for n, _ in node.properties if n == 'properties')
78+
next(n for n in node.properties if n.name == 'properties')
7879
with self.assertRaises(StopIteration):
79-
next(n for n, _ in node.properties if n == "origin")
80+
next(n for n in node.properties if n.name == "origin")
8081

8182
def test_scope_lookup_0(self):
8283
"""Symbol found in local scope with name and default type"""
@@ -137,13 +138,15 @@ def test_scope_lookup_7(self):
137138

138139
def test_node_properties_meta(self):
139140
pds = [pd for pd in sorted(SomeNode.node_properties, key=lambda x: x.name)]
140-
self.assertEqual(4, len(pds))
141-
self.assertEqual("foo", pds[0].name)
141+
self.assertEqual(5, len(pds))
142+
self.assertEqual("bar", pds[0].name)
142143
self.assertFalse(pds[0].provides_nodes)
143-
self.assertEqual("multiple", pds[1].name)
144-
self.assertTrue(pds[1].provides_nodes)
145-
self.assertEqual(Multiplicity.MANY, pds[1].multiplicity)
146-
self.assertEqual("name", pds[2].name)
147-
self.assertFalse(pds[2].provides_nodes)
148-
self.assertEqual("ref", pds[3].name)
149-
self.assertTrue(pds[3].provides_nodes)
144+
self.assertEqual("foo", pds[1].name)
145+
self.assertFalse(pds[1].provides_nodes)
146+
self.assertEqual("multiple", pds[2].name)
147+
self.assertTrue(pds[2].provides_nodes)
148+
self.assertEqual(Multiplicity.MANY, pds[2].multiplicity)
149+
self.assertEqual("name", pds[3].name)
150+
self.assertFalse(pds[3].provides_nodes)
151+
self.assertEqual("ref", pds[4].name)
152+
self.assertTrue(pds[4].provides_nodes)

0 commit comments

Comments
 (0)