Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Révision | 23b88308a2285e8ada96e9953e6386778d5101c6 (tree) |
---|---|
l'heure | 2024-04-14 03:17:49 |
Auteur | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
asis (failing tests)
@@ -29,6 +29,4 @@ | ||
29 | 29 | .*_packages/.*/dist/ |
30 | 30 | build/ |
31 | 31 | |
32 | -TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/doc/moats.png | |
33 | -TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/doc/namespaces.png | |
34 | -TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/doc/protocols.png | |
32 | +.*/doc/.*\.png |
@@ -9,6 +9,7 @@ | ||
9 | 9 | |
10 | 10 | clean_caches: |
11 | 11 | find . -type d -name __pycache__ -print0 | xargs -0 rm -r |
12 | + find . -type f -name \*.pyc -print0 | xargs -0 rm | |
12 | 13 | find . -type d -name .pytest_cache -print0 | xargs -0 rm -r |
13 | 14 | rm -rf ./.coverage |
14 | 15 | rm -rf ./.mutmut-cache |
@@ -1,17 +1,16 @@ | ||
1 | 1 | default: all |
2 | 2 | |
3 | -PYREVERSE_PKGS = castle/TESTDOUBLES/aigr.sieve castle/TESTDOUBLES/aigr.base | |
3 | +PYREVERSE_PKGS = castle/TESTDOUBLES/aigr.base castle/TESTDOUBLES/aigr.sieve.basic | |
4 | 4 | |
5 | 5 | LAST = \ |
6 | - pytst/test_0_base.py \ | |
7 | - pytst/test_1_sieve_protocols.py \ | |
8 | - pytst/test_2_sieve_NS.py \ | |
6 | + pytst/base/test_0_base.py \ | |
9 | 7 | # |
10 | 8 | CURRENT = \ |
11 | - pytst/test_3_moat.py \ | |
9 | + pytst/sieve/basic1/test_2_sieve_NS.py \ | |
12 | 10 | # |
13 | 11 | |
14 | 12 | TODO = \ |
13 | + pytst/sieve/basic1/test_1_sieve_protocols.py \ | |
15 | 14 | # |
16 | 15 | |
17 | 16 |
@@ -1,5 +0,0 @@ | ||
1 | -# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | - | |
3 | -from .protocols import * | |
4 | -from .namespaces import * | |
5 | -#XXXfrom .moats import * |
@@ -0,0 +1,5 @@ | ||
1 | +# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | + | |
3 | +#from .protocols import * | |
4 | +#from .namespaces import * | |
5 | +#XXXfrom .moats import * |
@@ -0,0 +1,51 @@ | ||
1 | +# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | + | |
3 | +"""This manual crafted AIGR (a TestDoubles) is for the "base version" of the Sieve [#1]_. | |
4 | + It does NOT uses SlowStart -- nor does solve the Heisenbug [2]_ | |
5 | + | |
6 | + .. [#1] http://docideas.mietus.nl/en/default/CCastle/4.Blog/1.TheSieve.html | |
7 | + .. [#2] http://docideas.mietus.nl/en/default/CCastle/4.Blog/2.Heisenbug.html | |
8 | +""" | |
9 | + | |
10 | +from castle.aigr.aid import TypedParameter | |
11 | +from castle.aigr import ComponentInterface, ID | |
12 | +from castle.aigr import Port, PortDirection | |
13 | + | |
14 | +from . import protocols | |
15 | + | |
16 | + | |
17 | +# component Generator : Component { | |
18 | +# port StartSieve<in>:controll; | |
19 | +# port SimpleSieve<out>:outlet; | |
20 | +# } | |
21 | +GeneratorMoat = ComponentInterface(name=ID("Generator"), | |
22 | + ports=( | |
23 | + Port(name='controll', direction=PortDirection.In, type=protocols.StartSieve), | |
24 | + Port(name='outlet', direction=PortDirection.Out, type=protocols.SimpleSieve), | |
25 | + )) | |
26 | + | |
27 | + | |
28 | +# component Sieve(onPrime:int) : Component { | |
29 | +# port SimpleSieve<in>:try; | |
30 | +# port SimpleSieve<out>:coprime; | |
31 | +# } | |
32 | +SieveMoat = ComponentInterface(name=ID("Sieve"), | |
33 | + ports=( | |
34 | + Port(name='try', direction=PortDirection.In, type=protocols.SimpleSieve), | |
35 | + Port(name='coprime', direction=PortDirection.Out, type=protocols.SimpleSieve), | |
36 | + )) | |
37 | + | |
38 | + | |
39 | +# component Finder : Component { | |
40 | +# port SimpleSieve<in>:newPrime; | |
41 | +# port SimpleSieve<out>:found; | |
42 | +# } | |
43 | +FinderMoat = ComponentInterface(name=ID("Finder"), | |
44 | + ports=( | |
45 | + Port(name='newPrime', direction=PortDirection.In, type=protocols.SimpleSieve), | |
46 | + Port(name='found', direction=PortDirection.Out, type=protocols.SimpleSieve), | |
47 | + )) | |
48 | + | |
49 | + | |
50 | + | |
51 | + |
@@ -0,0 +1,48 @@ | ||
1 | +# (C) Albert Mietus, 2023,2024 Part of Castle/CCastle project | |
2 | + | |
3 | +from castle.aigr import NameSpace, Source_NS, ID | |
4 | + | |
5 | +# Note: this file only creates the namespaces, not the components (etc in those file) | |
6 | +## | |
7 | +## FILES | |
8 | +## | |
9 | + | |
10 | +# We mimic that both protocols ('StartSieve' & 'SimpleSieve') are defined in 1 file: :file:`protocols.Moat` | |
11 | +protocols = Source_NS(ID('protocols'), source='protocols.Moat') | |
12 | + | |
13 | +# Similar, all (comp) interfaces are located in the file: :file:`interfaces.Moat` | |
14 | +interfaces = Source_NS(ID('interfaces'), source='interfaces.Moat') | |
15 | + | |
16 | +# Each (3) components are coded in its on Castle-file. | |
17 | +comps = { name : Source_NS(ID(name), source=name+'.Moat') for name in ('generator', 'sieve', 'finder')} | |
18 | + | |
19 | +## | |
20 | +## IMPORTS | |
21 | +## | |
22 | + | |
23 | +# `protocols.Moat` has no imports | |
24 | + | |
25 | +# `interfaces.Moat` needs to import <protocols> | |
26 | +interfaces.register(protocols) | |
27 | + | |
28 | +# Each comp need to import it own interface, and all protocols | |
29 | +for comp in comps.values(): | |
30 | + comp.register(interfaces) | |
31 | + comp.register(protocols) | |
32 | + | |
33 | + | |
34 | +# Main is the main namespace, which imports both <interfaces> and <protocols> | |
35 | +main = Source_NS(ID('main'), source='main.Moat') | |
36 | +main.register(interfaces) | |
37 | +main.register(protocols) | |
38 | + | |
39 | + | |
40 | +## | |
41 | +## Q: Should main import the components? | |
42 | +## | |
43 | +## It's and option: _OPT_MAIN_IMPORTS_COMPS | |
44 | +def _main_imports_comps(): | |
45 | + for comp in (ns for name,ns in comps.items() if name != 'main'): | |
46 | + main.register(comp) | |
47 | +_OPT_MAIN_IMPORTS_COMPS=True | |
48 | +if _OPT_MAIN_IMPORTS_COMPS: _main_imports_comps() |
@@ -0,0 +1,29 @@ | ||
1 | +# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | + | |
3 | +from castle.aigr import EventProtocol, Event, ID | |
4 | +from castle.aigr import TypedParameter, Argument, Specialise | |
5 | + | |
6 | +import typing as PTH # Python TypeHints | |
7 | + | |
8 | +StartSieve = EventProtocol(ID('StartSieve'), | |
9 | + events=( | |
10 | + Event(name=ID('runTo'), return_type=None, typedParameters=(TypedParameter(name='max', type=int),)), | |
11 | + Event(name=ID('newMax'), return_type=None, typedParameters=(TypedParameter(name='max', type=int),)))) | |
12 | + | |
13 | + | |
14 | +SlowStart = EventProtocol(ID('SlowStart'), | |
15 | + typedParameters=(TypedParameter(name='queue_max', type=int),), | |
16 | + events=( | |
17 | + Event(name=ID('setMax'), return_type=None, typedParameters=(TypedParameter(name='queue_max', type=int),)),)) | |
18 | + | |
19 | +SlowStart_1 = Specialise(ID("SlowStart_1"), | |
20 | + based_on=SlowStart, | |
21 | + #OR: arguments=(Argument(name=queue_max, value=1),)) | |
22 | + arguments=(Argument(value=1),)) | |
23 | + | |
24 | +SimpleSieve = EventProtocol(ID('SimpleSieve'), | |
25 | + based_on=SlowStart_1, | |
26 | + events=( | |
27 | + Event(name=ID('input'), return_type=None, typedParameters=(TypedParameter(name='try', type=int),)),)) | |
28 | + | |
29 | + |
@@ -1,21 +0,0 @@ | ||
1 | -@startuml | |
2 | - | |
3 | - | |
4 | -package Classes <<Cloud>> { | |
5 | -class ComponentInterface | |
6 | -} | |
7 | - | |
8 | - | |
9 | - | |
10 | -'SieveMoat = ComponentInterface(name=ID("Sieve"), | |
11 | -' ports=( | |
12 | -' Port(name='try', direction=PortDirection.In, type=protocols.SimpleSieve), | |
13 | -' Port(name='coprime', direction=PortDirection.Out, type=protocols.SimpleSieve), | |
14 | -' )) | |
15 | -object SieveMoat { | |
16 | - name = "Sieve" | |
17 | - ports = [try, coprime] | |
18 | -} | |
19 | -ComponentInterface <|-- SieveMoat | |
20 | - | |
21 | -@enduml |
@@ -1,43 +0,0 @@ | ||
1 | -@startuml | |
2 | - | |
3 | -package Classes <<Cloud>> { | |
4 | -class NameSpace | |
5 | -class Source_NS | |
6 | -NameSpace <|- Source_NS | |
7 | -} | |
8 | - | |
9 | -package NameSpaces <<Node>> { | |
10 | -object top { | |
11 | - name="The Sieve" | |
12 | -} | |
13 | -object start_sieve | |
14 | -object slow_start | |
15 | -object simple_sieve | |
16 | -object base | |
17 | -} | |
18 | - | |
19 | -package "Sieve Protocols" { | |
20 | - object StartSieve | |
21 | - object SlowStart | |
22 | - object SlowStart_1 | |
23 | - SlowStart <|.. SlowStart_1 | |
24 | - object SimpleSieve | |
25 | -} | |
26 | -start_sieve o.. base : register | |
27 | -slow_start o.. base : register | |
28 | -simple_sieve o.. base : register | |
29 | - | |
30 | - | |
31 | -start_sieve o.. StartSieve : register | |
32 | - | |
33 | -slow_start o.. SlowStart_1 : register | |
34 | -simple_sieve o.. slow_start : register | |
35 | - | |
36 | -simple_sieve o.. SimpleSieve : register | |
37 | - | |
38 | -top o.. start_sieve : register | |
39 | -top o.. slow_start : register | |
40 | -top o.. simple_sieve : register | |
41 | -top o.. base : register | |
42 | - | |
43 | -@enduml |
@@ -1,53 +0,0 @@ | ||
1 | -@startuml | |
2 | - | |
3 | - | |
4 | -package Classes <<Cloud>> { | |
5 | -class EventProtocol | |
6 | -class Specialise | |
7 | -EventProtocol <|- Specialise | |
8 | -} | |
9 | - | |
10 | -'StartSieve = EventProtocol(ID('StartSieve'), | |
11 | -' events=( | |
12 | -' Event(name=ID('runTo'), return_type=None, typedParameters=(TypedParameter(name='max', type=int),)), | |
13 | -' Event(name=ID('newMax'), return_type=None, typedParameters=(TypedParameter(name='max', type=int),)))) | |
14 | -object StartSieve { | |
15 | - events = [runTo, newMax] | |
16 | -} | |
17 | -EventProtocol <--- StartSieve | |
18 | - | |
19 | - | |
20 | -'SlowStart = EventProtocol(ID('SlowStart'), | |
21 | -' typedParameters=(TypedParameter(name='queue_max', type=int),), | |
22 | -' events=( | |
23 | -' Event(name=ID('setMax'), return_type=None, typedParameters=(TypedParameter(name='queue_max', type=int),)),)) | |
24 | -object SlowStart { | |
25 | - typedParameters = (queue_max :int,) | |
26 | - events = [setMax] | |
27 | -} | |
28 | -EventProtocol <--- SlowStart | |
29 | - | |
30 | - | |
31 | -'SlowStart_1 = Specialise(ID("SlowStart_1"), | |
32 | -' based_on=SlowStart, | |
33 | -' #OR: arguments=(Argument(name=queue_max, value=1),)) | |
34 | -' arguments=(Argument(value=1),)) | |
35 | -object SlowStart_1 { | |
36 | - based_on = SlowStart | |
37 | - arguments = (queue_max=1) | |
38 | -} | |
39 | -Specialise <-- SlowStart_1 | |
40 | -SlowStart <|- SlowStart_1 | |
41 | - | |
42 | -'SimpleSieve = EventProtocol(ID('SimpleSieve'), | |
43 | -' based_on=SlowStart_1, | |
44 | -' events=( | |
45 | -' Event(name=ID('input'), return_type=None, typedParameters=(TypedParameter(name='try', type=int),)),)) | |
46 | -object SimpleSieve { | |
47 | - based_on = SlowStart_1 | |
48 | - events = [input] | |
49 | -} | |
50 | -EventProtocol <--- SimpleSieve | |
51 | -SlowStart_1 <|- SimpleSieve | |
52 | - | |
53 | -@enduml |
@@ -1,51 +0,0 @@ | ||
1 | -# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | - | |
3 | -"""This manual crafted AIGR (a TestDoubles) is for the "base version" of the Sieve [#1]_. | |
4 | - It does NOT uses SlowStart -- nor does solve the Heisenbug [2]_ | |
5 | - | |
6 | - .. [#1] http://docideas.mietus.nl/en/default/CCastle/4.Blog/1.TheSieve.html | |
7 | - .. [#2] http://docideas.mietus.nl/en/default/CCastle/4.Blog/2.Heisenbug.html | |
8 | -""" | |
9 | - | |
10 | -from castle.aigr.aid import TypedParameter | |
11 | -from castle.aigr import ComponentInterface, ID | |
12 | -from castle.aigr import Port, PortDirection | |
13 | - | |
14 | -from . import protocols | |
15 | - | |
16 | - | |
17 | -# component Generator : Component { | |
18 | -# port StartSieve<in>:controll; | |
19 | -# port SimpleSieve<out>:outlet; | |
20 | -# } | |
21 | -GeneratorMoat = ComponentInterface(name=ID("Generator"), | |
22 | - ports=( | |
23 | - Port(name='controll', direction=PortDirection.In, type=protocols.StartSieve), | |
24 | - Port(name='outlet', direction=PortDirection.Out, type=protocols.SimpleSieve), | |
25 | - )) | |
26 | - | |
27 | - | |
28 | -# component Sieve(onPrime:int) : Component { | |
29 | -# port SimpleSieve<in>:try; | |
30 | -# port SimpleSieve<out>:coprime; | |
31 | -# } | |
32 | -SieveMoat = ComponentInterface(name=ID("Sieve"), | |
33 | - ports=( | |
34 | - Port(name='try', direction=PortDirection.In, type=protocols.SimpleSieve), | |
35 | - Port(name='coprime', direction=PortDirection.Out, type=protocols.SimpleSieve), | |
36 | - )) | |
37 | - | |
38 | - | |
39 | -# component Finder : Component { | |
40 | -# port SimpleSieve<in>:newPrime; | |
41 | -# port SimpleSieve<out>:found; | |
42 | -# } | |
43 | -FinderMoat = ComponentInterface(name=ID("Finder"), | |
44 | - ports=( | |
45 | - Port(name='newPrime', direction=PortDirection.In, type=protocols.SimpleSieve), | |
46 | - Port(name='found', direction=PortDirection.Out, type=protocols.SimpleSieve), | |
47 | - )) | |
48 | - | |
49 | - | |
50 | - | |
51 | - |
@@ -1,26 +0,0 @@ | ||
1 | -# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | - | |
3 | -from castle.aigr import NameSpace, Source_NS, ID | |
4 | - | |
5 | -start_sieve = Source_NS(ID('start_sieve')) | |
6 | -slow_start = Source_NS(ID('slow_start')) | |
7 | -simple_sieve = Source_NS(ID('simple_sieve')) | |
8 | - | |
9 | -from ..base import base | |
10 | -for all in (start_sieve, slow_start, simple_sieve): all.register(base) | |
11 | - | |
12 | -from . import protocols | |
13 | - | |
14 | -start_sieve.register(protocols.StartSieve) | |
15 | -slow_start.register(protocols.SlowStart) | |
16 | -simple_sieve.register(slow_start) # Import/use, to be able to refer slow_start.SlowStart | |
17 | -#simple_sieve.register(protocols.SlowStart_1) | |
18 | -simple_sieve.register(protocols.SimpleSieve) | |
19 | - | |
20 | - | |
21 | - | |
22 | -top = NameSpace(ID('TheSieve')) | |
23 | -top.register(start_sieve) | |
24 | -top.register(slow_start) | |
25 | -top.register(simple_sieve) | |
26 | -top.register(base) |
@@ -1,29 +0,0 @@ | ||
1 | -# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | - | |
3 | -from castle.aigr import EventProtocol, Event, ID | |
4 | -from castle.aigr import TypedParameter, Argument, Specialise | |
5 | - | |
6 | -import typing as PTH # Python TypeHints | |
7 | - | |
8 | -StartSieve = EventProtocol(ID('StartSieve'), | |
9 | - events=( | |
10 | - Event(name=ID('runTo'), return_type=None, typedParameters=(TypedParameter(name='max', type=int),)), | |
11 | - Event(name=ID('newMax'), return_type=None, typedParameters=(TypedParameter(name='max', type=int),)))) | |
12 | - | |
13 | - | |
14 | -SlowStart = EventProtocol(ID('SlowStart'), | |
15 | - typedParameters=(TypedParameter(name='queue_max', type=int),), | |
16 | - events=( | |
17 | - Event(name=ID('setMax'), return_type=None, typedParameters=(TypedParameter(name='queue_max', type=int),)),)) | |
18 | - | |
19 | -SlowStart_1 = Specialise(ID("SlowStart_1"), | |
20 | - based_on=SlowStart, | |
21 | - #OR: arguments=(Argument(name=queue_max, value=1),)) | |
22 | - arguments=(Argument(value=1),)) | |
23 | - | |
24 | -SimpleSieve = EventProtocol(ID('SimpleSieve'), | |
25 | - based_on=SlowStart_1, | |
26 | - events=( | |
27 | - Event(name=ID('input'), return_type=None, typedParameters=(TypedParameter(name='try', type=int),)),)) | |
28 | - | |
29 | - |
@@ -4,15 +4,17 @@ | ||
4 | 4 | folder "src files" { |
5 | 5 | |
6 | 6 | file "protocols.Moat" as p #Technology { |
7 | - node "protocol StartSieve" | |
8 | - node "protocol SimpleSieve" | |
7 | + component "protocol StartSieve" | |
8 | + component "protocol SimpleSieve" | |
9 | 9 | } |
10 | 10 | file "interfaces.Moat" as i #Technology { |
11 | - node "component Generator" | |
12 | - node "component Sieve" | |
13 | - node "component Finder" | |
11 | + component "component Generator" as gi | |
12 | + component "component Sieve" as si | |
13 | + component "component Finder" as fi | |
14 | + gi -right[hidden]-> si | |
15 | + si -right[hidden]-> fi | |
14 | 16 | } |
15 | - p <- i : "import <protocol>" | |
17 | + i->p : "import <protocol>" | |
16 | 18 | |
17 | 19 | |
18 | 20 | file "generator.Castle" as G #DarkSeaGreen { |
@@ -32,17 +34,17 @@ | ||
32 | 34 | p <-- F : import <protocols> |
33 | 35 | |
34 | 36 | file "main.Castle" as M #SeaGreen { |
35 | - node "component Main" | |
36 | - node "implement Main" { | |
37 | + component "component Main" #gray | |
38 | + node "implement Main" #application { | |
37 | 39 | control powerOn #LightSeaGreen |
38 | 40 | } |
39 | 41 | } |
40 | 42 | i <--- M : import <interfaces> |
41 | 43 | p <--- M : import <protocols> |
42 | 44 | |
43 | - G <. M | |
44 | - S <. M | |
45 | - F <. M | |
45 | + G <.. M | |
46 | + S <.. M | |
47 | + F <.. M | |
46 | 48 | } |
47 | 49 | @enduml |
48 | 50 |
@@ -4,6 +4,7 @@ | ||
4 | 4 | |
5 | 5 | [project] |
6 | 6 | name = "castle-TestDoubles-aigr-sieve" |
7 | +description = "A (partial, manually crafted) ``aigr`` TestDouble(s) for Sieve(s) -- as ref for reading(parsing) or input for writing" | |
7 | 8 | version = "0.0.1" |
8 | 9 | dependencies = ["castle-aigr"] |
9 | 10 |
@@ -1,45 +0,0 @@ | ||
1 | -# (C) Albert Mietus, 2023,2024 Part of Castle/CCastle project | |
2 | -# verify/aux test-functions | |
3 | - | |
4 | -import castle.aigr as aigr | |
5 | -from castle.TESTDOUBLES.aigr.base import Protocol as base_Protocol | |
6 | - | |
7 | -def verify_Protocol(p, name, my_event_names, total_no_of_event=None, base=None, cls=None): | |
8 | - if base is None: | |
9 | - base=base_Protocol | |
10 | - no_events = total_no_of_event if total_no_of_event else len(my_event_names) | |
11 | - if cls is None: | |
12 | - cls = aigr.EventProtocol | |
13 | - | |
14 | - assert isinstance(p, cls) | |
15 | - assert str(p.name) == name, f"{p.name} reported but expected: {name}" | |
16 | - assert p.based_on is base | |
17 | - assert p._noEvents() == no_events, f"{p.name} reports {p._noEvents()} events, but expected: {no_events} event(s)" | |
18 | - for no, name in enumerate(my_event_names): | |
19 | - assert str(p.events[no].name) == name, f"{p.name} (own/local) event no={no}: {p.events[no].name}, expected: {name}" | |
20 | - | |
21 | - | |
22 | - | |
23 | -def verify_NS(ns, name, registered_names, as_name=None): | |
24 | - if as_name is None: as_name=name | |
25 | - assert str(ns.name) == as_name, f"verify_NS:: name={ns.name}, expected: {as_name}\n\tns={ns}" | |
26 | - for n in registered_names: | |
27 | - if isinstance(n, (list, tuple)): | |
28 | - # This is hardly/not used: but .... We support `import n[1] as n[0]` | |
29 | - assert len(n) == 2 | |
30 | - name, asName = n[1], n[0] | |
31 | - else: | |
32 | - name, asName = n, n | |
33 | - assert str(ns.getID(asName).name) == name | |
34 | - | |
35 | -def verify_ComponentInterface(i, name, my_port_names=[], total_no_of_ports=None): | |
36 | - if total_no_of_ports is None: | |
37 | - total_no_of_ports = len(my_port_names) | |
38 | - | |
39 | - assert isinstance(i, aigr.ComponentInterface) | |
40 | - assert str(i.name) == name, f"{i.name} reported but expected: {name}" | |
41 | - | |
42 | - for no, name in enumerate(my_port_names): | |
43 | - assert str(i.ports[no].name) == name, f"{i.name} (own/local) port no={no}: {i.ports[no].name}, expected: {name} (str-compare)" | |
44 | - assert i.ports[no].name == aigr.ID(name), f"{i.name} (own/local) port no={no}: {i.ports[no].name}, expected: {name} (ID)" | |
45 | - |
@@ -0,0 +1,25 @@ | ||
1 | +# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | +"""Test the 'basic' (base) AIGR TestDoubles""" | |
3 | + | |
4 | +import pytest | |
5 | + | |
6 | +import castle.aigr as aigr | |
7 | +from castle.aigr.protocols import baseProtocol | |
8 | +from castle.TESTDOUBLES.aigr.base import base as base_NS | |
9 | + | |
10 | +def test_0_baseProtocol_exist(): | |
11 | + assert isinstance(baseProtocol, aigr.Protocol) | |
12 | + | |
13 | +def test_0_baseNS_exist(): | |
14 | + assert isinstance(base_NS, aigr.NameSpace) | |
15 | + | |
16 | + | |
17 | +def test_1_baseNS_has_Protocol(): | |
18 | + baseNS_protocol = base_NS.getID('Protocol') | |
19 | + assert isinstance(baseNS_protocol, aigr.Protocol) | |
20 | + | |
21 | +def test_1b_protocol_in_baseNS_is_baseProtocol(): | |
22 | + baseNS_protocol = base_NS.getID('Protocol') | |
23 | + assert baseNS_protocol is baseProtocol | |
24 | + | |
25 | + |
@@ -0,0 +1,33 @@ | ||
1 | +# (C) Albert Mietus, 2023,2024 Part of Castle/CCastle project | |
2 | +# verify/aux test-functions | |
3 | + | |
4 | +import castle.aigr as aigr | |
5 | +from castle.TESTDOUBLES.aigr.base import Protocol as base_Protocol | |
6 | + | |
7 | +def verify_Protocol(p, name, my_event_names, total_no_of_event=None, base=None, cls=None): | |
8 | + if base is None: | |
9 | + base=base_Protocol | |
10 | + no_events = total_no_of_event if total_no_of_event else len(my_event_names) | |
11 | + if cls is None: | |
12 | + cls = aigr.EventProtocol | |
13 | + | |
14 | + assert isinstance(p, cls) | |
15 | + assert str(p.name) == name, f"{p.name} reported but expected: {name}" | |
16 | + assert p.based_on is base | |
17 | + assert p._noEvents() == no_events, f"{p.name} reports {p._noEvents()} events, but expected: {no_events} event(s)" | |
18 | + for no, name in enumerate(my_event_names): | |
19 | + assert str(p.events[no].name) == name, f"{p.name} (own/local) event no={no}: {p.events[no].name}, expected: {name}" | |
20 | + | |
21 | + | |
22 | + | |
23 | +def verify_ComponentInterface(i, name, my_port_names=[], total_no_of_ports=None): | |
24 | + if total_no_of_ports is None: | |
25 | + total_no_of_ports = len(my_port_names) | |
26 | + | |
27 | + assert isinstance(i, aigr.ComponentInterface) | |
28 | + assert str(i.name) == name, f"{i.name} reported but expected: {name}" | |
29 | + | |
30 | + for no, name in enumerate(my_port_names): | |
31 | + assert str(i.ports[no].name) == name, f"{i.name} (own/local) port no={no}: {i.ports[no].name}, expected: {name} (str-compare)" | |
32 | + assert i.ports[no].name == aigr.ID(name), f"{i.name} (own/local) port no={no}: {i.ports[no].name}, expected: {name} (ID)" | |
33 | + |
@@ -0,0 +1,38 @@ | ||
1 | +# (C) Albert Mietus, 2024 Part of Castle/CCastle project | |
2 | +"""Test the AIGR TestDoubles of the BASIC1 Sieve protocols | |
3 | + documented in : | |
4 | + * .../TestDoubles_packages/TestDoubles-aigr-sieve/doc/basic1-import.puml | |
5 | + * http://docideas.mietus.nl/en/default/CCastle/4.Blog/b.TheSieve.html#the-design | |
6 | +""" | |
7 | +import logging; logger = logging.getLogger(__name__) | |
8 | +import pytest | |
9 | + | |
10 | +from castle import aigr | |
11 | +from castle.TESTDOUBLES.aigr.sieve.basic1 import protocols | |
12 | +from . import verify_Protocol | |
13 | + | |
14 | + | |
15 | +def test_0_all_sieveProtocols_exist(): | |
16 | + for p in (protocols.StartSieve, protocols.SlowStart, protocols.SimpleSieve): | |
17 | + assert isinstance(p, aigr.EventProtocol) | |
18 | + | |
19 | +def test_1_StartSieve(): | |
20 | + p = protocols.StartSieve | |
21 | + verify_Protocol(p, name="StartSieve", my_event_names=('runTo', 'newMax')) | |
22 | + | |
23 | +def test_1_SlowStart(): | |
24 | + p = protocols.SlowStart | |
25 | + verify_Protocol(p, name="SlowStart", my_event_names=['setMax']) | |
26 | + | |
27 | +def test_2_SlowStart_1(): | |
28 | + p = protocols.SlowStart_1 | |
29 | + verify_Protocol(p, name="SlowStart_1", cls=aigr.Specialise, base=protocols.SlowStart, my_event_names=['setMax']) | |
30 | + | |
31 | +def test_2_SimpleSieve(): | |
32 | + p = protocols.SimpleSieve | |
33 | + verify_Protocol(p, name="SimpleSieve", base=protocols.SlowStart_1, total_no_of_event=2, my_event_names=['input']) | |
34 | + | |
35 | + | |
36 | + | |
37 | +def test_99_update(): | |
38 | + assert False |
@@ -0,0 +1,58 @@ | ||
1 | +# (C) Albert Mietus, 2024 Part of Castle/CCastle project | |
2 | +"""Test the AIGR TestDoubles of the BASIC1 Sieve protocols | |
3 | + documented in : | |
4 | + * .../TestDoubles_packages/TestDoubles-aigr-sieve/doc/basic1-import.puml | |
5 | + * http://docideas.mietus.nl/en/default/CCastle/4.Blog/b.TheSieve.html#the-design | |
6 | +""" | |
7 | + | |
8 | +import logging; logger = logging.getLogger(__name__) | |
9 | +import pytest | |
10 | + | |
11 | +from castle.aigr import NameSpace | |
12 | +from castle import aigr | |
13 | +from castle.TESTDOUBLES.aigr.sieve.basic1 import namespaces | |
14 | + | |
15 | +moat_files = ('protocols', 'interfaces') | |
16 | +comp_files = ('generator', 'sieve', 'finder') | |
17 | + | |
18 | +def test_0_all_sieveProtocols_exist(): | |
19 | + for ns in (namespaces.interfaces, namespaces.protocols): | |
20 | + assert isinstance(ns, aigr.Source_NS) | |
21 | + for ns in (getattr(namespaces, name) for name in moat_files): # same loop as above! | |
22 | + assert isinstance(ns, aigr.Source_NS) | |
23 | + for ns in (namespaces.comps[name] for name in comp_files): | |
24 | + assert isinstance(ns, aigr.Source_NS) | |
25 | + assert isinstance(namespaces.main, aigr.Source_NS) | |
26 | + | |
27 | + | |
28 | + | |
29 | +def test_1_comps_imports_moats(): | |
30 | + for (comp_name, comp_ns) in ((name, namespaces.comps[name]) for name in comp_files): | |
31 | + logger.debug(f"comp_name={comp_name}, comp_ns={comp_ns}") | |
32 | + for moat_name in moat_files: | |
33 | + moat_node = comp_ns.findNode(moat_name) | |
34 | + logger.debug(f"moat_name={moat_name}, moat_node={moat_node}") | |
35 | + verify_nodeIsNS_withName(moat_node, moat_name) | |
36 | + | |
37 | +def test_2a_main_imports_moats(): | |
38 | + """ main imports <interfaces>, <protocols> and (see test_2b...)""" | |
39 | + for name in moat_files: | |
40 | + ns_node = namespaces.main.findNode(name) | |
41 | + verify_nodeIsNS_withName(ns_node, name) | |
42 | + | |
43 | +def test_2b_main_imports_implements_optionally(): | |
44 | + """(see test_2a...) and optionally the 3 components""" | |
45 | + log_prefix =f"namespaces._OPT_MAIN_IMPORTS_COMPS={namespaces._OPT_MAIN_IMPORTS_COMPS}..." | |
46 | + if namespaces._OPT_MAIN_IMPORTS_COMPS: | |
47 | + logger.info(log_prefix +f"check the comp_files ({comp_files})") | |
48 | + for name in comp_files: | |
49 | + ns_node = namespaces.main.findNode(name) | |
50 | + verify_nodeIsNS_withName(ns_node, name) | |
51 | + else: | |
52 | + logger.info(log_prefix +f"skip check on comp_files") | |
53 | + | |
54 | + | |
55 | + | |
56 | +def verify_nodeIsNS_withName(node, name:str): | |
57 | + assert isinstance(node, aigr.NameSpace) | |
58 | + assert node.name == name |
@@ -1,25 +0,0 @@ | ||
1 | -# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | -"""Test the 'basic' (base) AIGR TestDoubles""" | |
3 | - | |
4 | -import pytest | |
5 | - | |
6 | -import castle.aigr as aigr | |
7 | -from castle.aigr.protocols import baseProtocol | |
8 | -from castle.TESTDOUBLES.aigr.base import base as base_NS | |
9 | - | |
10 | -def test_0_baseProtocol_exist(): | |
11 | - assert isinstance(baseProtocol, aigr.Protocol) | |
12 | - | |
13 | -def test_o_baseNS_exist(): | |
14 | - assert isinstance(base_NS, aigr.NameSpace) | |
15 | - | |
16 | - | |
17 | -def test_1_baseNS_has_Protocol(): | |
18 | - baseNS_protocol = base_NS.getID('Protocol') | |
19 | - assert isinstance(baseNS_protocol, aigr.Protocol) | |
20 | - | |
21 | -def test_1b_protocol_in_baseNS_is_baseProtocol(): | |
22 | - baseNS_protocol = base_NS.getID('Protocol') | |
23 | - assert baseNS_protocol is baseProtocol | |
24 | - | |
25 | - |
@@ -1,38 +0,0 @@ | ||
1 | -# (C) Albert Mietus, 2023,2024 Part of Castle/CCastle project | |
2 | -"""Test the AIGR TestDoubles of the Sieve protocols | |
3 | - See: http://docideas.mietus.nl/en/default/CCastle/4.Blog/b.TheSieve.html#the-design | |
4 | -""" | |
5 | - | |
6 | -import pytest | |
7 | - | |
8 | -from castle import aigr | |
9 | -from castle.TESTDOUBLES.aigr.sieve import protocols | |
10 | -from . import verify_Protocol | |
11 | - | |
12 | - | |
13 | -def test_0_all_sieveProtocols_exist(): | |
14 | - for p in (protocols.StartSieve, protocols.SlowStart, protocols.SimpleSieve): | |
15 | - assert isinstance(p, aigr.EventProtocol) | |
16 | - | |
17 | - for p in (protocols.SlowStart_1,): | |
18 | - assert isinstance(p, aigr.Specialise) | |
19 | - assert isinstance(p.based_on, aigr.EventProtocol) | |
20 | - | |
21 | -def test_1_StartSieve(): | |
22 | - p = protocols.StartSieve | |
23 | - verify_Protocol(p, name="StartSieve", my_event_names=('runTo', 'newMax')) | |
24 | - | |
25 | -def test_1_SlowStart(): | |
26 | - p = protocols.SlowStart | |
27 | - verify_Protocol(p, name="SlowStart", my_event_names=['setMax']) | |
28 | - | |
29 | -def test_2_SlowStart_1(): | |
30 | - p = protocols.SlowStart_1 | |
31 | - verify_Protocol(p, name="SlowStart_1", cls=aigr.Specialise, base=protocols.SlowStart, my_event_names=['setMax']) | |
32 | - | |
33 | -def test_2_SimpleSieve(): | |
34 | - p = protocols.SimpleSieve | |
35 | - verify_Protocol(p, name="SimpleSieve", base=protocols.SlowStart_1, total_no_of_event=2, my_event_names=['input']) | |
36 | - | |
37 | - | |
38 | - |
@@ -1,38 +0,0 @@ | ||
1 | -# (C) Albert Mietus, 2023,2024 Part of Castle/CCastle project | |
2 | -"""Test the AIGR TestDoubles of the Sieve NameSpaces | |
3 | - See: http://docideas.mietus.nl/en/default/CCastle/4.Blog/b.TheSieve.html#the-design | |
4 | - See file:///Users/albert/work/DocIdeas,hg/__result/html/CCastle/HACK/DocParts/Design/231016_NS.html | |
5 | - (not published yet -- see .../DocParts/Design/231016_NS.rst for source)""" | |
6 | - | |
7 | -import logging; logger = logging.getLogger(__name__) | |
8 | -import pytest | |
9 | - | |
10 | -from castle.TESTDOUBLES.aigr.sieve import namespaces | |
11 | -from castle.TESTDOUBLES.aigr.base import base as base_ns | |
12 | - | |
13 | -from . import verify_NS | |
14 | - | |
15 | -def test_slow_start_has_SlowStart(): | |
16 | - ns = namespaces.slow_start | |
17 | - verify_NS(ns, "slow_start", ["SlowStart"]) | |
18 | - | |
19 | -def test_start_sieve_has_StartSieve(): | |
20 | - ns = namespaces.start_sieve | |
21 | - verify_NS(ns, "start_sieve", ["StartSieve"]) | |
22 | - | |
23 | -def test_simple_sieve_has_SimpleSieve_and_SpecialiseGeneric(): | |
24 | - ns = namespaces.simple_sieve | |
25 | - #verify_NS(ns, "simple_sieve", ["SlowStart_1", "SimpleSieve"]) | |
26 | - verify_NS(ns, "simple_sieve", ["SimpleSieve"]) | |
27 | - | |
28 | - | |
29 | -def test_top(): | |
30 | - ns = namespaces.top | |
31 | - verify_NS(ns, "top", as_name='TheSieve', registered_names=('start_sieve', 'slow_start', 'simple_sieve')) | |
32 | - verify_NS(ns, "top", as_name='TheSieve', registered_names=('base',)) | |
33 | - | |
34 | - | |
35 | -def test_all_NS_base_in_start_sieve(): | |
36 | - nss = namespaces.start_sieve.all_NS() | |
37 | - for n,ns in nss.items(): print(f'name={n}: {ns.name} // {ns}') | |
38 | - assert nss['base'] is base_ns |
@@ -33,6 +33,9 @@ | ||
33 | 33 | def register(self, named_node :NamedNode, asName:PTH.Optional[ID|str]=None): |
34 | 34 | name = ID(asName) if asName else PTH.cast(ID, named_node.name) |
35 | 35 | |
36 | + logger.debug(f"register: <{type(named_node).__name__}:{named_node.name}> in <{type(self).__name__}:{self.name}> as {name}") | |
37 | + | |
38 | + | |
36 | 39 | if name in self._dict: |
37 | 40 | old = self._dict[name] |
38 | 41 | logger.warning(f"The '{name}'-node is already in this namespace; -- it will be lost." + |