def test_build_from_config2(template_sequence, template_dependencies): """ Test rebuilding a sequence including a template sequence. Channel mapping of template_vars values are known. """ conf = {'template_id': 'test', 'name': 'Template', 'template_vars': "{'b': '25'}"} seq = TemplateSequence.build_from_config(conf, template_dependencies) seq.context.channel_mapping = {'A': 'Ch1_L', 'B': 'Ch2_L', 'Ch1': 'Ch2_A', 'Ch2': 'Ch1_A'} root = RootSequence() context = TestContext(sampling=0.5) root.context = context root.add_child_item(0, seq) pref = root.preferences_from_members() new = RootSequence.build_from_config(pref, template_dependencies) assert new.items[0].index == 1 seq = new.items[0] assert seq.name == 'Template' assert seq.template_id == template_sequence assert seq.template_vars == dict(b='25') assert seq.local_vars == dict(a='1.5') assert len(seq.items) == 4 assert seq.items[3].index == 5 assert seq.docs == 'Basic user comment\nff' context = seq.context assert context.template is seq assert context.logical_channels == ['A', 'B'] assert context.analogical_channels == ['Ch1', 'Ch2'] assert context.channel_mapping == {'A': 'Ch1_L', 'B': 'Ch2_L', 'Ch1': 'Ch2_A', 'Ch2': 'Ch1_A'}
def template_sequence(pulses_plugin): """Create a template sequence and make sure the plugin pick it up. """ from ecpy_pulses.pulses.pulse import Pulse from ecpy_pulses.pulses.sequences.base_sequences import (RootSequence, BaseSequence) from ecpy_pulses.pulses.shapes.square_shape import SquareShape from ecpy_pulses.pulses.contexts.template_context import TemplateContext root = RootSequence() context = TemplateContext(logical_channels=['A', 'B'], analogical_channels=['Ch1', 'Ch2'], channel_mapping={ 'A': '', 'B': '', 'Ch1': '', 'Ch2': '' }) root.context = context root.local_vars = OrderedDict({'a': '1.5'}) pulse1 = Pulse(channel='A', def_1='1.0', def_2='{a}') pulse2 = Pulse(channel='B', def_1='{a} + 1.0', def_2='3.0') pulse3 = Pulse(channel='Ch1', def_1='{2_stop} + 0.5', def_2='{b}', kind='Analogical', shape=SquareShape()) seq = BaseSequence() seq.add_child_item( 0, Pulse(channel='Ch2', def_1='{2_stop} + 0.5', def_2='{sequence_end}', kind='Analogical', shape=SquareShape())) for i in [pulse1, pulse2, seq, pulse3][::-1]: root.add_child_item(0, i) pref = root.preferences_from_members() pref['template_vars'] = repr(dict(b='')) del pref['item_id'] del pref['external_vars'] del pref['time_constrained'] temp_path = os.path.join(pulses_plugin.templates_folders[0], '__dummy__.temp_pulse.ini') save_sequence_prefs(temp_path, pref, 'dummy doc') pulses_plugin._refresh_known_template_sequences() return '__dummy__'
def test_build_from_config(): """Test building a pulse sequence. """ root = RootSequence() context = TestContext() root.context = context root.external_vars = {'a': 1.5} pulse1 = Pulse(def_1='1.0', def_2='{a}') pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0') pulse3 = Pulse(def_1='{2_stop} + 0.5', def_2='10', kind='Analogical', shape=SquareShape()) pulse4 = Pulse(def_1='{2_stop} + 0.5', def_2='10', kind='Analogical', shape=SquareShape()) seq = BaseSequence() add_children(root, [pulse1, pulse2, pulse3, seq]) add_children(seq, [pulse4]) pref = root.preferences_from_members() dependecies = {'ecpy.pulses.items': {'ecpy_pulses.BaseSequence': BaseSequence, 'ecpy_pulses.Pulse': Pulse}, 'ecpy.pulses.shapes': {'ecpy_pulses.SquareShape': SquareShape}, 'ecpy.pulses.contexts': {'ecpy_pulses.TestContext': TestContext}} aux = RootSequence.build_from_config(pref, dependecies) assert aux.external_vars == {'a': 1.5} assert len(aux.items) == 4 assert isinstance(aux.context, TestContext) pulse1 = aux.items[0] assert pulse1.def_1 == '1.0' assert pulse1.def_2 == '{a}' pulse2 = aux.items[1] assert pulse2.def_1 == '{a} + 1.0' assert pulse2.def_2 == '3.0' pulse3 = aux.items[2] assert pulse3.def_1 == '{2_stop} + 0.5' assert pulse3.def_2 == '10' assert pulse3.kind == 'Analogical' assert isinstance(pulse3.shape, SquareShape) seq = aux.items[3] assert len(seq.items) == 1
def test_build_from_config2(template_sequence, template_dependencies): """ Test rebuilding a sequence including a template sequence. Channel mapping of template_vars values are known. """ conf = { 'template_id': 'test', 'name': 'Template', 'template_vars': "{'b': '25'}" } seq = TemplateSequence.build_from_config(conf, template_dependencies) seq.context.channel_mapping = { 'A': 'Ch1_L', 'B': 'Ch2_L', 'Ch1': 'Ch2_A', 'Ch2': 'Ch1_A' } root = RootSequence() context = TestContext(sampling=0.5) root.context = context root.add_child_item(0, seq) pref = root.preferences_from_members() new = RootSequence.build_from_config(pref, template_dependencies) assert new.items[0].index == 1 seq = new.items[0] assert seq.name == 'Template' assert seq.template_id == template_sequence assert seq.template_vars == dict(b='25') assert seq.local_vars == dict(a='1.5') assert len(seq.items) == 4 assert seq.items[3].index == 5 assert seq.docs == 'Basic user comment\nff' context = seq.context assert context.template is seq assert context.logical_channels == ['A', 'B'] assert context.analogical_channels == ['Ch1', 'Ch2'] assert context.channel_mapping == { 'A': 'Ch1_L', 'B': 'Ch2_L', 'Ch1': 'Ch2_A', 'Ch2': 'Ch1_A' }
def template_sequence(pulses_plugin): """Create a template sequence and make sure the plugin pick it up. """ from ecpy_pulses.pulses.pulse import Pulse from ecpy_pulses.pulses.sequences.base_sequences import RootSequence, BaseSequence from ecpy_pulses.pulses.shapes.square_shape import SquareShape from ecpy_pulses.pulses.contexts.template_context import TemplateContext root = RootSequence() context = TemplateContext( logical_channels=["A", "B"], analogical_channels=["Ch1", "Ch2"], channel_mapping={"A": "", "B": "", "Ch1": "", "Ch2": ""}, ) root.context = context root.local_vars = {"a": "1.5"} pulse1 = Pulse(channel="A", def_1="1.0", def_2="{a}") pulse2 = Pulse(channel="B", def_1="{a} + 1.0", def_2="3.0") pulse3 = Pulse(channel="Ch1", def_1="{2_stop} + 0.5", def_2="{b}", kind="Analogical", shape=SquareShape()) seq = BaseSequence() seq.add_child_item( 0, Pulse(channel="Ch2", def_1="{2_stop} + 0.5", def_2="{sequence_end}", kind="Analogical", shape=SquareShape()) ) for i in [pulse1, pulse2, seq, pulse3][::-1]: root.add_child_item(0, i) pref = root.preferences_from_members() pref["template_vars"] = repr(dict(b="")) del pref["item_id"] del pref["external_vars"] del pref["time_constrained"] temp_path = os.path.join(pulses_plugin.templates_folders[0], "__dummy__.temp_pulse.ini") save_sequence_prefs(temp_path, pref, "dummy doc") pulses_plugin._refresh_known_template_sequences() return "__dummy__"
def test_build_from_config(): """Test building a pulse sequence. """ root = RootSequence() context = TestContext() root.context = context root.external_vars = OrderedDict({'a': 1.5}) pulse1 = Pulse(def_1='1.0', def_2='{a}') pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0') pulse3 = Pulse(def_1='{2_stop} + 0.5', def_2='10', kind='Analogical', shape=SquareShape()) pulse4 = Pulse(def_1='{2_stop} + 0.5', def_2='10', kind='Analogical', shape=SquareShape()) seq = BaseSequence() add_children(root, [pulse1, pulse2, pulse3, seq]) add_children(seq, [pulse4]) pref = root.preferences_from_members() dependecies = { 'ecpy.pulses.item': { 'ecpy_pulses.BaseSequence': BaseSequence, 'ecpy_pulses.Pulse': Pulse }, 'ecpy.pulses.shape': { 'ecpy_pulses.SquareShape': SquareShape }, 'ecpy.pulses.context': { 'ecpy_pulses.TestContext': TestContext } } aux = RootSequence.build_from_config(pref, dependecies) assert aux.external_vars == {'a': 1.5} assert len(aux.items) == 4 assert isinstance(aux.context, TestContext) pulse1 = aux.items[0] assert pulse1.parent assert pulse1.def_1 == '1.0' assert pulse1.def_2 == '{a}' pulse2 = aux.items[1] assert pulse2.parent assert pulse2.def_1 == '{a} + 1.0' assert pulse2.def_2 == '3.0' pulse3 = aux.items[2] assert pulse3.parent assert pulse3.def_1 == '{2_stop} + 0.5' assert pulse3.def_2 == '10' assert pulse3.kind == 'Analogical' assert isinstance(pulse3.shape, SquareShape) seq = aux.items[3] assert seq.parent assert len(seq.items) == 1