Skip to content

Commit

Permalink
Switch to ScriptTest for CLI integration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Nov 1, 2016
1 parent fea62d7 commit 40913a8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
3 changes: 3 additions & 0 deletions osmerge/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import click

from . import VERSION


log = logging.getLogger(__name__)


@click.group()
@click.version_option(message=VERSION)
def main():
logging.basicConfig(level=logging.INFO)
logging.getLogger('yorm').setLevel(logging.WARNING)
Expand Down
1 change: 1 addition & 0 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pytest-describe
pytest-expecter
pytest-cov
pytest-random
scripttest == 1.3

# Coverage
coverage
Expand Down
33 changes: 26 additions & 7 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
# pylint: disable=unused-variable,expression-not-assigned
# pylint: disable=unused-variable,expression-not-assigned,redefined-outer-name

import sys

import pytest
import scripttest
from expecter import expect
from click.testing import CliRunner

from osmerge.cli import main

@pytest.fixture
def env(tmpdir):
path = str(tmpdir.join("test"))
env = scripttest.TestFileEnvironment(path)
return env


@pytest.fixture
def cli(env):
prog = sys.executable, '-m', 'osmerge'
return lambda *args: env.run(*prog, *args, expect_error=True)


def describe_cli():

def it_can_be_called_without_a_command():
runner = CliRunner()
def it_displays_help_information(cli):
cmd = cli('--help')

expect(cmd.returncode) == 0
expect(cmd.stdout).contains("Usage: ")

result = runner.invoke(main)
def it_displays_version_information(cli):
cmd = cli('--version')

expect(result.exit_code) == 0
expect(cmd.returncode) == 0
expect(cmd.stdout or cmd.stderr).contains("OSMerge v0.")

0 comments on commit 40913a8

Please sign in to comment.