Skip to content

Updating code_utils.py to solve issue #1747 #1758

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

Merged
merged 26 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6a66ca9
Update code_utils.py
abhaymathur21 Feb 17, 2024
080c1ed
Merge branch 'main' into main
abhaymathur21 Feb 17, 2024
324346a
Update code_utils.py
abhaymathur21 Feb 17, 2024
e670c08
Update local_commandline_code_executor.py
abhaymathur21 Feb 17, 2024
6237dc0
Merge branch 'main' into main
abhaymathur21 Feb 17, 2024
ac5b1da
Update autogen/coding/local_commandline_code_executor.py
abhaymathur21 Feb 17, 2024
708acd9
Update code_utils.py
abhaymathur21 Feb 18, 2024
ab90126
Update code_utils.py
abhaymathur21 Feb 18, 2024
3266c41
Merge branch 'main' into main
abhaymathur21 Feb 18, 2024
1743f90
Merge branch 'main' into main
abhaymathur21 Feb 18, 2024
5aa8998
Update code_utils.py
abhaymathur21 Feb 18, 2024
42c8fa0
Update code_utils.py
abhaymathur21 Feb 18, 2024
56072de
Update and rename test_code.py to test_code_utils.py
abhaymathur21 Feb 18, 2024
f127ccf
Merge remote-tracking branch 'upstream/main'
abhaymathur21 Feb 19, 2024
645636d
Update test_code_utils.py
abhaymathur21 Feb 19, 2024
8c1d931
Update test_code_utils.py
abhaymathur21 Feb 19, 2024
b5df8aa
Merge branch 'main' into main
abhaymathur21 Feb 19, 2024
247d6c2
Update autogen/code_utils.py
abhaymathur21 Feb 19, 2024
a874723
Merge branch 'microsoft:main' into main
abhaymathur21 Feb 22, 2024
59264e0
solved issue #1747
abhaymathur21 Feb 22, 2024
f998ed4
updated unit test
abhaymathur21 Feb 22, 2024
50c40f9
fixed formatting
abhaymathur21 Feb 22, 2024
b613347
fixed formatting
abhaymathur21 Feb 22, 2024
094a3c1
fixed formatting
abhaymathur21 Feb 22, 2024
6edae9a
fixed a bug
abhaymathur21 Feb 22, 2024
eff220a
removed extra return None and removed redundant comments
abhaymathur21 Feb 22, 2024
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
3 changes: 2 additions & 1 deletion autogen/code_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ def get_powershell_command():
return "pwsh"

except FileNotFoundError:
print("Neither powershell nor pwsh is installed.")
if WIN32:
logging.warning("Neither powershell nor pwsh is installed but it is a Windows OS")
return None


Expand Down
22 changes: 13 additions & 9 deletions test/test_code_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,20 +575,24 @@ def test_get_powershell_command_pwsh(self, mock_subprocess_run):
self.assertEqual(get_powershell_command(), "pwsh")

@patch("subprocess.run")
def test_get_powershell_command_no_shell(self, mock_subprocess_run):
@patch("logging.warning")
def test_get_powershell_command_windows_no_shell(self, mock_logging_warning, mock_subprocess_run):
# Set up the mock to simulate 'powershell' and 'pwsh' not found
mock_subprocess_run.side_effect = [FileNotFoundError, FileNotFoundError]

with patch("sys.stdout", new=StringIO()) as fake_out:
get_powershell_command()
self.assertEqual(fake_out.getvalue().strip(), "Neither powershell nor pwsh is installed.")
with patch("autogen.code_utils.WIN32", True):
self.assertIsNone(get_powershell_command())
mock_logging_warning.assert_called_once_with(
"Neither powershell nor pwsh is installed but it is a Windows OS"
)

@patch("subprocess.run")
def test_get_powershell_command_no_shell_no_output(self, mock_subprocess_run):
# Set up the mock to simulate 'powershell' and 'pwsh' not found without printing error message
mock_subprocess_run.side_effect = [FileNotFoundError, FileNotFoundError]

self.assertIsNone(get_powershell_command())
def test_get_powershell_command_no_windows_no_shell(self, mock_subprocess_run):
# Set up the mock to simulate 'powershell' and 'pwsh' not found
mock_subprocess_run.side_effect = FileNotFoundError
# Mock WIN32 to False
with patch("autogen.code_utils.WIN32", False):
self.assertIsNone(get_powershell_command())


if __name__ == "__main__":
Expand Down
Loading