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

Updates to dotnet example automation for recent changes on dotnet side #9359

Merged
merged 5 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +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
pass
elif line.startswith("using "):
lines_using_statements.append(line)
elif line.startswith("namespace "):
# remove the prefix first
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import unittest
import parameterized
from main import break_down_aggregated_dotnet_example, format_dotnet, get_dotnet_using_statements
from typing import List

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.

// <auto-generated/>
Expand All @@ -20,14 +25,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")]
ArcturusZhang marked this conversation as resolved.
Show resolved Hide resolved
public async Task GetAll_ContainerGroupsListByResourceGroup()
{
// Generated from example definition: specification/containerinstance/resource-manager/Microsoft.ContainerInstance/stable/2021-10-01/examples/ContainerGroupsListByResourceGroup.json
Expand Down Expand Up @@ -324,10 +330,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)
Expand Down Expand Up @@ -356,18 +362,28 @@ 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)

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))