Skip to content

Commit 1fccfea

Browse files
authored
Add text to Unknown tap line (#163)
Unknown tap line where simply discarded. Instead, provide a way to retrieve the original text programmatically. This could be used by an alternative CLI application to pass through those lines. Signed-off-by: Pierrick Guillaume <pguillaume@fymyte.com>
1 parent c14fc7e commit 1fccfea

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Contributors
1515
* meejah (https://meejah.ca)
1616
* Michael F. Lamb (http://datagrok.org)
1717
* Nicolas Caniart
18+
* Pierrick Guillaume
1819
* Richard Bosworth
1920
* Ross Burton
2021
* Simon McVittie

src/tap/line.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,15 @@ class Unknown(Line):
203203
This exists for the purpose of a Null Object pattern.
204204
"""
205205

206+
def __init__(self, text=None):
207+
self._text = text
208+
206209
@property
207210
def category(self):
208211
""":returns: ``unknown``"""
209212
return "unknown"
213+
214+
@property
215+
def text(self):
216+
"""Get the text."""
217+
return self._text

src/tap/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def parse_line(self, text, fh=None):
133133
if match:
134134
return self._parse_version(match)
135135

136-
return Unknown()
136+
return Unknown(text)
137137

138138
def _parse_plan(self, match):
139139
"""Parse a matching plan line."""
@@ -142,7 +142,7 @@ def _parse_plan(self, match):
142142

143143
# Only SKIP directives are allowed in the plan.
144144
if directive.text and not directive.skip:
145-
return Unknown()
145+
return Unknown(match.string)
146146

147147
return Plan(expected_tests, directive)
148148

tests/test_parser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ def test_finds_directive(self):
110110
def test_unrecognizable_line(self):
111111
"""The parser returns an unrecognizable line."""
112112
parser = Parser()
113+
test_line = "This is not a valid TAP line. # srsly"
113114

114-
line = parser.parse_line("This is not a valid TAP line. # srsly")
115+
line = parser.parse_line(test_line)
115116

116117
self.assertEqual("unknown", line.category)
118+
self.assertEqual(test_line, line.text)
117119

118120
def test_diagnostic_line(self):
119121
"""The parser extracts a diagnostic line."""
@@ -171,10 +173,12 @@ def test_finds_plan_with_skip(self):
171173
def test_ignores_plan_with_any_non_skip_directive(self):
172174
"""The parser only recognizes SKIP directives in plans."""
173175
parser = Parser()
176+
test_line = "1..42 # TODO will not work."
174177

175-
line = parser.parse_line("1..42 # TODO will not work.")
178+
line = parser.parse_line(test_line)
176179

177180
self.assertEqual("unknown", line.category)
181+
self.assertEqual(test_line, line.text)
178182

179183
def test_parses_text(self):
180184
sample = inspect.cleandoc(

0 commit comments

Comments
 (0)