import tempfile
import StringIO

import pytest

from shelltest.shelltest import ShellTest, ShellTestSource, ShellTestRunner


@pytest.fixture
def tests():
    return [ShellTest('echo hello', 'hello\n', ShellTestSource('', 0)),
            ShellTest('echo $?', '0\n', ShellTestSource('', 2))]


def test_run(tests):
    r = ShellTestRunner(tests)
    results = r.run()
    assert len(results) == 2
    assert results[0].success
    assert results[0].ret_code == 0
    assert results[0].test == tests[0]
    assert results[0].actual_output == tests[0].expected_output
    assert results[1].success
    assert results[1].ret_code == 0
    assert results[1].test == tests[1]
    assert results[1].actual_output == tests[1].expected_output

import tempfile
import StringIO

import pytest

from shelltest.shelltest import ShellTest, ShellTestSource, ShellTestRunner


def runner(tests):
    tests = [ShellTest(cmd, output, ShellTestSource('', 0)) for cmd, output in tests]
    return ShellTestRunner(tests)


@pytest.mark.parametrize("cmd,output,ret_code,success", (
    ('echo hello', 'hello\n', 0, True),
    ('echo $?', '0\n', 0, True),
    ('exit 42', '', 42, True)))
def test_echo(cmd, output, ret_code, success):
    r = runner([(cmd, output)])
    res = r.run()[0]
    assert res.success == success
    assert res.ret_code == ret_code
    assert res.test == r.tests[0]
    assert res.actual_output == output

Update runner tests to use parameters
Update runner tests to use parameters

  import tempfile
  import StringIO
  
  import pytest
  
  from shelltest.shelltest import ShellTest, ShellTestSource, ShellTestRunner
  
  
+ def runner(tests):
+     tests = [ShellTest(cmd, output, ShellTestSource('', 0)) for cmd, output in tests]
+     return ShellTestRunner(tests)
- @pytest.fixture
- def tests():
-     return [ShellTest('echo hello', 'hello\n', ShellTestSource('', 0)),
-             ShellTest('echo $?', '0\n', ShellTestSource('', 2))]
  
  
- def test_run(tests):
-     r = ShellTestRunner(tests)
+ @pytest.mark.parametrize("cmd,output,ret_code,success", (
+     ('echo hello', 'hello\n', 0, True),
+     ('echo $?', '0\n', 0, True),
+     ('exit 42', '', 42, True)))
+ def test_echo(cmd, output, ret_code, success):
+     r = runner([(cmd, output)])
-     results = r.run()
+     res = r.run()[0]
+     assert res.success == success
-     assert len(results) == 2
-     assert results[0].success
-     assert results[0].ret_code == 0
+     assert res.ret_code == ret_code
-     assert results[0].test == tests[0]
+     assert res.test == r.tests[0]
-     assert results[0].actual_output == tests[0].expected_output
+     assert res.actual_output == output
-     assert results[1].success
-     assert results[1].ret_code == 0
-     assert results[1].test == tests[1]
-     assert results[1].actual_output == tests[1].expected_output
  
Update runner tests to use parameters
## Code Before:
import tempfile
import StringIO

import pytest

from shelltest.shelltest import ShellTest, ShellTestSource, ShellTestRunner


@pytest.fixture
def tests():
    return [ShellTest('echo hello', 'hello\n', ShellTestSource('', 0)),
            ShellTest('echo $?', '0\n', ShellTestSource('', 2))]


def test_run(tests):
    r = ShellTestRunner(tests)
    results = r.run()
    assert len(results) == 2
    assert results[0].success
    assert results[0].ret_code == 0
    assert results[0].test == tests[0]
    assert results[0].actual_output == tests[0].expected_output
    assert results[1].success
    assert results[1].ret_code == 0
    assert results[1].test == tests[1]
    assert results[1].actual_output == tests[1].expected_output

## Instruction:
Update runner tests to use parameters
## Code After:
import tempfile
import StringIO

import pytest

from shelltest.shelltest import ShellTest, ShellTestSource, ShellTestRunner


def runner(tests):
    tests = [ShellTest(cmd, output, ShellTestSource('', 0)) for cmd, output in tests]
    return ShellTestRunner(tests)


@pytest.mark.parametrize("cmd,output,ret_code,success", (
    ('echo hello', 'hello\n', 0, True),
    ('echo $?', '0\n', 0, True),
    ('exit 42', '', 42, True)))
def test_echo(cmd, output, ret_code, success):
    r = runner([(cmd, output)])
    res = r.run()[0]
    assert res.success == success
    assert res.ret_code == ret_code
    assert res.test == r.tests[0]
    assert res.actual_output == output
