From 1d7d2d84463ed16dd19e823b7d61865b96f79615 Mon Sep 17 00:00:00 2001 From: Ian Adam Naval Date: Thu, 26 Feb 2015 18:08:01 -0500 Subject: [PATCH] Add tests for example commands --- test/test_example_cmd.py | 19 +++++++++++++++++++ test/utils.py | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test/test_example_cmd.py create mode 100644 test/utils.py diff --git a/test/test_example_cmd.py b/test/test_example_cmd.py new file mode 100644 index 0000000..8b24b18 --- /dev/null +++ b/test/test_example_cmd.py @@ -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() diff --git a/test/utils.py b/test/utils.py new file mode 100644 index 0000000..6c73571 --- /dev/null +++ b/test/utils.py @@ -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()