From 857b2e87140429a08a25ac48da67da0b3730a8d6 Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Mon, 11 Nov 2024 10:40:21 +0800 Subject: [PATCH 1/5] fix in new cases and update tests in new cases --- .../dotnet/main.py | 3 ++ .../dotnet/test_main.py | 37 ++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/tools/azure-rest-api-specs-examples-automation/dotnet/main.py b/tools/azure-rest-api-specs-examples-automation/dotnet/main.py index d34e0b6f28d..81e0af93a87 100644 --- a/tools/azure-rest-api-specs-examples-automation/dotnet/main.py +++ b/tools/azure-rest-api-specs-examples-automation/dotnet/main.py @@ -99,6 +99,9 @@ def get_dotnet_using_statements(lines: List[str]) -> List[str]: ] for line in lines: if line.startswith("using "): + # ignore the NUnit namespaces if any + if line.startswith("using NUnit."): + continue lines_using_statements.append(line) elif line.startswith("namespace "): # remove the prefix first diff --git a/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py b/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py index 0b8f9e973f5..e5054fad128 100644 --- a/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py +++ b/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py @@ -2,7 +2,11 @@ import parameterized from main import break_down_aggregated_dotnet_example, format_dotnet, get_dotnet_using_statements -file_content = """// Copyright (c) Microsoft Corporation. All rights reserved. +class TestMain(unittest.TestCase): + @parameterized.parameterized.expand( + [ + ( + """// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. // @@ -20,14 +24,15 @@ using Azure.ResourceManager.ContainerInstance.Models; using Azure.ResourceManager.Models; using Azure.ResourceManager.Resources; +using NUnit.Framework; namespace Azure.ResourceManager.ContainerInstance.Samples { public partial class Sample_ContainerGroupCollection { // ContainerGroupsListByResourceGroup - [NUnit.Framework.Test] - [NUnit.Framework.Ignore("Only verifying that the sample builds")] + [Test] + [Ignore("Only verifying that the sample builds")] public async Task GetAll_ContainerGroupsListByResourceGroup() { // Generated from example definition: specification/containerinstance/resource-manager/Microsoft.ContainerInstance/stable/2021-10-01/examples/ContainerGroupsListByResourceGroup.json @@ -324,10 +329,10 @@ } } """ - - -class TestMain(unittest.TestCase): - def test_break_down_aggregated_dotnet_example(self): + ) + ] + ) + def test_break_down_aggregated_dotnet_example(self, file_content: str): lines = file_content.splitlines(keepends=True) examples = break_down_aggregated_dotnet_example(lines) self.assertIsNotNone(examples.class_opening) @@ -356,14 +361,27 @@ def test_break_down_aggregated_dotnet_example(self): using Azure.ResourceManager.Compute.Models; using Azure.ResourceManager.Resources; using Azure.ResourceManager.Resources.Models; +using NUnit.Framework; namespace Azure.ResourceManager.Compute.Samples { -}""" +}""", + [ + "using System;\n", + "using System.Threading.Tasks;\n", + "using Azure;\n", + "using Azure.Core;\n", + "using Azure.Identity;\n", + "using Azure.ResourceManager;\n", + "using Azure.ResourceManager.Compute;\n", + "using Azure.ResourceManager.Compute.Models;\n", + "using Azure.ResourceManager.Resources;\n", + "using Azure.ResourceManager.Resources.Models;\n", + ] ) ] ) - def test_example_usings(self, content: str): + def test_example_usings(self, content: str, expected_usings: list[str]): lines = content.splitlines(keepends=True) usings = get_dotnet_using_statements(lines) @@ -371,3 +389,4 @@ def test_example_usings(self, content: str): self.assertIn("using Azure.Core;\n", usings) self.assertIn("using Azure.ResourceManager;\n", usings) self.assertIn("using Azure.ResourceManager.Compute;\n", usings) + self.assertSetEqual(set(expected_usings), set(usings)) From 38128aa4abeb8ab111d1a9c9ffbd13a51fe6717d Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Mon, 11 Nov 2024 11:01:36 +0800 Subject: [PATCH 2/5] remove useless pieces --- .../dotnet/test_main.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py b/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py index e5054fad128..0c5ee11fdeb 100644 --- a/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py +++ b/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py @@ -384,9 +384,5 @@ def test_break_down_aggregated_dotnet_example(self, file_content: str): def test_example_usings(self, content: str, expected_usings: list[str]): lines = content.splitlines(keepends=True) usings = get_dotnet_using_statements(lines) - - self.assertIn("using Azure;\n", usings) - self.assertIn("using Azure.Core;\n", usings) - self.assertIn("using Azure.ResourceManager;\n", usings) - self.assertIn("using Azure.ResourceManager.Compute;\n", usings) + self.assertSetEqual(set(expected_usings), set(usings)) From 90af2c39f2f0f8f7737a5652b1fb61ec24a6257c Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Mon, 11 Nov 2024 11:25:03 +0800 Subject: [PATCH 3/5] update code --- .../azure-rest-api-specs-examples-automation/dotnet/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/azure-rest-api-specs-examples-automation/dotnet/main.py b/tools/azure-rest-api-specs-examples-automation/dotnet/main.py index 81e0af93a87..fcde732db4c 100644 --- a/tools/azure-rest-api-specs-examples-automation/dotnet/main.py +++ b/tools/azure-rest-api-specs-examples-automation/dotnet/main.py @@ -98,10 +98,10 @@ def get_dotnet_using_statements(lines: List[str]) -> List[str]: "using Azure.ResourceManager;\n", ] for line in lines: - if line.startswith("using "): + if line.startsWith("using NUnit."): # ignore the NUnit namespaces if any - if line.startswith("using NUnit."): - continue + pass + elif line.startswith("using "): lines_using_statements.append(line) elif line.startswith("namespace "): # remove the prefix first From 47bfa3a271f9991e81af2d71a6161e5fa713e797 Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Mon, 11 Nov 2024 11:32:51 +0800 Subject: [PATCH 4/5] fix test cases --- .../dotnet/test_main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py b/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py index 0c5ee11fdeb..0ff3b5388b0 100644 --- a/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py +++ b/tools/azure-rest-api-specs-examples-automation/dotnet/test_main.py @@ -1,6 +1,7 @@ import unittest import parameterized from main import break_down_aggregated_dotnet_example, format_dotnet, get_dotnet_using_statements +from typing import List class TestMain(unittest.TestCase): @parameterized.parameterized.expand( @@ -381,7 +382,7 @@ def test_break_down_aggregated_dotnet_example(self, file_content: str): ) ] ) - def test_example_usings(self, content: str, expected_usings: list[str]): + def test_example_usings(self, content: str, expected_usings: List[str]): lines = content.splitlines(keepends=True) usings = get_dotnet_using_statements(lines) From d86355fc70c39f7381fbe9e51555f9e115e83277 Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Mon, 11 Nov 2024 12:50:18 +0800 Subject: [PATCH 5/5] fix typo --- tools/azure-rest-api-specs-examples-automation/dotnet/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/azure-rest-api-specs-examples-automation/dotnet/main.py b/tools/azure-rest-api-specs-examples-automation/dotnet/main.py index fcde732db4c..f219c088ea3 100644 --- a/tools/azure-rest-api-specs-examples-automation/dotnet/main.py +++ b/tools/azure-rest-api-specs-examples-automation/dotnet/main.py @@ -98,7 +98,7 @@ def get_dotnet_using_statements(lines: List[str]) -> List[str]: "using Azure.ResourceManager;\n", ] for line in lines: - if line.startsWith("using NUnit."): + if line.startswith("using NUnit."): # ignore the NUnit namespaces if any pass elif line.startswith("using "):