示例#1
0
    def test_traversable_tutorial(self):
        # Create a Harvester object:
        self.harvester = Harvester()

        # The following block is just for administrative purpose;
        # you should not include it in your code:
        cti_file_path = get_cti_file_path()
        if 'TLSimu.cti' not in cti_file_path:
            return

        # Add a CTI file path:
        self.harvester.add_cti_file(cti_file_path)
        self.harvester.update_device_info_list()

        # Connect to the first camera in the list:
        self.ia = self.harvester.create_image_acquirer(0)

        #
        num_images_to_acquire = 0

        # Then start image acquisition:
        self.ia.start_image_acquisition()

        while num_images_to_acquire < 100:
            #
            with self.ia.fetch_buffer() as buffer:
                # self.do_something(buffer)
                pass

            num_images_to_acquire += 1

        # We don't need the ImageAcquirer object. Destroy it:
        self.ia.destroy()
示例#2
0
    def test_traversable_tutorial(self):
        # Create a Harvester object:
        self.harvester = Harvester()
        
        # Add a CTI file path:
        self.harvester.add_cti_file(
            get_cti_file_path()
        )
        self.harvester.update_device_info_list()

        # Connect to the first camera in the list:
        self.ia = self.harvester.create_image_acquirer(0)

        #
        num_images_to_acquire = 0

        # Then start image acquisition:
        self.ia.start_image_acquisition()

        while num_images_to_acquire < 100:
            #
            with self.ia.fetch_buffer() as buffer:
                # self.do_something(buffer)
                pass

            num_images_to_acquire += 1

        # We don't need the ImageAcquirer object. Destroy it:
        self.ia.destroy()
示例#3
0
    def setUp(self) -> None:
        # The following block is just for administrative purpose;
        # you should not include it in your code:
        self.cti_file_path = get_cti_file_path()
        if 'TLSimu.cti' not in self.cti_file_path:
            self.skipTest('The target is not TLSimu.')

        # Create a Harvester object:
        self.harvester = Harvester()
class TestIssue81(unittest.TestCase):
    _cti_file_path = get_cti_file_path()
    sys.path.append(_cti_file_path)

    def test_issue_81(self):
        message_queue = Queue()
        t = _TestIssue81(
            message_queue=message_queue, cti_file_path=self._cti_file_path
        )
        t.start()
        t.join()
        try:
            result = message_queue.get(block=False)
        except Empty:
            # Nothing happened; everything is fine.
            pass
        else:
            exception, message, backtrace = result
            # Transfer the exception:
            raise exception(message)

    def test_issue_85(self):
        #
        temp_dir = os.path.join(
            gettempdir(), 'harvester', self.test_issue_85.__name__
        )

        #
        if os.path.isdir(temp_dir):
            rmtree(temp_dir)
        os.makedirs(temp_dir)

        #
        env_var = 'HARVESTERS_XML_FILE_DIR'
        original = None if os.environ else os.environ[env_var]

        os.environ[env_var] = temp_dir

        #
        self.assertFalse(os.listdir(temp_dir))

        #
        with Harvester() as h:
            h.add_cti_file(self._cti_file_path)
            h.update_device_info_list()
            with h.create_image_acquirer(0):
                pass

        #
        if original:
            os.environ[env_var] = original

        #
        self.assertTrue(os.listdir(temp_dir))
示例#5
0
class TestIssue81(unittest.TestCase):
    _cti_file_path = get_cti_file_path()
    sys.path.append(_cti_file_path)

    def test_issue_81(self):
        message_queue = Queue()
        t = _TestIssue81(message_queue=message_queue,
                         cti_file_path=self._cti_file_path)
        t.start()
        t.join()
        try:
            result = message_queue.get(block=False)
        except Empty:
            # Nothing happened; everything is fine.
            pass
        else:
            exception, message, backtrace = result
            # Transfer the exception:
            raise exception(message)
示例#6
0
class TestIssue85(unittest.TestCase):
    _cti_file_path = get_cti_file_path()
    sys.path.append(_cti_file_path)

    def setUp(self) -> None:
        #
        self.env_var = 'HARVESTERS_XML_FILE_DIR'
        self.original = None if os.environ else os.environ[self.env_var]

    def tearDown(self) -> None:
        if self.original:
            os.environ[self.env_var] = self.original

    def test_issue_85(self):
        #
        temp_dir = os.path.join(
            gettempdir(), 'harvester', self.test_issue_85.__name__
        )

        #
        if os.path.isdir(temp_dir):
            rmtree(temp_dir)
        os.makedirs(temp_dir)

        #
        os.environ[self.env_var] = temp_dir

        #
        self.assertFalse(os.listdir(temp_dir))

        #
        with Harvester() as h:
            h.add_file(self._cti_file_path)
            h.update()
            with h.create_image_acquirer(0):
                # Check if XML files have been stored in the expected
                # directory:
                self.assertTrue(os.listdir(temp_dir))