forked from M-Labs/nac3
[artiq] add tests for module support
This commit is contained in:
parent
14e80dfab7
commit
879b063968
29
nac3artiq/demo/module_support.py
Normal file
29
nac3artiq/demo/module_support.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from min_artiq import *
|
||||||
|
import tests.string_attribute_issue337 as issue337
|
||||||
|
import tests.support_class_attr_issue102 as issue102
|
||||||
|
import tests.global_variables as global_variables
|
||||||
|
|
||||||
|
@nac3
|
||||||
|
class TestModuleSupport:
|
||||||
|
core: KernelInvariant[Core]
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.core = Core()
|
||||||
|
|
||||||
|
@kernel
|
||||||
|
def run(self):
|
||||||
|
# Accessing classes
|
||||||
|
issue337.Demo().run()
|
||||||
|
obj = issue102.Demo()
|
||||||
|
obj.attr3 = 3
|
||||||
|
|
||||||
|
# Calling functions
|
||||||
|
global_variables.inc_X()
|
||||||
|
global_variables.display_X()
|
||||||
|
|
||||||
|
# Updating global variables
|
||||||
|
global_variables.X = 9
|
||||||
|
global_variables.display_X()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
TestModuleSupport().run()
|
14
nac3artiq/demo/tests/global_variables.py
Normal file
14
nac3artiq/demo/tests/global_variables.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from min_artiq import *
|
||||||
|
from numpy import int32
|
||||||
|
|
||||||
|
X: Kernel[int32] = 1
|
||||||
|
|
||||||
|
@rpc
|
||||||
|
def display_X():
|
||||||
|
print_int32(X)
|
||||||
|
|
||||||
|
@kernel
|
||||||
|
def inc_X():
|
||||||
|
global X
|
||||||
|
X += 1
|
||||||
|
|
@ -1,16 +1,13 @@
|
|||||||
from min_artiq import *
|
from min_artiq import *
|
||||||
from numpy import int32
|
from numpy import int32
|
||||||
|
|
||||||
|
|
||||||
@nac3
|
@nac3
|
||||||
class Demo:
|
class Demo:
|
||||||
core: KernelInvariant[Core]
|
attr1: Kernel[str]
|
||||||
attr1: KernelInvariant[str]
|
attr2: Kernel[int32]
|
||||||
attr2: KernelInvariant[int32]
|
|
||||||
|
|
||||||
|
|
||||||
|
@kernel
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.core = Core()
|
|
||||||
self.attr2 = 32
|
self.attr2 = 32
|
||||||
self.attr1 = "SAMPLE"
|
self.attr1 = "SAMPLE"
|
||||||
|
|
||||||
@ -19,6 +16,3 @@ class Demo:
|
|||||||
print_int32(self.attr2)
|
print_int32(self.attr2)
|
||||||
self.attr1
|
self.attr1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
Demo().run()
|
|
@ -1,7 +1,6 @@
|
|||||||
from min_artiq import *
|
from min_artiq import *
|
||||||
from numpy import int32
|
from numpy import int32
|
||||||
|
|
||||||
|
|
||||||
@nac3
|
@nac3
|
||||||
class Demo:
|
class Demo:
|
||||||
attr1: KernelInvariant[int32] = 2
|
attr1: KernelInvariant[int32] = 2
|
||||||
@ -12,7 +11,6 @@ class Demo:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.attr3 = 8
|
self.attr3 = 8
|
||||||
|
|
||||||
|
|
||||||
@nac3
|
@nac3
|
||||||
class NAC3Devices:
|
class NAC3Devices:
|
||||||
core: KernelInvariant[Core]
|
core: KernelInvariant[Core]
|
||||||
@ -35,6 +33,5 @@ class NAC3Devices:
|
|||||||
|
|
||||||
NAC3Devices.attr4 # Attributes accessible for classes without __init__
|
NAC3Devices.attr4 # Attributes accessible for classes without __init__
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
NAC3Devices().run()
|
NAC3Devices().run()
|
Loading…
Reference in New Issue
Block a user