Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing long class name #20739

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixing long class name
adityashahms committed Dec 18, 2024
commit b3a563145c7fc5023679f1bc4c3389823dd3518a
96 changes: 49 additions & 47 deletions Tasks/AzureTestPlanV0/Invokers/pythoninvoker.ts
Original file line number Diff line number Diff line change
@@ -14,10 +14,32 @@ export async function executePythonTests(testsToBeExecuted: string[]):Promise<nu

// Extract discovered tests from stdout
const discoveredTests: string[] = extractDiscoveredTests(discoveryResult.stdout ?? '');
testsToBeExecuted = testsToBeExecuted.map(transformTestStrings);
var testStringtoFQNMap: Map<string, string> = new Map<string, string>();

for(let test of discoveredTests){
testStringtoFQNMap.set(transformTestStrings(test), test);
}

var testsToRun: string[] = [];

for(let test of testsToBeExecuted){
if(!testStringtoFQNMap.has(test)){
tl.debug(`Test ${test} not found in discovered tests`);
}
else{
try{
testsToRun.push(testStringtoFQNMap.get(test));
}
catch (err){
console.log(err);
console.log(String(err));
testsToRun.concat([`'${testStringtoFQNMap.get(test)}'`]);
}
}
}

// Find common tests between testsToBeExecuted and discovered tests
const testsToRun: string[] = testsToBeExecuted.filter(test => discoveredTests.indexOf(test) !== -1);
//const testsToRun: string[] = testsToBeExecuted.filter(test => discoveredTests.indexOf(test) !== -1);

// Variables for debug console logs
const testsToBeExecutedString: string = testsToBeExecuted.join(", ");
@@ -65,41 +87,9 @@ async function runPytestCommand(args: string[]): Promise<SpawnResult> {
}
}

function extractOldDiscoveredTests(output) {
const testNames = [];
let currentPackage = '';
let currentModule = '';
let currentClass = '';

const lines = output.split('\n');

for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();

if (line.startsWith('<Package')) {
currentPackage = line.match(/<Package (.*?)>/)[1];
} else if (line.startsWith('<Module')) {
currentModule = line.match(/<Module (.*?)>/)[1];
} else if (line.startsWith('<UnitTestCase')) {
currentClass = line.match(/<UnitTestCase (.*?)>/)[1];
} else if (line.startsWith('<TestCaseFunction')) {
const functionName = line.match(/<TestCaseFunction (.*?)>/)[1];
let fullyQualifiedName = '';
if (currentPackage !== '') {
fullyQualifiedName += currentPackage + '/';
}
fullyQualifiedName += `${currentModule}::${currentClass}::${functionName}`;
testNames.push(fullyQualifiedName);
}
}
tl.debug("Discovered tests : " + testNames);
return testNames;
}

