Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sys | ||
|
||
|
||
def sed_replace(filename: str) -> None: | ||
# NOTE: this function is used by 'test_edit_run' to provide a cross-platform | ||
# way to edit a file that the test can later recognize and see it was called | ||
with open(filename) as fd: | ||
contents = "\n".join([ | ||
line.replace("title: ", "title: test_edit") for line in fd | ||
]) | ||
|
||
with open(filename, "w") as fd: | ||
fd.write(contents) | ||
|
||
|
||
def echo(filename: str) -> None: | ||
# NOTE: this function is used by 'test_open_run' to provide a cross-platform | ||
# custom command that shows it tried to open a file | ||
print("Attempted to open '{}'".format(filename)) | ||
|
||
|
||
if __name__ == "__main__": | ||
cmd, filename = sys.argv[-2:] | ||
|
||
try: | ||
ret = 0 | ||
if cmd == "sed": | ||
sed_replace(filename) | ||
elif cmd == "echo": | ||
echo(filename) | ||
else: | ||
ret = 1 | ||
except Exception: | ||
ret = 1 | ||
|
||
raise SystemExit(ret) |
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