Exemple #1
0
    def test_bypass_stream(self, write_stream_mock, open_stream_mock,
                           get_read_streams_mock, *othermocks):
        # given
        file_len = 50
        file_obj = IterIO(BytesIO('a' * file_len))
        get_read_streams_mock.return_value = [Stream('name', file_len, None)]
        open_stream_mock.return_value = file_obj
        options = create_stream_bypass_simple_config()

        # when:
        with closing(StreamBypass(options, meta())) as bypass:
            bypass.execute()

        # then:
        write_stream_mock.assert_called_once_with(
            Stream('name', file_len, None), file_obj)
        self.assertEquals(bypass.bypass_state.stats['bytes_copied'], 50,
                          'Wrong number of bytes written')
Exemple #2
0
    def test_resume_bypass(self, write_stream_mock, open_stream_mock,
                           get_streams_mock, *othermocks):
        # given
        options = create_stream_bypass_simple_config()
        options.persistence_options.update(
            resume=True, persistence_state_id=self.tmp_bypass_resume_file)
        options.persistence_options['options']['file_path'] = self.data_dir
        file_len = 50
        file_obj_b = IterIO(BytesIO('b' * file_len))
        stream_a = Stream('file_a', file_len, None)
        stream_b = Stream('file_b', file_len, None)
        get_streams_mock.return_value = [stream_a, stream_b]
        open_stream_mock.return_value = file_obj_b
        # Initial state is:
        # done = [(file_a, 50, None)] stats = {'bytes_copied': 50}

        # when:
        with closing(StreamBypass(options, meta())) as bypass:
            bypass.execute()

        # then:
        write_stream_mock.assert_called_once_with(stream_b, file_obj_b)
        assert bypass.bypass_state.stats['bytes_copied'] == 100,\
            'Wrong number of bytes written'