Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ducminh-phan committed Apr 7, 2019
1 parent d241494 commit ecc1d3c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
12 changes: 12 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
from main.options import AlignmentMode, Options, WriteBackMode

OPTIONS = [
Options(
write_back=WriteBackMode.CHECK,
step_keyword_alignment=alignment_mode,
fast=False,
)
for alignment_mode in AlignmentMode
]


def get_content(file_name):
with open(f"tests/data/valid/{file_name}.feature") as f:
return f.read()
Expand Down
39 changes: 37 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest

from main import core
from main.errors import EquivalentError, InternalError
from tests.helpers import dump_to_stderr, get_content
from main.errors import EquivalentError, InternalError, NothingChanged, StableError
from tests.helpers import OPTIONS, dump_to_stderr, get_content


def test_assert_equivalent():
Expand All @@ -30,3 +30,38 @@ def test_assert_equivalent_invalid_dst(invalid_contents):

with pytest.raises(InternalError):
core.assert_equivalent(login_content, invalid_content)


@pytest.mark.parametrize("options", OPTIONS)
def test_assert_stable(valid_contents, options):
for content in valid_contents:
formatted_content = core.format_file_contents(content, options=options)

core.assert_stable(content, formatted_content, options=options)


@pytest.mark.parametrize("options", OPTIONS)
@patch("main.core.dump_to_file", dump_to_stderr)
def test_assert_stable_fail(options):
src = dst = get_content("full")

with pytest.raises(StableError):
core.assert_stable(src, dst, options=options)


@pytest.mark.parametrize("options", OPTIONS)
def test_format_file_contents(valid_contents, options):
for src in valid_contents:
core.format_file_contents(src, options=options)


@pytest.mark.parametrize("options", OPTIONS)
def test_format_file_contents_no_change(options):
with pytest.raises(NothingChanged):
core.format_file_contents("", options=options)

content = get_content("full")
formatted_content = core.format_file_contents(content, options=options)

with pytest.raises(NothingChanged):
core.format_file_contents(formatted_content, options=options)

0 comments on commit ecc1d3c

Please sign in to comment.