Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/tap/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,16 @@ def __str__(self):
diagnostics = ""
if self.diagnostics is not None:
diagnostics = "\n" + self.diagnostics.rstrip()
return f"{is_not}ok {self.number} {self.description}{directive}{diagnostics}"
yaml_block = ""
if self._yaml_block is not None:
indented_yaml_block = "\n".join(
f" {line}" for line in self._yaml_block.splitlines()
)
yaml_block = f"\n ---\n{indented_yaml_block}\n ..."
return (
f"{is_not}ok {self.number} {self.description}{directive}"
f"{diagnostics}{yaml_block}"
)


class Plan(Line):
Expand Down
20 changes: 18 additions & 2 deletions src/tap/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,39 @@ def _track(self, class_name):
if self.combined:
self.combined_test_cases_seen.append(class_name)

def add_ok(self, class_name, description, directive="", diagnostics=None):
def add_ok(
self,
class_name,
description,
directive="",
diagnostics=None,
raw_yaml_block=None,
):
result = Result(
ok=True,
number=self._get_next_line_number(class_name),
description=description,
diagnostics=diagnostics,
directive=Directive(directive),
raw_yaml_block=raw_yaml_block,
)
self._add_line(class_name, result)

def add_not_ok(self, class_name, description, directive="", diagnostics=None):
def add_not_ok(
self,
class_name,
description,
directive="",
diagnostics=None,
raw_yaml_block=None,
):
result = Result(
ok=False,
number=self._get_next_line_number(class_name),
description=description,
diagnostics=diagnostics,
directive=Directive(directive),
raw_yaml_block=raw_yaml_block,
)
self._add_line(class_name, result)

Expand Down
26 changes: 24 additions & 2 deletions tests/test_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
from tap.directive import Directive
from tap.line import Line, Result

try:
import yaml # noqa
from more_itertools import peekable # noqa

have_yaml = True
except ImportError:
have_yaml = False


class TestLine(unittest.TestCase):
"""Tests for tap.line.Line"""
Expand Down Expand Up @@ -38,5 +46,19 @@ def test_str_directive(self):
self.assertEqual("ok 44 passing # SKIP a reason", str(result))

def test_str_diagnostics(self):
result = Result(False, 43, "failing", diagnostics="# more info")
self.assertEqual("not ok 43 failing\n# more info", str(result))
result = Result(False, 45, "failing", diagnostics="# more info")
self.assertEqual("not ok 45 failing\n# more info", str(result))

def test_yaml_block(self):
raw_yaml_block = """\
message: test_message
severity: fail
"""
result = Result(False, 46, "passing", raw_yaml_block=raw_yaml_block)
if have_yaml:
self.assertEqual(result.yaml_block["message"], "test_message")
self.assertIn(
" ---\n message: test_message\n severity: fail\n ...", str(result)
)
else:
self.assertIsNone(result.yaml_block)
40 changes: 40 additions & 0 deletions tests/test_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
from tap.tests import TestCase
from tap.tracker import Tracker

try:
import yaml # noqa
from more_itertools import peekable # noqa

have_yaml = True
except ImportError:
have_yaml = False


class TestTracker(TestCase):
def _make_header(self, test_case):
Expand Down Expand Up @@ -295,6 +303,38 @@ def test_adds_not_ok_with_diagnostics(self):
line = tracker._test_cases["FakeTestCase"][0]
self.assertEqual("# more info\n", line.diagnostics)

def test_adds_ok_with_yaml_block(self):
tracker = Tracker()
tracker.add_ok(
"FakeTestCase",
"a description",
raw_yaml_block="""\
message: test_message
severity: pass
""",
)
line = tracker._test_cases["FakeTestCase"][0]
if have_yaml:
self.assertEqual("test_message", line.yaml_block["message"])
else:
self.assertIsNone(line.yaml_block)

def test_adds_not_ok_with_yaml_block(self):
tracker = Tracker()
tracker.add_not_ok(
"FakeTestCase",
"a description",
raw_yaml_block="""\
message: test_message
severity: fail
""",
)
line = tracker._test_cases["FakeTestCase"][0]
if have_yaml:
self.assertEqual("test_message", line.yaml_block["message"])
else:
self.assertIsNone(line.yaml_block)

def test_header_displayed_by_default(self):
tracker = Tracker()
self.assertTrue(tracker.header)
Expand Down