function extractDiscoveredTests(output: string) {
const testNames = [];

const lines = output.split('\n');
function extractDiscoveredTests(output: string): string[] {
var testNames: string[] = [];
var lines: string[] = output.split('\n');

for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
@@ -111,17 +101,29 @@ function extractDiscoveredTests(output: string) {
return testNames;
}

function transformTestStrings(test: string): string {
// Input is like Folder/SubFolder/TestClass.py::TestSubClass::TestSubSubClass::test_method_name
// Output is lke Folder.SubFolder.TestClass.TestSubClass.TestSubSubClass.test_method_name
function transformTestStrings(automatedTestName: string): string {
// Remove any leading or trailing whitespace
test = test.trim();
automatedTestName = automatedTestName.trim();
let updatedAutomatedTestName: string = automatedTestName;

const index = automatedTestName.indexOf("::");
if(index !== -1) {
let testFilePath = automatedTestName.substring(0, index);
let testMethod = automatedTestName.substring(index + 2);

//Check if testfilePath is a python file
if(testFilePath.endsWith(".py")) {
testFilePath = testFilePath.slice(0, -3).replace(/\//g, '.');

// Replace '.' with '/' for the directory structure
// Replace the last part of the string with '.py'
test = test.replace(/\./g, '/').replace(/\.([^/]+)$/, '.py');
//Do the same replace with :: to . in testMethod
testMethod = testMethod.replace(/::/g, '.');

//Finally generate updatedAutomatedTestName
updatedAutomatedTestName = testFilePath + "." + testMethod;
}
}

// Add the `::` before the test function name
const parts = test.split('/');
const functionName = parts.pop(); // Remove the function name
const testFile = parts.join('/'); // Join back the file path
return `${testFile}.py::${functionName}`; // Format as required
return updatedAutomatedTestName;
}
78 changes: 39 additions & 39 deletions Tasks/AzureTestPlanV0/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Tasks/AzureTestPlanV0/task.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 250,
"Patch": 6
"Patch": 8
},
"preview": true,
"demands": [],
2 changes: 1 addition & 1 deletion Tasks/AzureTestPlanV0/task.loc.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 250,
"Patch": 6
"Patch": 8
},
"preview": true,
"demands": [],
4 changes: 2 additions & 2 deletions _generated/AzureTestPlanV0.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|0.250.6
Node20-225|0.250.7
Default|0.250.8
Node20-225|0.250.9
96 changes: 49 additions & 47 deletions _generated/AzureTestPlanV0/Invokers/pythoninvoker.ts
Original file line number Diff line number Diff line change
@@ -14,10 +14,32 @@ export async function executePythonTests(testsToBeExecuted: string[]):Promise<nu

// Extract discovered tests from stdout
const discoveredTests: string[] = extractDiscoveredTests(discoveryResult.stdout ?? '');
testsToBeExecuted = testsToBeExecuted.map(transformTestStrings);
var testStringtoFQNMap: Map<string, string> = new Map<string, string>();

for(let test of discoveredTests){
testStringtoFQNMap.set(transformTestStrings(test), test);
}

var testsToRun: string[] = [];

for(let test of testsToBeExecuted){
if(!testStringtoFQNMap.has(test)){
tl.debug(`Test ${test} not found in discovered tests`);
}
else{
try{
testsToRun.push(testStringtoFQNMap.get(test));
}
catch (err){
console.log(err);
console.log(String(err));
testsToRun.concat([`'${testStringtoFQNMap.get(test)}'`]);
}
}
}

// Find common tests between testsToBeExecuted and discovered tests
const testsToRun: string[] = testsToBeExecuted.filter(test => discoveredTests.indexOf(test) !== -1);
//const testsToRun: string[] = testsToBeExecuted.filter(test => discoveredTests.indexOf(test) !== -1);

// Variables for debug console logs
const testsToBeExecutedString: string = testsToBeExecuted.join(", ");
@@ -65,41 +87,9 @@ async function runPytestCommand(args: string[]): Promise<SpawnResult> {
}
}

function extractOldDiscoveredTests(output) {
const testNames = [];
let currentPackage = '';
let currentModule = '';
let currentClass = '';

const lines = output.split('\n');

for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();

if (line.startsWith('<Package')) {
currentPackage = line.match(/<Package (.*?)>/)[1];
} else if (line.startsWith('<Module')) {
currentModule = line.match(/<Module (.*?)>/)[1];
} else if (line.startsWith('<UnitTestCase')) {
currentClass = line.match(/<UnitTestCase (.*?)>/)[1];
} else if (line.startsWith('<TestCaseFunction')) {
const functionName = line.match(/<TestCaseFunction (.*?)>/)[1];
let fullyQualifiedName = '';
if (currentPackage !== '') {
fullyQualifiedName += currentPackage + '/';
}
fullyQualifiedName += `${currentModule}::${currentClass}::${functionName}`;
testNames.push(fullyQualifiedName);
}
}
tl.debug("Discovered tests : " + testNames);
return testNames;
}

