Address PR comments

Signed-off-by: John <jonawals@amazon.com>
monroegm-disable-blank-issue-2
John 5 years ago
parent 1cf1301a07
commit fd1bb483c0

@ -28,14 +28,16 @@ if(PAL_TRAIT_PYTHONCOVERAGE_SUPPORTED)
PUBLIC PUBLIC
PYTHON_COVERAGE_EDITOR PYTHON_COVERAGE_EDITOR
PRIVATE PRIVATE
LY_TEST_IMPACT_DEFAULT_CONFIG_FILE=\"\" ${LY_TEST_IMPACT_CONFIG_FILE_PATH_DEFINITION}
BUILD_DEPENDENCIES BUILD_DEPENDENCIES
PUBLIC PUBLIC
AZ::AzToolsFramework AZ::AzToolsFramework
RUNTIME_DEPENDENCIES
Gem::EditorPythonBindings.Editor
) )
ly_add_target( ly_add_target(
NAME PythonCoverage.Editor MODULE NAME PythonCoverage.Editor GEM_MODULE
NAMESPACE Gem NAMESPACE Gem
AUTOMOC AUTOMOC
OUTPUT_NAME Gem.PythonCoverage.Editor OUTPUT_NAME Gem.PythonCoverage.Editor
@ -58,26 +60,3 @@ if(PAL_TRAIT_PYTHONCOVERAGE_SUPPORTED)
ly_create_alias(NAME PythonCoverage.Builders NAMESPACE Gem TARGETS Gem::PythonCoverage.Editor) ly_create_alias(NAME PythonCoverage.Builders NAMESPACE Gem TARGETS Gem::PythonCoverage.Editor)
endif() endif()
endif() endif()
if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
if(PAL_TRAIT_BUILD_HOST_TOOLS)
ly_add_target(
NAME PythonCoverage.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
NAMESPACE Gem
FILES_CMAKE
pythoncoverage_editor_tests_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
Tests
Source
BUILD_DEPENDENCIES
PRIVATE
AZ::AzTest
Gem::PythonCoverage.Editor
)
ly_add_googletest(
NAME Gem::PythonCoverage.Editor.Tests
)
endif()
endif()

@ -76,20 +76,18 @@ namespace PythonCoverage
void PythonCoverageEditorSystemComponent::ParseCoverageOutputDirectory() void PythonCoverageEditorSystemComponent::ParseCoverageOutputDirectory()
{ {
m_coverageState = CoverageState::Disabled; m_coverageState = CoverageState::Disabled;
// Config file path will be empty if test impact analysis framework is disabled at the build config level
const AZStd::string configFilePath = LY_TEST_IMPACT_DEFAULT_CONFIG_FILE; const AZStd::string configFilePath = LY_TEST_IMPACT_DEFAULT_CONFIG_FILE;
if (configFilePath.empty()) if (configFilePath.empty())
{ {
AZ_Warning(Caller, false, "No test impact analysis framework config found."); AZ_Warning(Caller, false, "No test impact analysis framework config file specified.");
return; return;
} }
const auto fileSize = AZ::IO::SystemFile::Length(configFilePath.c_str()); const auto fileSize = AZ::IO::SystemFile::Length(configFilePath.c_str());
if(!fileSize) if(!fileSize)
{ {
AZ_Error(Caller, false, "File '%s' does not exist", configFilePath.c_str()); AZ_Error(Caller, false, "Test impact analysis framework config file '%s' does not exist", configFilePath.c_str());
return; return;
} }
@ -97,7 +95,7 @@ namespace PythonCoverage
buffer[fileSize] = '\0'; buffer[fileSize] = '\0';
if (!AZ::IO::SystemFile::Read(configFilePath.c_str(), buffer.data())) if (!AZ::IO::SystemFile::Read(configFilePath.c_str(), buffer.data()))
{ {
AZ_Error(Caller, false, "Could not read contents of file '%s'", configFilePath.c_str()); AZ_Error(Caller, false, "Could not read contents of test impact analysis framework config file '%s'", configFilePath.c_str());
return; return;
} }
@ -105,13 +103,13 @@ namespace PythonCoverage
rapidjson::Document configurationFile; rapidjson::Document configurationFile;
if (configurationFile.Parse(configurationData.c_str()).HasParseError()) if (configurationFile.Parse(configurationData.c_str()).HasParseError())
{ {
AZ_Error(Caller, false, "Could not parse runtimeConfig data, JSON has errors"); AZ_Error(Caller, false, "Could not parse test impact analysis framework config file data, JSON has errors");
return; return;
} }
const auto& tempConfig = configurationFile["workspace"]["temp"]; const auto& tempConfig = configurationFile["workspace"]["temp"];
// Temo directory root path is absolute // Temp directory root path is absolute
const AZ::IO::Path tempWorkspaceRootDir = tempConfig["root"].GetString(); const AZ::IO::Path tempWorkspaceRootDir = tempConfig["root"].GetString();
// Artifact directory is relative to temp directory root // Artifact directory is relative to temp directory root
@ -212,7 +210,7 @@ namespace PythonCoverage
return coveringModuleOutputNames; return coveringModuleOutputNames;
} }
void PythonCoverageEditorSystemComponent::OnExecuteByFilenameAsTest(AZStd::string_view filename, AZStd::string_view testCase, [[maybe_unused]] const AZStd::vector<AZStd::string_view>& args) void PythonCoverageEditorSystemComponent::OnStartExecuteByFilenameAsTest(AZStd::string_view filename, AZStd::string_view testCase, [[maybe_unused]] const AZStd::vector<AZStd::string_view>& args)
{ {
if (m_coverageState == CoverageState::Disabled) if (m_coverageState == CoverageState::Disabled)
{ {

@ -47,7 +47,7 @@ namespace PythonCoverage
void OnEntityActivated(const AZ::EntityId& entityId) override; void OnEntityActivated(const AZ::EntityId& entityId) override;
// AZ::EditorPythonScriptNotificationsBus ... // AZ::EditorPythonScriptNotificationsBus ...
void OnExecuteByFilenameAsTest(AZStd::string_view filename, AZStd::string_view testCase, const AZStd::vector<AZStd::string_view>& args) override; void OnStartExecuteByFilenameAsTest(AZStd::string_view filename, AZStd::string_view testCase, const AZStd::vector<AZStd::string_view>& args) override;
//! Attempts to parse the test impact analysis framework configuration file. //! Attempts to parse the test impact analysis framework configuration file.
//! If either the test impact analysis framework is disabled or the configuration file cannot be parsed, python coverage //! If either the test impact analysis framework is disabled or the configuration file cannot be parsed, python coverage

@ -1,24 +0,0 @@
#include <AzTest/AzTest.h>
class PythonCoverageEditorTest
: public ::testing::Test
{
protected:
void SetUp() override
{
}
void TearDown() override
{
}
};
TEST_F(PythonCoverageEditorTest, SanityTest)
{
ASSERT_TRUE(true);
}
AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);

@ -1,14 +0,0 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
set(FILES
Tests/PythonCoverageEditorTest.cpp
)

@ -1,9 +1,7 @@
{ {
"gem_name": "PythonCoverage", "gem_name": "PythonCoverage",
"origin": "The primary repo for PythonCoverage goes here: i.e. http://www.mydomain.com",
"license": "What license PythonCoverage uses goes here: i.e. https://opensource.org/licenses/MIT",
"display_name": "PythonCoverage", "display_name": "PythonCoverage",
"summary": "A short description of PythonCoverage.", "summary": "A tool for generating gem coverage for Python tests.",
"canonical_tags": [ "canonical_tags": [
"Gem" "Gem"
], ],

@ -1,46 +0,0 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
namespace AzToolsFramework
{
//! Provides a bus to notify when Python scripts are about to run.
class EditorPythonRunnerNotification
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//////////////////////////////////////////////////////////////////////////
//! Notifies the execution of a Python script using a string.
virtual void ExecuteByString([[maybe_unused]] AZStd::string_view script) {}
//! Notifies the execution of a Python script using a filename.
virtual void ExecuteByFilename([[maybe_unused]] AZStd::string_view filename) {}
//! Notifies the execution of a Python script using a filename and args.
virtual void ExecuteByFilenameWithArgs(
[[maybe_unused]] AZStd::string_view filename, [[maybe_unused]] const AZStd::vector<AZStd::string_view>& args) {}
//! Notifies the execution of a Python script as a test.
virtual void ExecuteByFilenameAsTest(
[[maybe_unused]] AZStd::string_view filename, [[maybe_unused]] const AZStd::vector<AZStd::string_view>& args) {}
};
using EditorPythonRunnerNotificationBus = AZ::EBus<EditorPythonRunnerNotification>;
} // namespace AzToolsFramework

@ -27,18 +27,18 @@ namespace AzToolsFramework
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
//! Notifies the execution of a Python script using a string. //! Notifies the start of execution of a Python script using a string.
virtual void OnExecuteByString([[maybe_unused]] AZStd::string_view script) {} virtual void OnStartExecuteByString([[maybe_unused]] AZStd::string_view script) {}
//! Notifies the execution of a Python script using a filename. //! Notifies the start of execution of a Python script using a filename.
virtual void OnExecuteByFilename([[maybe_unused]] AZStd::string_view filename) {} virtual void OnStartExecuteByFilename([[maybe_unused]] AZStd::string_view filename) {}
//! Notifies the execution of a Python script using a filename and args. //! Notifies the start of execution of a Python script using a filename and args.
virtual void OnExecuteByFilenameWithArgs( virtual void OnStartExecuteByFilenameWithArgs(
[[maybe_unused]] AZStd::string_view filename, [[maybe_unused]] const AZStd::vector<AZStd::string_view>& args) {} [[maybe_unused]] AZStd::string_view filename, [[maybe_unused]] const AZStd::vector<AZStd::string_view>& args) {}
//! Notifies the execution of a Python script as a test. //! Notifies the start of execution of a Python script as a test.
virtual void OnExecuteByFilenameAsTest( virtual void OnStartExecuteByFilenameAsTest(
[[maybe_unused]] AZStd::string_view filename, [[maybe_unused]] AZStd::string_view testCase, [[maybe_unused]] const AZStd::vector<AZStd::string_view>& args) {} [[maybe_unused]] AZStd::string_view filename, [[maybe_unused]] AZStd::string_view testCase, [[maybe_unused]] const AZStd::vector<AZStd::string_view>& args) {}
}; };
using EditorPythonScriptNotificationsBus = AZ::EBus<EditorPythonScriptNotifications>; using EditorPythonScriptNotificationsBus = AZ::EBus<EditorPythonScriptNotifications>;

@ -581,7 +581,7 @@ namespace EditorPythonBindings
if (!script.empty()) if (!script.empty())
{ {
AzToolsFramework::EditorPythonScriptNotificationsBus::Broadcast( AzToolsFramework::EditorPythonScriptNotificationsBus::Broadcast(
&AzToolsFramework::EditorPythonScriptNotificationsBus::Events::OnExecuteByString, script); &AzToolsFramework::EditorPythonScriptNotificationsBus::Events::OnStartExecuteByString, script);
// Acquire GIL before calling Python code // Acquire GIL before calling Python code
AZStd::lock_guard<decltype(m_lock)> lock(m_lock); AZStd::lock_guard<decltype(m_lock)> lock(m_lock);
@ -644,14 +644,14 @@ namespace EditorPythonBindings
{ {
AZStd::vector<AZStd::string_view> args; AZStd::vector<AZStd::string_view> args;
AzToolsFramework::EditorPythonScriptNotificationsBus::Broadcast( AzToolsFramework::EditorPythonScriptNotificationsBus::Broadcast(
&AzToolsFramework::EditorPythonScriptNotificationsBus::Events::OnExecuteByFilename, filename); &AzToolsFramework::EditorPythonScriptNotificationsBus::Events::OnStartExecuteByFilename, filename);
ExecuteByFilenameWithArgs(filename, args); ExecuteByFilenameWithArgs(filename, args);
} }
void PythonSystemComponent::ExecuteByFilenameAsTest(AZStd::string_view filename, AZStd::string_view testCase, const AZStd::vector<AZStd::string_view>& args) void PythonSystemComponent::ExecuteByFilenameAsTest(AZStd::string_view filename, AZStd::string_view testCase, const AZStd::vector<AZStd::string_view>& args)
{ {
AzToolsFramework::EditorPythonScriptNotificationsBus::Broadcast( AzToolsFramework::EditorPythonScriptNotificationsBus::Broadcast(
&AzToolsFramework::EditorPythonScriptNotificationsBus::Events::OnExecuteByFilenameAsTest, filename, testCase, args); &AzToolsFramework::EditorPythonScriptNotificationsBus::Events::OnStartExecuteByFilenameAsTest, filename, testCase, args);
const Result evalResult = EvaluateFile(filename, args); const Result evalResult = EvaluateFile(filename, args);
if (evalResult == Result::Okay) if (evalResult == Result::Okay)
{ {
@ -668,7 +668,7 @@ namespace EditorPythonBindings
void PythonSystemComponent::ExecuteByFilenameWithArgs(AZStd::string_view filename, const AZStd::vector<AZStd::string_view>& args) void PythonSystemComponent::ExecuteByFilenameWithArgs(AZStd::string_view filename, const AZStd::vector<AZStd::string_view>& args)
{ {
AzToolsFramework::EditorPythonScriptNotificationsBus::Broadcast( AzToolsFramework::EditorPythonScriptNotificationsBus::Broadcast(
&AzToolsFramework::EditorPythonScriptNotificationsBus::Events::OnExecuteByFilenameWithArgs, filename, args); &AzToolsFramework::EditorPythonScriptNotificationsBus::Events::OnStartExecuteByFilenameWithArgs, filename, args);
EvaluateFile(filename, args); EvaluateFile(filename, args);
} }

Loading…
Cancel
Save