Skip to content

Commit

Permalink
Fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ReaNAiveD committed Mar 12, 2025
1 parent ebbc7c8 commit f209cca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/azure-cli-core/azure/cli/core/breaking_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ def version(self):
class NextBreakingChangeWindow(TargetVersion):
def __str__(self):
next_breaking_change_version = _next_breaking_change_version()
message = 'in next breaking change release'
if next_breaking_change_version:
return f'in next breaking change release({next_breaking_change_version}) scheduled for {NEXT_BREAKING_CHANGE_DATE}'
return 'in next breaking change release'
message += f'({next_breaking_change_version})'
if NEXT_BREAKING_CHANGE_DATE:
message += f' scheduled for {NEXT_BREAKING_CHANGE_DATE}'
return message

def version(self):
return _next_breaking_change_version()
Expand Down
21 changes: 14 additions & 7 deletions src/azure-cli-core/azure/cli/core/tests/test_breaking_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ def test_command_deprecate(self):
self.assertIn('[Deprecated]', captured_output.getvalue())

@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_RELEASE', '3.0.0')
@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_DATE', 'May 2024')
def test_argument_deprecate(self):
from contextlib import redirect_stderr, redirect_stdout

from azure.cli.core.breaking_change import register_argument_deprecate

register_argument_deprecate('test group cmd', argument='arg1', redirect='arg2')
warning = ("Argument 'arg1' has been deprecated and will be removed in next breaking change release(3.0.0). "
"Use 'arg2' instead.")
warning = ("Argument 'arg1' has been deprecated and will be removed in next breaking change release(3.0.0) "
"scheduled for May 2024. Use 'arg2' instead.")
cli = DummyCli(commands_loader_cls=TestCommandsLoader)

captured_err = io.StringIO()
Expand All @@ -156,14 +157,15 @@ def test_argument_deprecate(self):
self.assertIn('[Deprecated]', captured_output.getvalue())

@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_RELEASE', '3.0.0')
@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_DATE', 'May 2024')
def test_option_deprecate(self):
from contextlib import redirect_stderr, redirect_stdout

from azure.cli.core.breaking_change import register_argument_deprecate

register_argument_deprecate('test group cmd', argument='--arg1', redirect='--arg1-alias')
warning = ("Option '--arg1' has been deprecated and will be removed in next breaking change release(3.0.0). "
"Use '--arg1-alias' instead.")
warning = ("Option '--arg1' has been deprecated and will be removed in next breaking change release(3.0.0) "
"scheduled for May 2024. Use '--arg1-alias' instead.")
cli = DummyCli(commands_loader_cls=TestCommandsLoader)

captured_err = io.StringIO()
Expand All @@ -180,6 +182,7 @@ def test_option_deprecate(self):
self.assertIn(' --arg1 [Deprecated]', captured_output.getvalue())

@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_RELEASE', '3.0.0')
@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_DATE', None)
def test_be_required(self):
from contextlib import redirect_stderr, redirect_stdout

Expand Down Expand Up @@ -207,6 +210,7 @@ def test_be_required(self):
self.assertIn('[Breaking Change]', captured_output.getvalue())

@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_RELEASE', '3.0.0')
@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_DATE', None)
def test_default_change(self):
from contextlib import redirect_stderr, redirect_stdout

Expand Down Expand Up @@ -236,15 +240,16 @@ def test_default_change(self):
self.assertIn('[Breaking Change]', captured_output.getvalue())

@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_RELEASE', '3.0.0')
@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_DATE', 'May 2024')
def test_output_change(self):
from contextlib import redirect_stderr, redirect_stdout

from azure.cli.core.breaking_change import register_output_breaking_change

register_output_breaking_change('test group cmd', description="The output of 'test group cmd' "
"would be changed.")
warning = ("The output will be changed in next breaking change release(3.0.0). The output of 'test group cmd' "
"would be changed.")
warning = ("The output will be changed in next breaking change release(3.0.0) scheduled for May 2024. "
"The output of 'test group cmd' would be changed.")
cli = DummyCli(commands_loader_cls=TestCommandsLoader)

captured_err = io.StringIO()
Expand All @@ -265,13 +270,14 @@ def test_output_change(self):
self.assertIn('[Breaking Change]', captured_output.getvalue())

@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_RELEASE', '3.0.0')
@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_DATE', 'May 2024')
def test_logic_change(self):
from contextlib import redirect_stderr, redirect_stdout

from azure.cli.core.breaking_change import register_logic_breaking_change

register_logic_breaking_change('test group cmd', summary="Logic Change Summary")
warning = "Logic Change Summary in next breaking change release(3.0.0)."
warning = "Logic Change Summary in next breaking change release(3.0.0) scheduled for May 2024."
cli = DummyCli(commands_loader_cls=TestCommandsLoader)

captured_err = io.StringIO()
Expand All @@ -292,6 +298,7 @@ def test_logic_change(self):
self.assertIn('[Breaking Change]', captured_output.getvalue())

@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_RELEASE', '3.0.0')
@mock.patch('azure.cli.core.breaking_change.NEXT_BREAKING_CHANGE_DATE', None)
def test_multi_breaking_change(self):
from contextlib import redirect_stderr, redirect_stdout

Expand Down

0 comments on commit f209cca

Please sign in to comment.