function extractDiscoveredTests(output: string) {
const testNames = [];

const lines = output.split('\n');
function extractDiscoveredTests(output: string): string[] {
var testNames: string[] = [];
var lines: string[] = output.split('\n');

for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
@@ -111,17 +101,29 @@ function extractDiscoveredTests(output: string) {
return testNames;
}

function transformTestStrings(test: string): string {
// Input is like Folder/SubFolder/TestClass.py::TestSubClass::TestSubSubClass::test_method_name
// Output is lke Folder.SubFolder.TestClass.TestSubClass.TestSubSubClass.test_method_name
function transformTestStrings(automatedTestName: string): string {
// Remove any leading or trailing whitespace
test = test.trim();
automatedTestName = automatedTestName.trim();
let updatedAutomatedTestName: string = automatedTestName;

const index = automatedTestName.indexOf("::");
if(index !== -1) {
let testFilePath = automatedTestName.substring(0, index);
let testMethod = automatedTestName.substring(index + 2);

//Check if testfilePath is a python file
if(testFilePath.endsWith(".py")) {
testFilePath = testFilePath.slice(0, -3).replace(/\//g, '.');

// Replace '.' with '/' for the directory structure
// Replace the last part of the string with '.py'
test = test.replace(/\./g, '/').replace(/\.([^/]+)$/, '.py');
//Do the same replace with :: to . in testMethod
testMethod = testMethod.replace(/::/g, '.');

//Finally generate updatedAutomatedTestName
updatedAutomatedTestName = testFilePath + "." + testMethod;
}
}

// Add the `::` before the test function name
const parts = test.split('/');
const functionName = parts.pop(); // Remove the function name
const testFile = parts.join('/'); // Join back the file path
return `${testFile}.py::${functionName}`; // Format as required
return updatedAutomatedTestName;
}
78 changes: 39 additions & 39 deletions _generated/AzureTestPlanV0/package-lock.json
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0/task.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 250,
"Patch": 6
"Patch": 8
},
"preview": true,
"demands": [],
@@ -178,8 +178,8 @@
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
},
"_buildConfigMapping": {
"Default": "0.250.6",
"Default": "0.250.8",
"LocalPackages": "0.249.4",
"Node20-225": "0.250.7"
"Node20-225": "0.250.9"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0/task.loc.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 250,
"Patch": 6
"Patch": 8
},
"preview": true,
"demands": [],
@@ -178,8 +178,8 @@
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
},
"_buildConfigMapping": {
"Default": "0.250.6",
"Default": "0.250.8",
"LocalPackages": "0.249.4",
"Node20-225": "0.250.7"
"Node20-225": "0.250.9"
}
}
4 changes: 4 additions & 0 deletions _generated/AzureTestPlanV0_Node20/.npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
scripts-prepend-node-path=true

registry=https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/

always-auth=true
96 changes: 49 additions & 47 deletions _generated/AzureTestPlanV0_Node20/Invokers/pythoninvoker.ts
Original file line number Diff line number Diff line change
@@ -14,10 +14,32 @@ export async function executePythonTests(testsToBeExecuted: string[]):Promise<nu

// Extract discovered tests from stdout
const discoveredTests: string[] = extractDiscoveredTests(discoveryResult.stdout ?? '');
testsToBeExecuted = testsToBeExecuted.map(transformTestStrings);
var testStringtoFQNMap: Map<string, string> = new Map<string, string>();

for(let test of discoveredTests){
testStringtoFQNMap.set(transformTestStrings(test), test);
}

var testsToRun: string[] = [];

for(let test of testsToBeExecuted){
if(!testStringtoFQNMap.has(test)){
tl.debug(`Test ${test} not found in discovered tests`);
}
else{
try{
testsToRun.push(testStringtoFQNMap.get(test));
}
catch (err){
console.log(err);
console.log(String(err));
testsToRun.concat([`'${testStringtoFQNMap.get(test)}'`]);
}
}
}

