Exemplo n.º 1
0
    def test_then_construction(self):
        loop = Loop(self.p1[1:6:1])
        task1 = Task(self.p1.set, 2)
        task2 = Wait(0.02)
        loop2 = loop.then(task1)
        loop3 = loop2.then(task2, task1)
        loop4 = loop3.then(task2, overwrite=True)
        loop5 = loop4.each(self.p1, BreakIf(lambda: self.p1.get() >= 3))
        loop6 = loop5.then(task1)
        loop7 = loop6.then(task1, overwrite=True)

        # original loop is untouched, same as .each and .loop
        self.assertEqual(loop.then_actions, ())

        # but loop2 has the task we asked for
        self.assertEqual(loop2.then_actions, (task1, ))

        # loop3 gets the other tasks appended
        self.assertEqual(loop3.then_actions, (task1, task2, task1))

        # loop4 gets only the new one
        self.assertEqual(loop4.then_actions, (task2, ))

        # tasks survive .each
        self.assertEqual(loop5.then_actions, (task2, ))

        # and ActiveLoop.then works the same way as Loop.then
        self.assertEqual(loop6.then_actions, (task2, task1))
        self.assertEqual(loop7.then_actions, (task1, ))

        # .then rejects Loops and others that are valid loop actions
        for action in (loop2, loop7, BreakIf(lambda: self.p1() >= 3), self.p1,
                       True, 42):
            with self.assertRaises(TypeError):
                loop.then(action)
Exemplo n.º 2
0
    def test_basic(self):
        p1 = AbortingGetter('p1', count=2, vals=Numbers(-10, 10), set_cmd=None)
        sv = p1[1:3:1]
        loop = Loop(sv)

        # not sure why you'd do it, but you *can* snapshot a Loop
        expected = {
            '__class__': 'qcodes.loops.Loop',
            'sweep_values': sv.snapshot(),
            'delay': 0,
            'then_actions': []
        }
        self.assertEqual(loop.snapshot(), expected)
        loop = loop.then(Task(p1.set, 0), Wait(0.123))
        expected['then_actions'] = [{
            'type': 'Task',
            'func': repr(p1.set)
        }, {
            'type': 'Wait',
            'delay': 0.123
        }]

        # then test snapshot on an ActiveLoop
        breaker = BreakIf(lambda: p1.get_latest() > 3)
        self.assertEqual(breaker.snapshot()['type'], 'BreakIf')
        loop = loop.each(p1, breaker)
        expected['__class__'] = 'qcodes.loops.ActiveLoop'
        expected['actions'] = [p1.snapshot(), breaker.snapshot()]

        self.assertEqual(loop.snapshot(), expected)
Exemplo n.º 3
0
    def test_basic(self):
        p1 = AbortingGetter('p1', count=2, vals=Numbers(-10, 10))
        sv = p1[1:3:1]
        loop = Loop(sv)

        # not sure why you'd do it, but you *can* snapshot a Loop
        expected = {
            '__class__': 'qcodes.loops.Loop',
            'sweep_values': sv.snapshot(),
            'delay': 0,
            'then_actions': []
        }
        self.assertEqual(loop.snapshot(), expected)
        loop = loop.then(Task(p1.set, 0), Wait(0.123))
        expected['then_actions'] = [{
            'type': 'Task',
            'func': repr(p1.set)
        }, {
            'type': 'Wait',
            'delay': 0.123
        }]

        # then test snapshot on an ActiveLoop
        breaker = BreakIf(p1.get_latest > 3)
        self.assertEqual(breaker.snapshot()['type'], 'BreakIf')
        # TODO: once we have reprs for DeferredOperations, test that
        # the right thing shows up in breaker.snapshot()['condition']
        loop = loop.each(p1, breaker)
        expected['__class__'] = 'qcodes.loops.ActiveLoop'
        expected['actions'] = [p1.snapshot(), breaker.snapshot()]

        self.assertEqual(loop.snapshot(), expected)