How to test input via subprocess.Popen with data from file
Loris Bennett
loris.bennett at fu-berlin.de
Thu Mar 10 07:16:11 EST 2022
Hi,
I have a command which produces output like the
following:
Job ID: 9431211
Cluster: curta
User/Group: build/staff
State: COMPLETED (exit code 0)
Nodes: 1
Cores per node: 8
CPU Utilized: 01:30:53
CPU Efficiency: 83.63% of 01:48:40 core-walltime
Job Wall-clock time: 00:13:35
Memory Utilized: 6.45 GB
Memory Efficiency: 80.68% of 8.00 GB
I want to parse this and am using subprocess.Popen and accessing the
contents via Popen.stdout. However, for testing purposes I want to save
various possible outputs of the command as text files and use those as
inputs.
What format should I use to pass data to the actual parsing function?
I could in both production and test convert the entire input to a string
and pass the string to the parsing method.
However, I could use something like
test_input_01 = subprocess.Popen(
["cat test_input_01.txt"],
stdout=subprocess.PIPE,
)
for the test input and then pass a Popen object to the parsing function.
Any comments on these alternative or suggestions for doing something
completely different?
Cheers,
Loris
--
This signature is currently under construction.
More information about the Python-list
mailing list