Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
set_background_color = MagicMock(return_value=None)
set_cursor_position = MagicMock(return_value=None)
set_window_position = MagicMock(return_value=None)
set_cursor_size = MagicMock(return_value=None)
set_buffer_size = MagicMock(return_value=None)
set_window_size = MagicMock(return_value=None)
set_window_title = MagicMock(return_value=None)
read_key = MagicMock(return_value=key_info)
flush_input = MagicMock(return_value=None)
set_buffer1 = MagicMock(return_value=None)
set_buffer2 = MagicMock(return_value=None)
scroll_buffer = MagicMock(return_value=None)
window_title = "pypsrp window"
cursor_size = 50
foreground_color = Color(value=Color.WHITE)
background_color = Color(value=Color.BLUE)
cursor_position = Coordinates(x=1, y=2)
window_position = Coordinates(x=3, y=4)
buffer_size = Size(width=80, height=80)
max_physical_window_size = Size(width=80, height=80)
max_window_size = Size(width=80, height=80)
window_size = Size(width=80, height=80)
host_raw_ui = PSHostRawUserInterface(window_title, cursor_size,
foreground_color,
background_color, cursor_position,
window_position, buffer_size,
max_physical_window_size,
max_window_size, window_size)
host_raw_ui.SetForegroundColor = set_foreground_color
host_raw_ui.SetBackgroundColor = set_background_color
def test_create_buffer_cell(self):
serializer = Serializer()
buffer_cell = BufferCell(
character="A", foreground_color=Color(value=Color.CYAN),
background_color=Color(value=Color.GREEN),
cell_type=BufferCellType.COMPLETE
)
expected_xml = normalise_xml(self.BUFFER_CELL)
actual = serializer.serialize(buffer_cell)
actual_xml = normalise_xml(ET.tostring(actual))
assert_xml_diff(actual_xml, expected_xml)
assert len(actual) == 17
assert str(actual[0]) == "White"
assert str(actual[1]) == "Green"
assert set_foreground_color.call_count == 1
assert isinstance(set_foreground_color.call_args[0][0], RunspacePool)
assert isinstance(set_foreground_color.call_args[0][1], PowerShell)
assert set_foreground_color.call_args[0][2] == Color.GREEN
assert str(actual[2]) == "Blue"
assert str(actual[3]) == "Red"
assert set_background_color.call_count == 1
assert isinstance(set_background_color.call_args[0][0], RunspacePool)
assert isinstance(set_background_color.call_args[0][1], PowerShell)
assert set_background_color.call_args[0][2] == Color.RED
assert str(actual[4]) == "1,2"
assert str(actual[5]) == "11,12"
assert set_cursor_position.call_count == 1
assert isinstance(set_cursor_position.call_args[0][0], RunspacePool)
assert isinstance(set_cursor_position.call_args[0][1], PowerShell)
assert set_cursor_position.call_args[0][2].extended_properties['x'] \
== 11
assert set_cursor_position.call_args[0][2].extended_properties['y'] \
== 12
assert str(actual[6]) == "3,4"
assert str(actual[7]) == "13,14"
assert set_window_position.call_count == 1
assert isinstance(set_window_position.call_args[0][0], RunspacePool)
assert isinstance(set_window_position.call_args[0][1], PowerShell)
$cells[0,1] = $buffer_cell1_2
$cells[1,1] = $buffer_cell2_2
$cells[1,0] = $buffer_cell2_1
$host.UI.RawUI.SetBufferContents($coordinates, $cells)
$host.UI.RawUI.ScrollBufferContents($rectangle, $coordinates, $rectangle, $buffer_cell)''')
actual = ps.invoke()
assert len(actual) == 17
assert str(actual[0]) == "White"
assert str(actual[1]) == "Green"
assert set_foreground_color.call_count == 1
assert isinstance(set_foreground_color.call_args[0][0], RunspacePool)
assert isinstance(set_foreground_color.call_args[0][1], PowerShell)
assert set_foreground_color.call_args[0][2] == Color.GREEN
assert str(actual[2]) == "Blue"
assert str(actual[3]) == "Red"
assert set_background_color.call_count == 1
assert isinstance(set_background_color.call_args[0][0], RunspacePool)
assert isinstance(set_background_color.call_args[0][1], PowerShell)
assert set_background_color.call_args[0][2] == Color.RED
assert str(actual[4]) == "1,2"
assert str(actual[5]) == "11,12"
assert set_cursor_position.call_count == 1
assert isinstance(set_cursor_position.call_args[0][0], RunspacePool)
assert isinstance(set_cursor_position.call_args[0][1], PowerShell)
assert set_cursor_position.call_args[0][2].extended_properties['x'] \
== 11
assert set_cursor_position.call_args[0][2].extended_properties['y'] \
assert actual[1] == "ReadLineAsSecureString response"
assert mock_read_line_as_ss.call_count == 1
assert isinstance(mock_read_line_as_ss.call_args[0][0],
RunspacePool)
assert isinstance(mock_read_line_as_ss.call_args[0][1], PowerShell)
assert mock_write1.call_count == 1
assert isinstance(mock_write1.call_args[0][0], RunspacePool)
assert isinstance(mock_write1.call_args[0][1], PowerShell)
assert mock_write1.call_args[0][2] == "Write1"
assert mock_write2.call_count == 1
assert isinstance(mock_write2.call_args[0][0], RunspacePool)
assert isinstance(mock_write2.call_args[0][1], PowerShell)
assert mock_write2.call_args[0][2] == Color.BLUE
assert mock_write2.call_args[0][3] == Color.WHITE
assert mock_write2.call_args[0][4] == "Write2"
assert mock_write_line1.call_count == 1
assert isinstance(mock_write_line1.call_args[0][0], RunspacePool)
assert isinstance(mock_write_line1.call_args[0][1], PowerShell)
assert mock_write_line2.call_count == 1
assert isinstance(mock_write_line2.call_args[0][0], RunspacePool)
assert isinstance(mock_write_line2.call_args[0][1], PowerShell)
assert mock_write_line2.call_args[0][2] == "WriteLine2"
assert mock_write_line3.call_count == 1
assert isinstance(mock_write_line3.call_args[0][0], RunspacePool)
assert isinstance(mock_write_line3.call_args[0][1], PowerShell)
assert mock_write_line3.call_args[0][2] == Color.GRAY
def test_parse_buffer_cell(self):
serializer = Serializer()
actual = serializer.deserialize(normalise_xml(self.BUFFER_CELL),
ObjectMeta("Obj", object=BufferCell))
assert actual.character == "A"
assert actual.foreground_color.value == Color.CYAN
assert actual.background_color.value == Color.GREEN
assert actual.cell_type == BufferCellType.COMPLETE
def test_create_host_info(self):
serializer = Serializer()
foreground_color = Color(value=Color.CYAN)
background_color = Color(value=Color.RED)
cursor_position = Coordinates(x=1, y=2)
window_position = Coordinates(x=3, y=4)
cursor_size = 10
buffer_size = Size(height=10, width=20)
window_size = Size(height=30, width=40)
max_window_size = Size(height=50, width=60)
max_physical_window_size = Size(height=70, width=80)
window_title = "Random Window Title"
ps_raw_ui = PSHostRawUserInterface(
window_title, cursor_size, foreground_color, background_color,
cursor_position, window_position, buffer_size,
max_physical_window_size, max_window_size, window_size
)
ps_ui = PSHostUserInterface(raw_ui=ps_raw_ui)
2: "DarkGreen",
3: "DarkCyan",
4: "DarkRed",
5: "DarkMagenta",
6: "DarkYellow",
7: "Gray",
8: "DarkGray",
9: "Blue",
10: "Green",
11: "Cyan",
12: "Red",
13: "Magenta",
14: "Yellow",
15: "White",
}
super(Color, self).__init__("System.ConsoleColor", string_map,
**kwargs)
"System.Management.Automation.Runspaces.ApartmentState":
ObjectMeta("Obj", object=ApartmentState),
"System.Management.Automation.Runspaces.PipelineResultTypes":
ObjectMeta("Obj", object=PipelineResultTypes),
"System.Management.Automation.Runspaces.PSThreadOptions":
ObjectMeta("Obj", object=PSThreadOptions),
"System.Management.Automation.Runspaces.RemoteStreamOptions":
ObjectMeta("Obj", object=RemoteStreamOptions),
"System.Management.Automation.VerboseRecord":
ObjectMeta("Obj", object=VerboseRecord),
"System.Management.Automation.WarningRecord":
ObjectMeta("Obj", object=WarningRecord),
"System.Collections.Hashtable": DictionaryMeta(),
"System.Collections.Queue": QueueMeta(),
"System.Collections.Stack": StackMeta(),
"System.ConsoleColor": ObjectMeta("Obj", object=Color),
# Fallback to the GenericComplexObject
"System.Object":
ObjectMeta("ObjDynamic", object=GenericComplexObject),
# Primitive types
"System.String": ObjectMeta("S"),
"System.Char": ObjectMeta("C"),
"System.Boolean": ObjectMeta("B"),
"System.DateTime": ObjectMeta("DT"),
# None: ObjectMeta("TS"), # duration timespan
"System.Byte": ObjectMeta("By"),
"System.SByte": ObjectMeta("SB"),
"System.UInt16": ObjectMeta("U16"),
"System.Int16": ObjectMeta("I16"),
"System.UInt32": ObjectMeta("U32"),
def SetBackgroundColor(self, runspace, pipeline, color):
"""
MI: 30
SHOULD set the background color of the hosting application.
:param runspace: The runspace the host call relates to
:param pipeline: The pipeline (if any) that the call relates to
:param color: The int value for pypsrp.complex_objects.Color to set
"""
self.background_color = Color(value=color)