def run_activity(activity: Activity, configuration: Configuration, secrets: Secrets) -> Any: """ Run the given activity and return its result. If the activity defines a `timeout` this function raises :exc:`ActivityFailed`. This function assumes the activity is valid as per `ensure_layer_activity_is_valid`. Please be careful not to call this function without validating its input as this could be a security issue or simply fails miserably. This is an internal function and should probably avoid being called outside this package. """ try: provider = activity["provider"] activity_type = provider["type"] if activity_type == "python": result = run_python_activity(activity, configuration, secrets) elif activity_type == "process": result = run_process_activity(activity, configuration, secrets) elif activity_type == "http": result = run_http_activity(activity, configuration, secrets) except Exception: # just make sure we have a full traceback logger.debug("Activity failed", exc_info=True) raise return result
def test_process_non_exit_zero_warning(logger): run_process_activity( { "provider": { "type": "process", "path": "python", "arguments": '-c "import sys; sys.exit(1)"', } }, None, None, ) assert logger.warning.call_count == 1 assert ("This process returned a non-zero exit code." in logger.warning.call_args[0][0])
def test_process_homedir_relative_path(): path = os.path.abspath(dummy_script).replace(os.path.expanduser('~'), '~') result = run_process_activity( {"provider": { "type": "process", "path": path, "arguments": '' }}, None, None) assert result['status'] == 0
def test_process_cwd_relative_path(): result = run_process_activity( { "provider": { "type": "process", "path": dummy_script, "arguments": '' } }, None, None) assert result['status'] == 0
def test_process_absolute_path(): result = run_process_activity( { "provider": { "type": "process", "path": os.path.abspath(dummy_script), "arguments": '' } }, None, None) assert result['status'] == 0
def test_process_not_utf8_cannot_fail(): result = run_process_activity({ "provider": { "type": "process", "path": "python", "arguments": '-c "import sys; sys.stdout.buffer.write(bytes(\'é\', \'latin-1\'))"' } }, None, None) assert result['stdout'] == u'é'
def test_process_not_utf8_cannot_fail(): result = run_process_activity({ "provider": { "type": "process", "path": "python", "arguments": '-c "import sys; sys.stdout.buffer.write(bytes(\'é\', \'latin-1\'))"' } }, None, None) print(result['stderr']) # unfortunately, this doesn't seem to work well on mac if result['status'] == 0: assert result['stderr'] == u'' assert result['stdout'] == u'é'
def test_process_not_utf8_cannot_fail(): result = run_process_activity( { "provider": { "type": "process", "path": "python", "arguments": ("-c \"import sys; sys.stdout.buffer.write(bytes('é', 'latin-1'))\"" ), } }, None, None, ) # unfortunately, this doesn't seem to work well on mac if result["status"] == 0: assert result["stderr"] == "" assert result["stdout"] == "é"