From b8f4c6b9bb8ce4f2d7dc50e87690ad336841357c Mon Sep 17 00:00:00 2001 From: Leon Riesebos Date: Sat, 27 Feb 2021 16:22:32 -0500 Subject: [PATCH] added test case for get_experiment() with nested class Signed-off-by: Leon Riesebos --- artiq/test/test_tools.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/artiq/test/test_tools.py b/artiq/test/test_tools.py index 0e6455c20..0c24dd29e 100644 --- a/artiq/test/test_tools.py +++ b/artiq/test/test_tools.py @@ -116,3 +116,26 @@ class Exp1(EnvExperiment): # by elimination self.assertIs(mod.Exp1, tools.get_experiment(mod)) + + def test_nested_experiment(self): + with create_modules(MODNAME) as mods: + with mods[MODNAME].open("a") as fp: + print( + """ +from artiq.experiment import * + +class Foo: + class Exp1(EnvExperiment): + pass + """, + file=fp, + ) + + mod = tools.file_import(str(mods[MODNAME])) + + # by class name + self.assertIs(mod.Foo.Exp1, tools.get_experiment(mod, "Foo.Exp1")) + + # by elimination should fail + with self.assertRaises(ValueError): + tools.get_experiment(mod)