Add tests for example commands
This commit is contained in:
parent
7b5b8b4d06
commit
1d7d2d8446
19
test/test_example_cmd.py
Normal file
19
test/test_example_cmd.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from psh import echo, example
|
||||||
|
from utils import TestFormatter
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def test_formatter():
|
||||||
|
return TestFormatter()
|
||||||
|
|
||||||
|
|
||||||
|
def test_example_cmd_should_return_two_things(test_formatter):
|
||||||
|
example.chain(test_formatter).call()
|
||||||
|
assert "examplecommand" == test_formatter.get_data()
|
||||||
|
|
||||||
|
|
||||||
|
def test_echo_should_echo(test_formatter):
|
||||||
|
example.chain(echo).chain(test_formatter).call()
|
||||||
|
assert "examplecommand" == test_formatter.get_data()
|
18
test/utils.py
Normal file
18
test/utils.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from psh.commands import BaseCommand
|
||||||
|
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
class TestFormatter(BaseCommand):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(TestFormatter, self).__init__(*args, **kwargs)
|
||||||
|
self.buffer = StringIO()
|
||||||
|
|
||||||
|
def call(self):
|
||||||
|
input_generator = self.get_input_generator()
|
||||||
|
for line in input_generator:
|
||||||
|
self.buffer.write(line.decode('utf-8'))
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
return self.buffer.getvalue()
|
Reference in New Issue
Block a user