Skip to content

Commit fe38869

Browse files
committed
tests: Add binary console test
1 parent 444c8b4 commit fe38869

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/test_command_runner.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
__author__ = "Orsiris de Jong"
1919
__copyright__ = "Copyright (C) 2015-2025 Orsiris de Jong"
2020
__licence__ = "BSD 3 Clause"
21-
__build__ = "2025041801"
21+
__build__ = "2025090901"
2222

2323

2424
import sys
@@ -73,13 +73,17 @@ def timestamp(date):
7373
PING_FAILURE = "ping 0.0.0.0 -n 2 1>&2"
7474

7575
PRINT_FILE_CMD = "type {}".format(TEST_FILENAME)
76+
# On widows, we cannot print binary files to console, type would transliterate it into text
77+
# This is a dummy test on windows
78+
PRINT_BINARY_FILE_CMD = "type C:\\Windows\\System32\\cmd.exe"
7679
else:
7780
ENCODING = "utf-8"
7881
PING_CMD = ["ping", "-c", "4", "127.0.0.1"]
7982
PING_CMD_10S = ["ping", "-c", "10", "127.0.0.1"]
8083
PING_CMD_REDIR = "ping -c 4 127.0.0.1 1>&2"
8184
PING_CMD_AND_FAILURE = "ping -c 2 0.0.0.0 1>&2; ping -c 2 127.0.0.1"
8285
PRINT_FILE_CMD = "cat {}".format(TEST_FILENAME)
86+
PRINT_BINARY_FILE_CMD = "cat /bin/sh"
8387
PING_FAILURE = "ping -c 2 0.0.0.0 1>&2"
8488

8589

@@ -161,6 +165,18 @@ def test_standard_ping_with_encoding_disabled():
161165
assert isinstance(output, bytes), "Output should be binary."
162166

163167

168+
def test_direct_binary_output_to_stdout():
169+
"""
170+
Without encoding disabled, we should have binary output
171+
"""
172+
for method in methods:
173+
exit_code, output = command_runner(PRINT_BINARY_FILE_CMD, encoding=False, method=method)
174+
print(output)
175+
assert (
176+
exit_code == 0
177+
), "Exit code should be 0 for ping command with method {}".format(method)
178+
assert isinstance(output, bytes), "Output should be binary."
179+
164180
def test_timeout():
165181
"""
166182
Test command_runner with a timeout

0 commit comments

Comments
 (0)