def test_items_limit_should_not_meet_conditions(self): # given: config = create_stream_bypass_simple_config() config.writer_options['options']['items_limit'] = 10 # when: # then: self.assertFalse(StreamBypass.meets_conditions(config))
def test_custom_grouper_should_not_meet_conditions(self): # given: config = create_stream_bypass_simple_config(grouper={ 'name': 'whatever.Grouper', }) # when: # then: self.assertFalse(StreamBypass.meets_conditions(config))
def test_custom_filter_should_not_meet_conditions(self): # given: config = create_stream_bypass_simple_config(filter={ 'name': 'exporters.filters.PythonexpFilter', 'options': {'python_expression': 'None'} }) # when: # then: self.assertFalse(StreamBypass.meets_conditions(config))
def test_custom_filter_should_not_meet_conditions(self): # given: config = create_stream_bypass_simple_config( filter={ 'name': 'exporters.filters.PythonexpFilter', 'options': { 'python_expression': 'None' } }) # when: # then: self.assertFalse(StreamBypass.meets_conditions(config))
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')
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'
def test_should_meet_conditions(self): config = create_stream_bypass_simple_config() # shouldn't raise any exception StreamBypass.meets_conditions(config)