Files
o3de/Gems/EditorPythonBindings/Code/Source/PythonSystemComponent.h
T
AMZN-AlexOteiza b815c203da (Continuation) Implemented automation paralellization & standarization (#1718)
Engine improvements/fixes

Fixed behavior that made the editor automated test to be sometimes stuck if lost the focus is lost.
Added support for specifying multiple tests to in batch to the editor, this is achieved by passing --runpythontest with the tests separated by ';'
Added new cmdline argument --project-user-path for overriding the user path. This allows to have multiple editors running writing logs and crash logs in different locations.
Moved responsability of exiting after a test finishes/passes out of ExecuteByFilenameAsTest, callers will use the bool return to know if the test passed.
Editor test batch and parallelization implementation:

Now the external python portion of the editor tests will be specified via test specs which will generate the test. Requiring no code. This is almost a data-driven approach.
Tests can be specified as single tests, parallel, batchable or batchable+parallel
Command line arguments for pytest to override the maximum number of editors, disable parallelization or batching.
Automated tests for testing this new editor testing utility

Signed-off-by: Garcia Ruiz <aljanru@amazon.co.uk>

Co-authored-by: Garcia Ruiz <aljanru@amazon.co.uk>
2021-07-22 12:57:23 +02:00

90 lines
3.9 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <EditorPythonBindings/EditorPythonBindingsSymbols.h>
#include <AzCore/Component/Component.h>
#include <AzCore/std/containers/unordered_set.h>
#include <AzToolsFramework/API/EditorPythonConsoleBus.h>
#include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h>
#include <AzCore/std/parallel/semaphore.h>
namespace EditorPythonBindings
{
/**
* Manages the Python interpreter inside this Gem (Editor only)
* - redirects the Python standard output and error streams to AZ_TracePrintf and AZ_Warning, respectively
*/
class PythonSystemComponent
: public AZ::Component
, protected AzToolsFramework::EditorPythonEventsInterface
, protected AzToolsFramework::EditorPythonRunnerRequestBus::Handler
{
public:
AZ_COMPONENT(PythonSystemComponent, PythonSystemComponentTypeId, AZ::Component);
static void Reflect(AZ::ReflectContext* context);
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
protected:
////////////////////////////////////////////////////////////////////////
// AZ::Component interface implementation
void Activate() override;
void Deactivate() override;
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// AzToolsFramework::EditorPythonEventsInterface
bool StartPython(bool silenceWarnings = false) override;
bool StopPython(bool silenceWarnings = false) override;
bool IsPythonActive() override;
void WaitForInitialization() override;
void ExecuteWithLock(AZStd::function<void()> executionCallback) override;
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// AzToolsFramework::EditorPythonRunnerRequestBus::Handler interface implementation
void ExecuteByString(AZStd::string_view script, bool printResult) override;
void ExecuteByFilename(AZStd::string_view filename) override;
void ExecuteByFilenameWithArgs(AZStd::string_view filename, const AZStd::vector<AZStd::string_view>& args) override;
bool ExecuteByFilenameAsTest(AZStd::string_view filename, AZStd::string_view testCase, const AZStd::vector<AZStd::string_view>& args) override;
////////////////////////////////////////////////////////////////////////
private:
// handle multiple Python initializers and threads
AZStd::atomic_int m_initalizeWaiterCount {0};
AZStd::semaphore m_initalizeWaiter;
AZStd::recursive_mutex m_lock;
enum class Result
{
Okay,
Error_IsNotInitialized,
Error_InvalidFilename,
Error_MissingFile,
Error_FileOpenValidation,
Error_InternalException,
Error_PythonException,
};
Result EvaluateFile(AZStd::string_view filename, const AZStd::vector<AZStd::string_view>& args);
// bootstrap logic and data
using PythonPathStack = AZStd::vector<AZStd::string>;
void DiscoverPythonPaths(PythonPathStack& pythonPathStack);
void ExecuteBootstrapScripts(const PythonPathStack& pythonPathStack);
bool ExtendSysPath(const AZStd::unordered_set<AZStd::string>& extendPaths);
// starts the Python interpreter
bool StartPythonInterpreter(const PythonPathStack& pythonPathStack);
bool StopPythonInterpreter();
};
}