// Find common tests between testsToBeExecuted and discovered tests
const testsToRun: string[] = testsToBeExecuted.filter(test => discoveredTests.indexOf(test) !== -1);
//const testsToRun: string[] = testsToBeExecuted.filter(test => discoveredTests.indexOf(test) !== -1);

// Variables for debug console logs
const testsToBeExecutedString: string = testsToBeExecuted.join(", ");
@@ -65,41 +87,9 @@ async function runPytestCommand(args: string[]): Promise<SpawnResult> {
}
}

function extractOldDiscoveredTests(output) {
const testNames = [];
let currentPackage = '';
let currentModule = '';
let currentClass = '';

const lines = output.split('\n');

for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();

if (line.startsWith('<Package')) {
currentPackage = line.match(/<Package (.*?)>/)[1];
} else if (line.startsWith('<Module')) {
currentModule = line.match(/<Module (.*?)>/)[1];
} else if (line.startsWith('<UnitTestCase')) {
currentClass = line.match(/<UnitTestCase (.*?)>/)[1];
} else if (line.startsWith('<TestCaseFunction')) {
const functionName = line.match(/<TestCaseFunction (.*?)>/)[1];
let fullyQualifiedName = '';
if (currentPackage !== '') {
fullyQualifiedName += currentPackage + '/';
}
fullyQualifiedName += `${currentModule}::${currentClass}::${functionName}`;
testNames.push(fullyQualifiedName);
}
}
tl.debug("Discovered tests : " + testNames);
return testNames;
}

function extractDiscoveredTests(output: string) {
const testNames = [];

const lines = output.split('\n');
function extractDiscoveredTests(output: string): string[] {
var testNames: string[] = [];
var lines: string[] = output.split('\n');

for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
@@ -111,17 +101,29 @@ function extractDiscoveredTests(output: string) {
return testNames;
}

function transformTestStrings(test: string): string {
// Input is like Folder/SubFolder/TestClass.py::TestSubClass::TestSubSubClass::test_method_name
// Output is lke Folder.SubFolder.TestClass.TestSubClass.TestSubSubClass.test_method_name
function transformTestStrings(automatedTestName: string): string {
// Remove any leading or trailing whitespace
test = test.trim();
automatedTestName = automatedTestName.trim();
let updatedAutomatedTestName: string = automatedTestName;

const index = automatedTestName.indexOf("::");
if(index !== -1) {
let testFilePath = automatedTestName.substring(0, index);
let testMethod = automatedTestName.substring(index + 2);

//Check if testfilePath is a python file
if(testFilePath.endsWith(".py")) {
testFilePath = testFilePath.slice(0, -3).replace(/\//g, '.');

// Replace '.' with '/' for the directory structure
// Replace the last part of the string with '.py'
test = test.replace(/\./g, '/').replace(/\.([^/]+)$/, '.py');
//Do the same replace with :: to . in testMethod
testMethod = testMethod.replace(/::/g, '.');

//Finally generate updatedAutomatedTestName
updatedAutomatedTestName = testFilePath + "." + testMethod;
}
}

// Add the `::` before the test function name
const parts = test.split('/');
const functionName = parts.pop(); // Remove the function name
const testFile = parts.join('/'); // Join back the file path
return `${testFile}.py::${functionName}`; // Format as required
return updatedAutomatedTestName;
}
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0_Node20/task.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 250,
"Patch": 7
"Patch": 9
},
"preview": true,
"demands": [],
@@ -182,8 +182,8 @@
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
},
"_buildConfigMapping": {
"Default": "0.250.6",
"Default": "0.250.8",
"LocalPackages": "0.249.4",
"Node20-225": "0.250.7"
"Node20-225": "0.250.9"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0_Node20/task.loc.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 250,
"Patch": 7
"Patch": 9
},
"preview": true,
"demands": [],
@@ -182,8 +182,8 @@
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
},
"_buildConfigMapping": {
"Default": "0.250.6",
"Default": "0.250.8",
"LocalPackages": "0.249.4",
"Node20-225": "0.250.7"
"Node20-225": "0.250.9"
}
}