Beispiel #1
0
    def test_reservoir_remove_sample(self, load_reservoir_remove_sample_image_record):
        """
        Test removing sample in reservoir.

        If step list is [1, 3, 5, 7, 9, 2, 3, 4, 15],
        and then [3, 5, 7, 9] will be deleted.
        Results will be [1, 2, 3, 4, 15].
        """
        test_tag_name = self._complete_tag_name

        not_found_step_list = []
        current_step_list = []

        steps_list = set(self._cross_steps_list)
        for step in steps_list:
            test_step = step

            image_processor = ImageProcessor(self._mock_data_manager)

            try:
                image_processor.get_single_image(self._train_id, test_tag_name, test_step)
                current_step_list.append(test_step)
            except ParamValueError:
                not_found_step_list.append(test_step)

        assert current_step_list == [1, 2, 3, 4, 15]
        assert not_found_step_list == [5, 7, 9]
    def test_reservoir_remove_sample(self):
        """
        Test removing sample in reservoir.

        If step list is [1, 3, 5, 7, 9, 2, 3, 4, 15] in one summary,
        Results will be [1, 2, 3, 4, 5, 7, 9, 15].
        """
        test_tag_name = self._complete_tag_name

        not_found_step_list = []
        current_step_list = []

        steps_list = set(self._cross_steps_list)
        for step in steps_list:
            test_step = step

            image_processor = ImageProcessor(self._mock_data_manager)

            try:
                image_processor.get_single_image(self._train_id, test_tag_name, test_step)
                current_step_list.append(test_step)
            except ImageNotExistError:
                not_found_step_list.append(test_step)

        assert current_step_list == [1, 2, 3, 4, 5, 7, 9, 15]
Beispiel #3
0
    def test_get_single_image_with_not_exist_step(self, load_image_record):
        """Test getting single image with not exist step."""
        test_tag_name = self._complete_tag_name
        test_step = 10000

        image_processor = ImageProcessor(self._mock_data_manager)

        with pytest.raises(ParamValueError) as exc_info:
            image_processor.get_single_image(self._train_id, test_tag_name, test_step)

        assert exc_info.value.error_code == '50540002'
        assert "Can not find the step with given train job id and tag." in exc_info.value.message
Beispiel #4
0
    def test_get_single_image_with_not_exist_tag(self, load_image_record):
        """Test getting single image with not exist tag."""
        test_tag_name = 'not_exist_tag_name'
        test_step = self._steps_list[0]

        image_processor = ImageProcessor(self._mock_data_manager)

        with pytest.raises(ParamValueError) as exc_info:
            image_processor.get_single_image(self._train_id, test_tag_name, test_step)

        assert exc_info.value.error_code == '50540002'
        assert "Can not find any data in this train job by given tag." in exc_info.value.message
Beispiel #5
0
    def test_get_single_image_with_not_exist_id(self, load_image_record):
        """Test getting single image with not exist id."""
        test_train_id = 'not_exist_id'
        test_tag_name = self._complete_tag_name
        test_step = self._steps_list[0]
        image_processor = ImageProcessor(self._mock_data_manager)

        with pytest.raises(ParamValueError) as exc_info:
            image_processor.get_single_image(test_train_id, test_tag_name, test_step)

        assert exc_info.value.error_code == '50540002'
        assert "Can not find any data in loader pool about the train job." in exc_info.value.message
    def test_get_single_image_with_not_exist_id(self):
        """Test getting single image with not exist id."""
        test_train_id = 'not_exist_id'
        test_tag_name = self._complete_tag_name
        test_step = self._steps_list[0]
        image_processor = ImageProcessor(self._mock_data_manager)

        with pytest.raises(TrainJobNotExistError) as exc_info:
            image_processor.get_single_image(test_train_id, test_tag_name, test_step)

        assert exc_info.value.error_code == '50545005'
        assert exc_info.value.message == "Train job is not exist. Detail: Can not find the given train job in cache."
    def test_get_single_image_with_not_exist_step(self):
        """Test getting single image with not exist step."""
        test_tag_name = self._complete_tag_name
        test_step = 10000

        image_processor = ImageProcessor(self._mock_data_manager)

        with pytest.raises(ImageNotExistError) as exc_info:
            image_processor.get_single_image(self._train_id, test_tag_name, test_step)

        assert exc_info.value.error_code == '5054500D'
        assert exc_info.value.message == "Image is not exist. " \
               "Detail: Can not find the step with given train job id and tag."
Beispiel #8
0
    def test_reservoir_add_sample(self, load_more_than_limit_image_record):
        """Test adding sample in reservoir."""
        test_tag_name = self._complete_tag_name

        cnt = 0

        for step in self._more_steps_list:
            test_step = step

            image_processor = ImageProcessor(self._mock_data_manager)

            try:
                image_processor.get_single_image(self._train_id, test_tag_name, test_step)
            except ParamValueError:
                cnt += 1
        assert len(self._more_steps_list) - cnt == 10
Beispiel #9
0
    def test_get_single_image_success(self, load_image_record):
        """Test getting single image successfully."""
        test_tag_name = self._complete_tag_name
        test_step_index = 0
        test_step = self._steps_list[test_step_index]

        expected_image_tensor = self._images_values.get(test_step)
        image_processor = ImageProcessor(self._mock_data_manager)
        results = image_processor.get_single_image(self._train_id, test_tag_name, test_step)
        recv_image_tensor = get_image_tensor_from_bytes(results)

        assert recv_image_tensor.any() == expected_image_tensor.any()
Beispiel #10
0
def single_image():
    """
    Interface to fetch raw image data for a particular image.

    Returns:
        Response, which contains a byte string of image.
    """
    tag = request.args.get("tag")
    step = request.args.get("step")
    train_id = get_train_id(request)

    processor = ImageProcessor(DATA_MANAGER)
    img_data = processor.get_single_image(train_id, tag, step)
    return img_data