Skip to content
Merged
Show file tree
Hide file tree
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
fix in new cases and update tests in new cases
  • Loading branch information
ArcturusZhang committed Nov 11, 2024
commit 857b2e87140429a08a25ac48da67da0b3730a8d6
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

// <auto-generated/>
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -356,18 +361,32 @@ 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))