Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Nov 5, 2024
1 parent 863939a commit 1100e0e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/faebryk/core/cpp/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class LinkDirectConditional(LinkDirect):
self, arg: Callable[[GraphInterface, GraphInterface], bool], /
) -> None: ...

class LinkFilteredException(Exception):
pass

class LinkNamedParent(LinkParent):
def __init__(self, arg: str, /) -> None: ...

Expand Down
4 changes: 3 additions & 1 deletion src/faebryk/core/cpp/src/graph/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ void Graph::add_edge(Link_ref link) {

// remove existing link
if (this->e_cache_simple[from].contains(to)) {
this->remove_edge(this->e_cache[from][to]);
// this->remove_edge(this->e_cache[from][to]);
// TODO: reconsider this
throw std::runtime_error("link already exists");
}

e_cache_simple[from].insert(to);
Expand Down
3 changes: 3 additions & 0 deletions src/faebryk/core/cpp/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ PYMOD(m) {
nb::class_<LinkDirectConditional, LinkDirect>(m, "LinkDirectConditional")
.def(nb::init<LinkDirectConditional::FilterF>());

nb::exception<LinkDirectConditional::LinkFilteredException>(m,
"LinkFilteredException");

// Node
nb::class_<Node>(m, "Node")
.def(nb::init<>())
Expand Down
4 changes: 1 addition & 3 deletions src/faebryk/core/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
Link,
LinkDirect,
LinkDirectConditional,
LinkFilteredException,
LinkNamedParent,
LinkParent,
LinkPointer,
LinkSibling,
)


class LinkFilteredException(Exception): ...
15 changes: 7 additions & 8 deletions src/faebryk/core/moduleinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,21 @@ class _LinkDirectShallow(LinkDirectConditional):
Make link that only connects up but not down
"""

def test(self, node: CNode):
return not any(
isinstance(p[0], self.type_test) for p in node.get_hierarchy()[:-1]
)
def has_no_parent_with_type(self, node: CNode):
parents = (p[0] for p in node.get_hierarchy()[:-1])
return not any(isinstance(p, self.test_type) for p in parents)

def __init__(self, type_test: type["ModuleInterface"]):
self.type_test = type_test
super().__init__(lambda src, dst: self.test(dst.node))
def __init__(self, test_type: type["ModuleInterface"]):
self.test_type = test_type
super().__init__(lambda src, dst: self.has_no_parent_with_type(dst.node))

# TODO rename
@classmethod
@once
def LinkDirectShallow(cls):
class _LinkDirectShallowMif(ModuleInterface._LinkDirectShallow):
def __init__(self):
super().__init__(cls)
super().__init__(test_type=cls)

return _LinkDirectShallowMif

Expand Down
1 change: 1 addition & 0 deletions src/faebryk/library/can_be_decoupled_rails.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class can_be_decoupled_rails(F.can_be_decoupled.impl()):
def __init__(self, *rails: F.ElectricPower):
super().__init__()
assert rails
self._rails = rails

Expand Down
4 changes: 2 additions & 2 deletions test/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class linkcls(LinkDirect):
self.assertIsInstance(gif1.is_connected(gif3), linkcls)
self.assertEqual(gif1.is_connected(gif3), gif3.is_connected(gif1))

self.assertRaises(AssertionError, lambda: gif1.connect(gif3))
gif1.connect(gif3, linkcls())
self.assertRaises(RuntimeError, lambda: gif1.connect(gif3))
self.assertRaises(RuntimeError, lambda: gif1.connect(gif3, linkcls()))

self.assertEqual(gif1.G, gif2.G)

Expand Down

0 comments on commit 1100e0e

Please sign in to comment.