def test_capture_mp_get(): vision = VisionSubclass(0) processor = ProcessorA(vision) with MultiProcessing(processor) as mp: assert (mp.remote_get('test_remote_get') == 'success') assert (mp.test_remote_get == 'success') vision.test_remote_get = 'changing current process which will not change remote process' assert (mp.test_remote_get == 'success')
def test_processor_properties(): vision = VisionSubclass("Test") processorA = ProcessorA(vision) processorB = ProcessorB(processorA) with processorB as s: assert(s.autoexposure is None) assert(s.autofocus is None) assert(s.autowhitebalance is None) assert(s.autogain is None) assert(s.exposure is None) assert(s.focus is None) assert(s.whitebalance is None) s.autoexposure = 1 s.autofocus = 2 s.autowhitebalance = 3 s.autogain = 4 s.exposure = 5 s.focus = 6 s.whitebalance = 7 assert(vision.autoexposure == 1) assert(vision.autofocus == 2) assert(vision.autowhitebalance == 3) assert(vision.autogain == 4) assert(vision.exposure == 5) assert(vision.focus == 6) assert(vision.whitebalance == 7)
def test_abstract_vision_implementation_properties(): with VisionSubclass() as s: assert (s.autoexposure is None) assert (s.autofocus is None) assert (s.autowhitebalance is None) assert (s.autogain is None) assert (s.exposure is None) assert (s.focus is None) assert (s.whitebalance is None) s.autoexposure = 1 s.autofocus = 2 s.autowhitebalance = 3 s.autogain = 4 s.exposure = 5 s.focus = 6 s.whitebalance = 7 assert (s.autoexposure == 1) assert (s.autofocus == 2) assert (s.autowhitebalance == 3) assert (s.autogain == 4) assert (s.exposure == 5) assert (s.focus == 6) assert (s.whitebalance == 7)
def test_mp_properties(): vision = VisionSubclass("Test") with MultiProcessing(vision, freerun=False) as s: assert (s.autoexposure is None) assert (s.autofocus is None) assert (s.autowhitebalance is None) assert (s.autogain is None) assert (s.exposure is None) assert (s.focus is None) assert (s.whitebalance is None) s.autoexposure = 1 s.autofocus = 2 s.autowhitebalance = 3 s.autogain = 4 s.exposure = 5 s.focus = 6 s.whitebalance = 7 assert (s.autoexposure == 1) assert (s.autofocus == 2) assert (s.autowhitebalance == 3) assert (s.autogain == 4) assert (s.exposure == 5) assert (s.focus == 6) assert (s.whitebalance == 7) assert (vision.autoexposure is None) assert (vision.autofocus is None) assert (vision.autowhitebalance is None) assert (vision.autogain is None) assert (vision.exposure is None) assert (vision.focus is None) assert (vision.whitebalance is None)
def test_mc_properties(): vision = VisionSubclass("Test") with MultiConsumers(vision) as s: assert (s.autoexposure is None) assert (s.autofocus is None) assert (s.autowhitebalance is None) assert (s.autogain is None) assert (s.exposure is None) assert (s.focus is None) assert (s.whitebalance is None) s.autoexposure = 1 s.autofocus = 2 s.autowhitebalance = 3 s.autogain = 4 s.exposure = 5 s.focus = 6 s.whitebalance = 7 assert (s.autoexposure == 1) assert (s.autofocus == 2) assert (s.autowhitebalance == 3) assert (s.autogain == 4) assert (s.exposure == 5) assert (s.focus == 6) assert (s.whitebalance == 7)
def test_capture_disabled(): vision = VisionSubclass(0) with ProcessorA(vision, enabled=False) as processor: img = processor.capture() assert(isinstance(img, Frame)) assert(img.images[0].source is vision) assert(img.images[0].image == "an image")
def test_capture(): vision = VisionSubclass(0) with ProcessorA(vision) as processor: img = processor.capture() assert(isinstance(img, Frame)) assert(img.images[0].source is processor) assert(img.images[0].image == "AN IMAGE")
def test_capture_stacked_incorrect(): vision = VisionSubclass("Test") processorA = ProcessorA(vision) processorB = ProcessorB(processorA) assert(processorB.name == "ProcessorB <- ProcessorA <- Test") with raises(AssertionError): processorB.capture()
def test_capture_mask_processor_override(): vision = VisionSubclass(0, num_images=2, processor_mask="10") with ProcessorA(vision, processor_mask="01") as processor: img = processor.capture() assert(isinstance(img, Frame)) assert(img.images[0].source is vision) assert(img.images[0].image == "an image") assert(img.images[1].source is processor) assert(img.images[1].image == "AN IMAGE1")
def test_capture_mp_lazy(): vision = VisionSubclass(0) processor = ProcessorA(vision) with MultiProcessing(processor, freerun=False) as mp: for index, img in enumerate(mp): assert (isinstance(img, Frame)) assert (img.index == index) assert (img.images[0].image == "AN IMAGE") if img.index > 10: break
def test_frame_get_image(): sourceA = VisionSubclass("A") sourceB = VisionSubclass("B") sourceC = VisionSubclass("C") imgA = Image(sourceA, "some image") imgB = Image(sourceB, "some other image") frame = Frame(datetime.now(), 0, (imgA, imgB)) assert (frame.get_image("A") == imgA) assert (frame.get_image("B") == imgB) assert (frame.get_image("C") is None) assert (frame.get_image(sourceA) == imgA) assert (frame.get_image(sourceB) == imgB) assert (frame.get_image(sourceC) is None) with raises(TypeError): frame.get_image(1)
def test_capture_mp_freerun(): vision = VisionSubclass(0) processor = ProcessorA(vision) with MultiProcessing(processor) as mp: for index, img in enumerate(mp): assert (isinstance(img, Frame)) assert (img.images[0].image == "AN IMAGE") sleep(.01) if index > 10: assert (img.index > index) break
def test_capture_mp_call(): vision = VisionSubclass(0) processor = ProcessorA(vision) with MultiProcessing(processor) as mp: assert (mp.remote_call('test_remote_call', 2, 5, kwarg_test=7) == ('success', 2, 5, 7)) vision.test_remote_get = 1 vision.test_remote_get = 3 assert (mp.remote_call('test_remote_call', 2, 5, kwarg_test=7) == ('success', 2, 5, 7)) assert (mp.test_remote_call(2, 5, kwarg_test=7) == ('success', 2, 5, 7)) mp.remote_set('test_remote_get', 2) assert (mp.remote_get('test_remote_get') == 2) assert (mp.remote_call('test_remote_call', 2, 5, kwarg_test=7) == (2, 2, 5, 7)) assert (mp.test_remote_call(2, 5, kwarg_test=7) == (2, 2, 5, 7)) assert (mp.test_payload1(Payload(2, 1)).a == 3) assert (mp.test_payload2(Payload(2, 1)).image == 3) assert (mp.process(Image(None, 'testing')).image == 'TESTING')
def test_method_resolution(): vision = VisionSubclass("Test") processorA = ProcessorA(vision) processorB = ProcessorB(processorA) assert(processorB.name == "ProcessorB <- ProcessorA <- Test") assert(not vision.camera_called) assert(processorB.camera_()) assert(processorB._camera_called) assert(vision._camera_called)
def test_capture_multiconsumers(): vision = VisionSubclass(0) processor = MultiConsumers(vision) with processor as p1: with processor as p2: for img1, img2 in zip(p1, p2): assert (isinstance(img1, Frame)) assert (isinstance(img2, Frame)) assert (img1 == img2) if img1.index > 10: break
def test_capture_multiconsumers_fail(): vision = VisionSubclass(0) processor = MultiConsumers(vision) processor.setup() processor.setup() processor.release() processor.release() with raises(AssertionError): processor.release()
def test_capture_mp_set(): vision = VisionSubclass(0) processor = ProcessorA(vision) with MultiProcessing(processor) as mp: mp.remote_set('test_remote_get', 1) assert (mp.remote_get('test_remote_get') == 1) assert (mp.test_remote_get == 1) assert (vision.test_remote_get == 'success') mp.remote_set('_some_field', 1) assert (mp._some_field == 1) assert (processor._some_field == 0) processor._some_field = 3 assert (mp._some_field == 1) assert (processor._some_field == 3)
def test_capture_mp_noattr(): vision = VisionSubclass(0) processor = ProcessorA(vision) with MultiProcessing(processor) as mp: with raises(AttributeError): mp.remote_call('test_remote_exception_no_such_attr', 2, 5, kwarg_test=7) with raises(AttributeError): _ = mp.test_remote_exception_no_such_attr with raises(AttributeError): _ = mp.remote_get('test_remote_exception_no_such_attr') with raises(AttributeError): _ = mp.remote_set('test_remote_exception_no_such_attr', 0)
def test_capture_stacked(): vision = VisionSubclass("Test") processorA = ProcessorA(vision) processorB = ProcessorB(processorA) assert(processorB.name == "ProcessorB <- ProcessorA <- Test") with processorB as processor: img = processor.capture() assert(isinstance(img, Frame)) assert(img.images[0].source is processorB) assert(img.images[0].image == "An Image") assert(processorB.get_source('VisionSubclass') is vision) assert(processorB.get_source('ProcessorA') is processorA) assert(processorB.get_source('ProcessorB') is processorB) assert(processorB.get_source('Test no') is None)
def test_image_replace(): img = Image(VisionSubclass(), "Some frame") img1 = img._replace(image="Some other frame") assert (isinstance(img1.source, VisionSubclass)) assert (img1.image == "Some other frame")
def test_image_make(): img = Image._make([VisionSubclass(), "Some frame"]) assert (isinstance(img.source, VisionSubclass)) assert (img.image == "Some frame")
def test_abstract_vision_implementation_setup(): s = VisionSubclass() s.setup() for _ in s: break s.release()
def test_abstract_vision_implementation_context(): s = VisionSubclass() with s as ss: for _ in ss: break
def test_abstract_vision_implementation(): VisionSubclass()
def test_capture_mp_call_exception(): vision = VisionSubclass(0) processor = ProcessorA(vision) with MultiProcessing(processor) as mp: with raises(MyException): mp.remote_call('test_remote_exception', 2, 5, kwarg_test=7)
def test_frame_fail_index(): with raises(TypeError): Frame(datetime.now(), "", (Image(VisionSubclass(), "some frame"), ))
def test_frame_fail_timestamp(): with raises(TypeError): Frame("", 0, (Image(VisionSubclass(), "some frame"), ))
def test_frame(): frame = Frame(datetime.now(), 0, (Image(VisionSubclass(), "some frame"), )) assert (isinstance(frame.timestamp, datetime)) assert (frame.index == 0) assert (len(frame.images) == 1) assert (isinstance(frame.images[0], Image))
def test_abstract_vision_implementation_nosetup(): s = VisionSubclass() with raises(AssertionError): for _ in s: break
def test_capture_mp_set_getter(): vision = VisionSubclass(0) processor = ProcessorA(vision) with MultiProcessing(processor) as mp: with raises(AttributeError): mp.remote_set('test_remote_getter_only', 0)