-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add pipe_once special command #193
Merged
+131
−14
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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,59 @@ | ||
import os | ||
import tempfile | ||
|
||
import pytest | ||
|
||
import litecli.packages.special | ||
|
||
|
||
def test_once_command(): | ||
with pytest.raises(TypeError): | ||
litecli.packages.special.execute(None, ".once") | ||
|
||
with pytest.raises(OSError): | ||
litecli.packages.special.execute(None, ".once /proc/access-denied") | ||
|
||
litecli.packages.special.write_once("hello world") # write without file set | ||
# keep Windows from locking the file with delete=False | ||
with tempfile.NamedTemporaryFile(delete=False) as f: | ||
litecli.packages.special.execute(None, ".once " + f.name) | ||
litecli.packages.special.write_once("hello world") | ||
if os.name == "nt": | ||
assert f.read() == b"hello world\r\n" | ||
else: | ||
assert f.read() == b"hello world\n" | ||
|
||
litecli.packages.special.execute(None, ".once -o " + f.name) | ||
litecli.packages.special.write_once("hello world line 1") | ||
litecli.packages.special.write_once("hello world line 2") | ||
f.seek(0) | ||
if os.name == "nt": | ||
assert f.read() == b"hello world line 1\r\nhello world line 2\r\n" | ||
else: | ||
assert f.read() == b"hello world line 1\nhello world line 2\n" | ||
# delete=False means we should try to clean up | ||
try: | ||
if os.path.exists(f.name): | ||
os.remove(f.name) | ||
except Exception as e: | ||
print(f"An error occurred while attempting to delete the file: {e}") | ||
|
||
|
||
def test_pipe_once_command(): | ||
with pytest.raises(IOError): | ||
litecli.packages.special.execute(None, "\\pipe_once") | ||
|
||
with pytest.raises(OSError): | ||
litecli.packages.special.execute(None, "\\pipe_once /proc/access-denied") | ||
|
||
if os.name == "nt": | ||
litecli.packages.special.execute(None, '\\pipe_once python -c "import sys; print(len(sys.stdin.read().strip()))"') | ||
litecli.packages.special.write_pipe_once("hello world") | ||
litecli.packages.special.unset_pipe_once_if_written() | ||
else: | ||
with tempfile.NamedTemporaryFile() as f: | ||
litecli.packages.special.execute(None, "\\pipe_once tee " + f.name) | ||
litecli.packages.special.write_pipe_once("hello world") | ||
litecli.packages.special.unset_pipe_once_if_written() | ||
f.seek(0) | ||
assert f.read() == b"hello world\n" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this up from mycli, using
tee
to write the output to a file which can then be checked. But I did notice around here that mycli is using write_once in this test instead of write_pipe_once.