def test_the_iterator_can_be_consumed(): factory = ShellFactory(CONF_OFFLINE) iterator = gen_profiles(10) shelled = factory.shell_iterator(iterator, destination='some-destination') iterator_bis = gen_profiles(10) assert list(shelled) == list(iterator_bis)
def test_shell_around_generators(mock_starfish): # Arrange config = Config(mock_starfish.url, 'test_3', 'run_1') starfish = ShellFactory(config) iterable = gen_profiles(10) # Act: Shell Processes shelled_input = starfish.shell_iterator(iterable, source='my-shelled-source') processed = first_3(shelled_input) shelled_result = starfish.shell_iterator( processed, destination='my-shelled-destination') list(shelled_result) # Consume the result iterator # Assert assert shelled_input.starfish.consumed == 10 assert shelled_result.starfish.consumed == 3
def test_some_failure_should_never_block_the_processing(): # Arrange config = Config('http://wrong_url', 'test_3', 'run_1') starfish = ShellFactory(config) iterable = gen_profiles(10) # Act: Shell Processes shelled_input = starfish.shell_iterator(iterable, source='my-shelled-source') processed = first_3(shelled_input) shelled_result = starfish.shell_iterator( processed, destination='my-shelled-destination') result = list(shelled_result) # Consume the result iterator # Assert assert len(result) == 3 assert shelled_input.starfish.failed assert shelled_result.starfish.failed
def test_shell_around_a_simple_functions(mock_starfish): with env(STARFISH_API_URL=mock_starfish.url, STARFISH_SERVICE_ID='test_1', STARFISH_RUN_ID='run_1'): starfish = ShellFactory.from_env() shelled = starfish.shell_process( noop_processing, source='some-source-identifier', destination='some-destination-identifier') # that would be the moment where you store profiles somewhere else. list(shelled(gen_profiles(10))) # The content has been consumed assert shelled.starfish.consumed == 20 # The server has been requested logs = mock_starfish.logs assert len(logs) == 20 assert 'some-source-identifier' in logs.sources assert 'some-destination-identifier' in logs.destinations for log in logs: assert check_server_log(log)
import json import click from starfish_shell import ShellFactory def profile_matcher(profile): return profile['login']['username'] FACTORY = ShellFactory.from_env(matcher=profile_matcher) def get_field(field, jline): for f in field: jline = jline.get(f, {}) return str(jline).lower() def filter_profiles(profiles, field, value, is_search): for profile in profiles: current_value = get_field(field, profile) if (is_search and value in current_value) or (current_value == value): yield profile @click.command() @click.option('--field', '-f', default='age') @click.option('--search/--no-search', default=False) @click.option('--value', '-V', default='25')
def test_i_can_create_the_factory(): factory = ShellFactory(CONF_OFFLINE) assert factory is not None
def test_the_iterator_has_starfish_infos(): factory = ShellFactory(CONF_OFFLINE) iterator = gen_profiles(10) shelled = factory.shell_iterator(iterator, source='source') assert shelled.starfish
def test_i_can_wrap_iterators(): factory = ShellFactory(CONF_OFFLINE) iterator = gen_profiles(10) shelled = factory.shell_iterator(iterator, source='some-source') assert shelled
def test_the_result_has_starfish_details(): factory = ShellFactory(CONF_OFFLINE) shelled = factory.shell_process(identity, source='some-source', destination='some-dest') assert shelled.starfish
def test_the_function_i_wrap_doesnt_change_input_outputs(): factory = ShellFactory(CONF_OFFLINE.with_matcher(random_matcher)) shelled = factory.shell_process(identity, source='some-source', destination='some-dest') assert list(shelled([1, 2, 3])) == [1, 2, 3]
def test_build_factory_config_from_env(): with env(STARFISH_API_URL='a', STARFISH_SERVICE_ID='b', STARFISH_RUN_ID='c'): config = ShellFactory.from_env().config assert config == Config(api_url='a', service_id='b', run_id='c')
def test_i_can_wrap_a_function_with_the_factory(): factory = ShellFactory(CONF_OFFLINE) shelled = factory.shell_process(identity, source='some-source', destination='some-dest') assert shelled is not None