def no_simulator_updates(pvnames):
    '''Context manager which pauses and resumes simulator PV updating'''
    try:
        caput(pvnames.pause_pv, 1)
        time.sleep(0.1)
        yield
    finally:
        caput(pvnames.pause_pv, 0)
        # Give the simulator some time to start back up
        time.sleep(0.5)
    def initialize_data():
        subarray_driver.put(numpy.arange(64) / 12.0)

        for p in mbbos:
            p.put(1)

        for i, p in enumerate(longs):
            p.put((i + 1))

        for i, p in enumerate(strs):
            p.put(("String %s" % (i + 1)))

        for i, p in enumerate(binaries):
            p.put((i + 1))

        for i, p in enumerate(analogs):
            p.put((i + 1) * 1.7135000)

        caput(f'{prefix}ao1.EGU', 'microns')
        caput(f'{prefix}ao1.PREC', 4)
        caput(f'{prefix}ai1.PREC', 2)
        caput(f'{prefix}ao2.PREC', 3)

        char_waves[0].put([60 + random.randrange(30) for i in range(128)])
        char_waves[1].put([random.randrange(256) for i in range(256)])
        char_waves[2].put([random.randrange(256) for i in range(2048)])
        char_waves[3].put([random.randrange(256) for i in range(65536)])

        long_waves[0].put([i + random.randrange(2) for i in range(128)])
        long_waves[1].put([i + random.randrange(128) for i in range(2048)])
        long_waves[2].put([i for i in range(65536)])

        double_waves[0].put([i + random.randrange(2) for i in range(128)])
        double_waves[1].put([random.random() for i in range(2048)])
        double_waves[2].put([random.random() for i in range(65536)])

        pause_pv.put(0)
        str_waves[0].put([(" String %i" % (i + 1)) for i in range(128)])
        print('Data initialized')
def test_subarrays(pvnames):
    print("Subarray test:  dynamic length arrays\n")
    driver = PV(pvnames.subarr_driver)
    subarr1 = PV(pvnames.subarr1)
    subarr1.connect()

    len_full = 64
    len_sub1 = 16
    full_data = numpy.arange(len_full) / 1.0

    caput("%s.NELM" % pvnames.subarr1, len_sub1)
    caput("%s.INDX" % pvnames.subarr1, 0)

    driver.put(full_data)
    time.sleep(0.1)
    subval = subarr1.get()

    assert len(subval) == len_sub1
    assert numpy.all(subval == full_data[:len_sub1])
    print("Subarray test:  C\n")
    caput("%s.NELM" % pvnames.subarr2, 19)
    caput("%s.INDX" % pvnames.subarr2, 3)

    subarr2 = PV(pvnames.subarr2)
    subarr2.get()

    driver.put(full_data)
    time.sleep(0.1)
    subval = subarr2.get()

    assert len(subval) == 19
    assert numpy.all(subval == full_data[3:3 + 19])

    caput("%s.NELM" % pvnames.subarr2, 5)
    caput("%s.INDX" % pvnames.subarr2, 13)

    driver.put(full_data)
    time.sleep(0.1)
    subval = subarr2.get()

    assert len(subval) == 5
    assert numpy.all(subval == full_data[13:5 + 13])