File tree 2 files changed +52
-7
lines changed
2 files changed +52
-7
lines changed Original file line number Diff line number Diff line change
1
+ from artiq .language import *
2
+ from artiq .test .hardware_testbench import ExperimentCase
3
+
4
+ class Roundtrip (EnvExperiment ):
5
+ def build (self ):
6
+ self .attr_device ("core" )
7
+
8
+ @kernel
9
+ def roundtrip (self , obj , fn ):
10
+ fn (obj )
11
+
12
+ class RoundtripTest (ExperimentCase ):
13
+ def assertRoundtrip (self , obj ):
14
+ exp = self .create (Roundtrip )
15
+ def callback (objcopy ) -> TNone :
16
+ self .assertEqual (obj , objcopy )
17
+ exp .roundtrip (obj , callback )
18
+
19
+ def test_None (self ):
20
+ self .assertRoundtrip (None )
21
+
22
+ def test_bool (self ):
23
+ self .assertRoundtrip (True )
24
+ self .assertRoundtrip (False )
25
+
26
+ def test_int (self ):
27
+ self .assertRoundtrip (42 )
28
+ self .assertRoundtrip (int (42 , width = 64 ))
29
+
30
+ def test_float (self ):
31
+ self .assertRoundtrip (42.0 )
32
+
33
+ def test_str (self ):
34
+ self .assertRoundtrip ("foo" )
35
+
36
+ def test_list (self ):
37
+ self .assertRoundtrip ([10 ])
38
+
39
+ def test_object (self ):
40
+ obj = object ()
41
+ self .assertRoundtrip (obj )
Original file line number Diff line number Diff line change @@ -37,20 +37,24 @@ def setUp(self):
37
37
self .pdb = FlatFileDB (os .path .join (artiq_root , "pdb.pyon" ))
38
38
self .rdb = ResultDB ()
39
39
40
- def execute (self , cls , ** kwargs ):
40
+ def create (self , cls , ** kwargs ):
41
+ try :
42
+ exp = cls (self .dmgr , self .pdb , self .rdb , ** kwargs )
43
+ exp .prepare ()
44
+ return exp
45
+ except KeyError as e :
46
+ # skip if ddb does not match requirements
47
+ raise unittest .SkipTest (* e .args )
48
+
49
+ def execute (self , cls , * args , ** kwargs ):
41
50
expid = {
42
51
"file" : sys .modules [cls .__module__ ].__file__ ,
43
52
"class_name" : cls .__name__ ,
44
53
"arguments" : kwargs
45
54
}
46
55
self .dmgr .virtual_devices ["scheduler" ].expid = expid
47
56
try :
48
- try :
49
- exp = cls (self .dmgr , self .pdb , self .rdb , ** kwargs )
50
- except KeyError as e :
51
- # skip if ddb does not match requirements
52
- raise unittest .SkipTest (* e .args )
53
- exp .prepare ()
57
+ exp = self .create (cls , ** kwargs )
54
58
exp .run ()
55
59
exp .analyze ()
56
60
return exp
You can’t perform that action at this time.
0 commit comments