-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tidy up exec.py, rename to subprocess.py
We never exec anyway so _KART_NO_EXEC is confusing. But we do still need to do subprocess.run slightly differently during tests, unless we figure out a better way to capture output. This makes the names of things more in line with how they work, and makes calls to kart/subprocess.py look and work identically to calls to subprocess (until we turn on _KART_TEST). (Ideally we would get rid of _KART_TEST and use fd-capturing, but this will take a bit more expertise. However, this still gets us a tiny bit closer to that goal).
- Loading branch information
Showing
6 changed files
with
69 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
import sys | ||
import subprocess as s | ||
from subprocess import * # noqa | ||
|
||
|
||
# kart.subprocess works exactly like subprocess unless the _KART_TEST environment variable is set. | ||
# In that case, kart.subprocess.run is actually run_for_test which makes sure the subprocess output | ||
# passes through sys.stdout and sys.stderr and is captured by CliRunner. | ||
|
||
|
||
def run(*args, **kwargs): | ||
if "_KART_TEST" in os.environ: | ||
return run_for_test(*args, **kwargs) | ||
else: | ||
return s.run(*args, **kwargs) | ||
|
||
|
||
def run_for_test(*args, **kwargs): | ||
# Don't do this if we're doing anything complicated: | ||
if "stdout" in kwargs or "stderr" in kwargs or "capture_output" in kwargs: | ||
return s.run(*args, **kwargs) | ||
|
||
# Helps CliRunner capture subprocess output during testing. This is pretty hacky. | ||
# TODO - find out if there's a better way to let CliRunner capture subprocess output. | ||
p = s.run(*args, **kwargs, capture_output=True, encoding="utf-8") | ||
sys.stdout.write(p.stdout) | ||
sys.stdout.flush() | ||
sys.stderr.write(p.stderr) | ||
sys.stderr.flush() | ||
return p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters