Ejemplo n.º 1
0
    def test_build_row(self, mock_build, mock_name):
        pixels = np.zeros((300, 300, 4))

        stage = models.PipelineStage(output_format='jpg',
                                     config={
                                         'tile_size': 100,
                                         'tile_overlap': 10
                                     })

        bundle = models.JobBundle(current_stage=stage)
        operation = TileImage(bundle)
        operation.build_row('f', 90, 1, pixels, 300)

        mock_name.assert_has_calls([
            call('f', 0, 1),
            call('f', 1, 1),
            call('f', 2, 1),
        ])
        assert (mock_name.call_count == 4)

        mock_build.assert_has_calls([
            call(pixels, 90, 0, 'a tile name'),
            call(pixels, 90, 90, 'a tile name'),
            call(pixels, 90, 180, 'a tile name'),
        ])
        assert (mock_build.call_count == 4)
Ejemplo n.º 2
0
    def test_tile_one(self, mock_row, mock_array, mock_open, *args):
        mock_open.return_value.__enter__ = Mock()
        mock_enter = mock_open.return_value.__enter__
        mock_enter.return_value.height = 300

        stage = models.PipelineStage(output_format='jpg',
                                     config={
                                         'tile_size': 100,
                                         'tile_overlap': 10
                                     })

        bundle = models.JobBundle(current_stage=stage)
        operation = TileImage(bundle)
        operation.tile_one('a')

        mock_open.assert_called_once_with('a')
        mock_array.assert_called_once_with(
            mock_open.return_value.__enter__.return_value)

        calls = [
            call('stripped', 0, 0, mock_array.return_value,
                 mock_enter.return_value.width),
            call('stripped', 90, 1, mock_array.return_value,
                 mock_enter.return_value.width),
            call('stripped', 180, 2, mock_array.return_value,
                 mock_enter.return_value.width),
            call('stripped', 270, 3, mock_array.return_value,
                 mock_enter.return_value.width),
        ]

        mock_row.assert_has_calls(calls)
        assert (mock_row.call_count == 4)
Ejemplo n.º 3
0
    def test_construct_tile_name(self):
        stage = models.PipelineStage(output_format='jpg',
                                     config={'output_directory': 'foo'})

        bundle = models.JobBundle(current_stage=stage)
        operation = TileImage(bundle)
        assert (operation.construct_tile_name(
            'f', 3, 4).endswith('foo/f_tile_004_003.jpg'))
Ejemplo n.º 4
0
    def test_apply_present(self, mock_one, mock_is, mock_mkdir):
        stage = models.PipelineStage(config={'output_directory': 'foo'})
        bundle = models.JobBundle(current_stage=stage)
        operation = TileImage(bundle)
        operation.apply(['a', 'b'])

        assert (mock_one.call_count == 2)
        mock_mkdir.assert_not_called()
Ejemplo n.º 5
0
    def test_construct_tile_name(self):
        stage = models.PipelineStage(
            output_format='jpg',
            sort_order=1,
            config={}
        )

        bundle = models.JobBundle(current_stage=stage)
        operation = TileImage(bundle)
        assert(operation.construct_tile_name('f', 3, 4).endswith("f_tile_004_003.png"))
Ejemplo n.º 6
0
    def test_get_new_filename(self, mock_get_new_version, mock_absolute, mock_construct):
        request = models.ImageryRequest(adapter_name='dummy')
        stage = models.PipelineStage(sort_order=3, output_format='png', config={})
        bundle = models.JobBundle(current_stage=stage, imagery_request=request)
        operation = ConcreteOperation(bundle)

        assert(operation.get_new_filename('some filename')=='new version name')
        mock_construct.assert_called_once_with(bundle, 'some filename')
        mock_absolute.assert_called_once_with(bundle=bundle, filename='dummy filename')
        mock_get_new_version.assert_called_once_with('absolute name')
Ejemplo n.º 7
0
    def test_pipeline_stage(self):
        stage = models.PipelineStage(
            output_format='jpg',
            select_images=['a', 'b'],
            config={'foo': 'bar'},
            sort_order=7,
        )
        bundle = models.JobBundle(current_stage=stage)
        operation = ConcreteOperation(bundle)

        assert(operation.pipeline_stage==stage)
        assert(operation.output_extension=='jpg')
        assert(operation.select_images==['a', 'b'])
        assert(operation.config=={'foo': 'bar'})
        assert(operation.sort_order==7)
Ejemplo n.º 8
0
    def test_build_tile(self, mock_array):
        mock_array.return_value.__enter__ = Mock()
        mock_enter = mock_array.return_value.__enter__
        pixels = np.zeros((300, 300, 4))

        stage = models.PipelineStage(
            output_format='jpg',
            config={'tile_size': 100, 'tile_overlap': 10}
        )

        bundle = models.JobBundle(current_stage=stage)
        operation = TileImage(bundle)

        operation.build_tile(pixels, 180, 90, 'f')

        np.testing.assert_array_equal(np.zeros((100, 100, 4)), mock_array.call_args[0][0])
        mock_enter.return_value.save.assert_called_once_with('f', 'png')
Ejemplo n.º 9
0
 def test_get_new_version_extension(self):
     stage = models.PipelineStage(sort_order=2, output_format='png', config={})
     bundle = models.JobBundle(current_stage=stage)
     operation = ConcreteOperation(bundle)
     assert(operation.get_new_version('foo.bar')=='foo_stage_02.png')
Ejemplo n.º 10
0
 def test_get_new_version_simple(self):
     stage = models.PipelineStage(sort_order=2, config={})
     bundle = models.JobBundle(current_stage=stage)
     operation = ConcreteOperation(bundle)
     assert(operation.get_new_version('foo.bar')=='foo_stage_02.tif')