Skip to content

Commit

Permalink
Fix nondeterministic text wrapping in tests.
Browse files Browse the repository at this point in the history
Previously, some tests depended on the terminal they're run in being a certain width.
  • Loading branch information
wolverdude committed May 14, 2024
1 parent bf82aa8 commit f158175
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions test/test_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ def stderr_message(message):
return '{}\ngenson: error: {}\n'.format(SHORT_USAGE, message)


def run(args=[], stdin_data=None):
def run(args=tuple(), stdin_data=None):
"""
Run the ``genson`` executable as a subprocess and return
(stdout, stderr).
"""
full_args = ['python', '-m', 'genson']
full_args.extend(args)
env = os.environ.copy()
env['COLUMNS'] = '80' # set width for deterministic text wrapping

genson_process = Popen(
['python', '-m', 'genson'] + args, stdout=PIPE, stderr=PIPE,
full_args, env=env, stdout=PIPE, stderr=PIPE,
stdin=PIPE if stdin_data is not None else None)
if stdin_data is not None:
stdin_data = stdin_data.encode('utf-8')
(stdout, stderr) = genson_process.communicate(stdin_data)
genson_process.wait()

if isinstance(stdout, bytes):
stdout = stdout.decode('utf-8')
if isinstance(stderr, bytes):
Expand Down

0 comments on commit f158175

Please sign in to comment.