Beispiel #1
0
    def test_flatten(self):
        inst1 = LaggyInstrument(resource='a')
        inst2 = LaggyInstrument(resource='b')

        with inst1, inst2:
            ret = lb.concurrently(d1=inst1.dict, d2=inst2.dict, flatten=True)
        self.assertIn('a', ret)
        self.assertIn('b', ret)
        self.assertEqual(ret['a'], 'a')
        self.assertEqual(ret['b'], 'b')

        with inst1, inst2:
            ret = lb.sequentially(d1=inst1.dict, d2=inst2.dict, flatten=True)
        self.assertIn('a', ret)
        self.assertIn('b', ret)
        self.assertEqual(ret['a'], 'a')
        self.assertEqual(ret['b'], 'b')

        with inst1, inst2:
            ret = lb.concurrently(d1=inst1.dict, d2=inst2.dict, flatten=False)
        self.assertIn('d1', ret)
        self.assertIn('d2', ret)
        self.assertEqual(ret['d1'], dict(a='a'))
        self.assertEqual(ret['d2'], dict(b='b'))

        with inst1, inst2:
            ret = lb.sequentially(d1=inst1.dict, d2=inst2.dict, flatten=False)
        self.assertIn('d1', ret)
        self.assertIn('d2', ret)
        self.assertEqual(ret['d1'], dict(a='a'))
        self.assertEqual(ret['d2'], dict(b='b'))
Beispiel #2
0
    def test_concurrent_fetch_delay(self):
        inst1 = LaggyInstrument(resource='fast', fetch_time=0.26)
        inst2 = LaggyInstrument(resource='slow', fetch_time=0.36)

        expect_delay = max(
            (inst1.settings.fetch_time, inst2.settings.fetch_time))
        with self.assert_delay(expect_delay):
            with inst1, inst2:
                self.assertEqual(inst1.state.connected, True)
                self.assertEqual(inst2.state.connected, True)
                lb.concurrently(fetch1=inst1.fetch, fetch2=inst2.fetch)
Beispiel #3
0
    def test_concurrent_nones(self):
        inst1 = LaggyInstrument(resource='a', fetch_time=0.16)
        inst2 = LaggyInstrument(resource='b', fetch_time=0.26)

        with inst1, inst2:
            ret = lb.concurrently(data1=inst1.none,
                                  data2=inst2.none,
                                  nones=False)
        self.assertEqual(ret, {})

        with inst1, inst2:
            ret = lb.concurrently(data1=inst1.none,
                                  data2=inst2.none,
                                  nones=True)
        self.assertIn('data1', ret)
        self.assertIn('data2', ret)
        self.assertEqual(ret['data1'], None)
        self.assertEqual(ret['data2'], None)
Beispiel #4
0
    def test_concurrent_connect_delay(self):
        inst1 = LaggyInstrument(resource='fast', delay=0.16)
        inst2 = LaggyInstrument(resource='slow', delay=0.26)

        expect_delay = max((inst1.settings.delay, inst2.settings.delay))
        with self.assert_delay(expect_delay):
            with lb.concurrently(inst1, inst2):
                self.assertEqual(inst1.state.connected, True)
                self.assertEqual(inst2.state.connected, True)
        self.assertEqual(inst1.state.connected, False)
        self.assertEqual(inst2.state.connected, False)
Beispiel #5
0
    def test_concurrent_fetch_as_args(self):
        inst1 = LaggyInstrument(resource='fast', fetch_time=.02)
        inst2 = LaggyInstrument(resource='slow', fetch_time=.03)

        with inst1, inst2:
            self.assertEqual(inst1.state.connected, True)
            self.assertEqual(inst2.state.connected, True)
            ret = lb.concurrently(fetch_0=inst1.fetch, fetch_1=inst2.fetch)
        self.assertIn('fetch_0', ret)
        self.assertIn('fetch_1', ret)
        self.assertEqual(ret['fetch_0'], inst1.settings.fetch_time)
        self.assertEqual(ret['fetch_1'], inst2.settings.fetch_time)
Beispiel #6
0
    def test_nested_fetch_delay(self):
        inst1 = LaggyInstrument(resource='a', fetch_time=0.16)
        inst2 = LaggyInstrument(resource='b', fetch_time=0.26)
        inst3 = LaggyInstrument(resource='c', fetch_time=0.37)

        expect_delay = inst1.settings.fetch_time+\
                       max((inst2.settings.fetch_time,inst3.settings.fetch_time))

        with self.assert_delay(expect_delay):
            with inst1, inst2, inst3:
                ret = lb.sequentially(
                    inst1.fetch,
                    lb.concurrently(sub_1=inst2.fetch, sub_2=inst3.fetch))
Beispiel #7
0
    def test_nested_connect_delay(self):
        inst1 = LaggyInstrument(resource='a', delay=0.16)
        inst2 = LaggyInstrument(resource='b', delay=0.26)
        inst3 = LaggyInstrument(resource='c', delay=0.37)

        expect_delay = inst1.settings.delay+\
                       max((inst2.settings.delay,inst3.settings.delay))

        with self.assert_delay(expect_delay):
            with lb.sequentially(inst1, lb.concurrently(inst2, inst3)):
                self.assertEqual(inst1.state.connected, True)
                self.assertEqual(inst2.state.connected, True)
                self.assertEqual(inst3.state.connected, True)
        self.assertEqual(inst1.state.connected, False)
        self.assertEqual(inst2.state.connected, False)
        self.assertEqual(inst3.state.connected, False)
Beispiel #8
0
    def test_concurrent_fetch_as_kws(self):
        inst1 = LaggyInstrument(resource='fast')
        inst2 = LaggyInstrument(resource='slow')

        with inst1, inst2:
            self.assertEqual(inst1.state.connected, True)
            self.assertEqual(inst2.state.connected, True)
            ret = lb.concurrently(
                **{
                    inst1.settings.resource: inst1.fetch,
                    inst2.settings.resource: inst2.fetch
                })
        self.assertIn(inst1.settings.resource, ret)
        self.assertIn(inst2.settings.resource, ret)
        self.assertEqual(ret[inst1.settings.resource],
                         inst1.settings.fetch_time)
        self.assertEqual(ret[inst2.settings.resource],
                         inst2.settings.fetch_time)