Skip to content

Commit 76f6eb7

Browse files
committed
tests: Count bytes written in stdio_test.StdIOTest
This is mainly for peace of mind. With all this non-blocking IO investigation I'm getting a bit paranoid wrt file objects. refs #712
1 parent 3dfaf83 commit 76f6eb7

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ In progress (unreleased)
2424
* :gh:issue:`1306` CI: Report sudo version on Ansible targets
2525
* :gh:issue:`1306` CI: Move sudo test users defaults into ``/etc/sudoers.d``
2626
* :gh:issue:`1306` preamble_size: Fix variability of measured command size
27+
* :gh:issue:`1306` tests: Count bytes written in ``stdio_test.StdIOTest``
2728

2829

2930
v0.3.27 (2025-08-20)

tests/data/stdio_checks.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@
33
import sys
44

55

6+
def _shout_stdout_py3(size):
7+
nwritten = sys.stdout.write('A' * size)
8+
return nwritten
9+
10+
11+
def _shout_stdout_py2(size):
12+
shout = 'A' * size
13+
nwritten = 0
14+
while nwritten < size:
15+
nwritten += os.write(sys.stdout.fileno(), shout[-nwritten:])
16+
return nwritten
17+
18+
619
def shout_stdout(size):
7-
sys.stdout.write('A' * size)
8-
return 'success'
20+
if sys.version_info > (3, 0):
21+
return _shout_stdout_py3(size)
22+
else:
23+
return _shout_stdout_py2(size)
924

1025

1126
def file_is_blocking(fobj):

tests/stdio_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def test_can_write_stdout_1_mib(self):
1515
"""
1616
size = 1 * 2**20
1717
context = self.router.local()
18-
result = context.call(stdio_checks.shout_stdout, size)
19-
self.assertEqual('success', result)
18+
nwritten = context.call(stdio_checks.shout_stdout, size)
19+
self.assertEqual(nwritten, size)
2020

2121
def test_stdio_is_blocking(self):
2222
context = self.router.local()

0 commit comments

Comments
 (0)