Skip to content

Commit

Permalink
address the stringio getvalue not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
feng-j678 committed Oct 23, 2024
1 parent 82f45bb commit 8bf1403
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/core/tests/Test_ConfigurePatchingProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
import re
import unittest
import sys
from io import StringIO
# Conditional import for StringIO
try:
from StringIO import StringIO # Python 2
except ImportError:
from io import StringIO # Python 3

from core.src.CoreMain import CoreMain
from core.src.bootstrap.Constants import Constants
Expand Down Expand Up @@ -317,6 +321,7 @@ def test_configure_patching_with_patch_mode_and_assessment_mode_by_platform(self
def test_configure_patching_raise_exception_auto_os_patch_state(self):
# arrange capture std IO
captured_output = StringIO()
original_stdout = sys.stdout
sys.stdout = captured_output

argument_composer = ArgumentComposer()
Expand All @@ -334,7 +339,7 @@ def test_configure_patching_raise_exception_auto_os_patch_state(self):
runtime.configure_patching_processor.start_configure_patching()

# restore sdt.out ouptput
sys.stdout = sys.__stdout__
sys.stdout = original_stdout

# assert
output = captured_output.getvalue()
Expand Down
10 changes: 8 additions & 2 deletions src/core/tests/Test_MaintenanceWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
# Requires Python 2.7+

import datetime
from io import StringIO
import sys
# Conditional import for StringIO
try:
from StringIO import StringIO # Python 2
except ImportError:
from io import StringIO # Python 3
import unittest
from core.tests.library.ArgumentComposer import ArgumentComposer
from core.tests.library.RuntimeCompositor import RuntimeCompositor


class TestMaintenanceWindow(unittest.TestCase):
def setUp(self):
pass
Expand Down Expand Up @@ -67,6 +72,7 @@ def test_RemainingTime_after_duration_complete(self):
def test_RemainingTime_log_to_stdout_true(self):
# Arrange, Capture stdout
captured_output = StringIO()
original_output = sys.stdout
sys.stdout = captured_output # Redirect stdout to the StringIO object

argument_composer = ArgumentComposer()
Expand All @@ -78,7 +84,7 @@ def test_RemainingTime_log_to_stdout_true(self):
remaining_time = runtime.maintenance_window.get_remaining_time_in_minutes(current_time, log_to_stdout=True)

# Restore stdout
sys.stdout = sys.__stdout__
sys.stdout = original_output

# Assert
output = captured_output.getvalue()
Expand Down

0 comments on commit 8bf1403

Please sign in to comment.