• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2


Commit MetaInfo

Revisionebe02ce214ec506922e504213fd0ba4e9d38981f (tree)
Time2023-10-21 04:32:07
AuthorAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

ASIS, refatored to remove mypy warning; added extra test for sub-NS, to raise coverty

Change Summary

Incremental Difference

diff -r 8948acb0b11d -r ebe02ce214ec castle/aigr/namednodes.py
--- a/castle/aigr/namednodes.py Fri Oct 20 15:45:25 2023 +0200
+++ b/castle/aigr/namednodes.py Fri Oct 20 21:32:07 2023 +0200
@@ -11,16 +11,17 @@
1111 from . import AIGR
1212
1313
14-
1514 class NameError(AttributeError):pass
1615
1716 @dataclass
1817 class NamedNode(AIGR):
1918 name :str
2019 _: KW_ONLY
21- _ns :PTH.Optional[NameSpace]=dc_field(init=None, default=None) #type: ignore[call-overload]
20+ # type(_ns) is NamedNode, but that leads to a cycle in imports, to use te more generic AIGR
21+ _ns :PTH.Optional[AIGR]=dc_field(init=None, default=None) #type: ignore[call-overload]
2222
23- def register_in_NS(self, ns):
23+
24+ def register_in_NS(self, ns: AIGR): #same: type(ns) is NameSpace, but ...
2425 self._ns = ns
2526
2627 @property
diff -r 8948acb0b11d -r ebe02ce214ec castle/aigr/namespaces.py
--- a/castle/aigr/namespaces.py Fri Oct 20 15:45:25 2023 +0200
+++ b/castle/aigr/namespaces.py Fri Oct 20 21:32:07 2023 +0200
@@ -13,7 +13,8 @@
1313 from enum import Enum
1414 from dataclasses import dataclass, KW_ONLY
1515 from dataclasses import field as dc_field
16-from .namednodes import *
16+
17+from .namednodes import NamedNode, NameError
1718
1819 from . import AIGR, _Marker
1920
diff -r 8948acb0b11d -r ebe02ce214ec castle/aigr/protocols.py
--- a/castle/aigr/protocols.py Fri Oct 20 15:45:25 2023 +0200
+++ b/castle/aigr/protocols.py Fri Oct 20 21:32:07 2023 +0200
@@ -10,9 +10,9 @@
1010 from . import AIGR
1111 from .events import Event
1212 from .aid import TypedParameter, Argument # Castle/AIGR types
13+from .namednodes import NamedNode
1314
14-from .namednodes import *
15-from .namespaces import NameSpace
15+
1616
1717 __all__ = ['ProtocolKind', 'Protocol', 'EventProtocol']
1818 # DataProtocol, StreamProtocol are added/implemented later
@@ -43,7 +43,6 @@
4343 kind :ProtocolKind
4444 based_on :PTH.Optional[Protocol]=dc_field(default_factory= lambda :Protocol._BASE) # pragma: no mutate
4545 typedParameters :PTH.Optional[PTH.Sequence[TypedParameter]]=()
46- _ns :PTH.Optional[NameSpace]=dc_field(init=None, default=None) #type: ignore[call-overload]
4746
4847
4948 @dataclass # pragma: no mutate
diff -r 8948acb0b11d -r ebe02ce214ec pytst/aigr/test_3_namespaces.py
--- a/pytst/aigr/test_3_namespaces.py Fri Oct 20 15:45:25 2023 +0200
+++ b/pytst/aigr/test_3_namespaces.py Fri Oct 20 21:32:07 2023 +0200
@@ -28,6 +28,17 @@
2828 return ns
2929
3030 @pytest.fixture
31+def top():
32+ top = NameSpace('top')
33+ return top
34+
35+@pytest.fixture
36+def sub(top):
37+ sub = NameSpace('sub')
38+ top.register(sub)
39+ return sub
40+
41+@pytest.fixture
3142 def sourceNS(a_node):
3243 ns = Source_NS("sourceNS", source="dummy")
3344 ns.register(a_node)
@@ -72,7 +83,7 @@
7283 assert aNS.getID(name) is two #The test
7384
7485
75-def test_5b_ns_in_ns():
86+def test_5a_ns_in_ns():
7687 "when we import a NS, we get a NS in a NS ..."
7788 top = NameSpace('top')
7889 sub = NameSpace('sub')
@@ -84,6 +95,18 @@
8495 assert sub.getID('elm') is elm
8596 assert top.search(dottedName="sub.elm") is elm
8697
98+
99+def test_5b_seach_1level(aNS,a_node):
100+ name = a_node.name
101+ assert (aNS.search(name) is a_node) and (aNS.getID(name) is a_node), "serach should find that what getID returns"
102+
103+
104+def test_5c_seachNotFound_1(top):
105+ assert top.search("Deze bestaat niet") is None
106+
107+def test_5d_seachNotFound_sub(top, sub):
108+ assert top.search("top.Deze.bestaat.niet") is None
109+
87110 def test_6a_registered_is_2ways(aNS, a_node):
88111 """When a NamedNode is registered in a NameSpace, it should a backlink (`ns property) to the NS again"""
89112 assert a_node.ns is aNS