Skip to content
Merged
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
3 changes: 3 additions & 0 deletions doorstop/core/publishers/tests/test_publisher_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def test_toc_no_links_or_heading_levels(self):
{"depth": 2, "text": "1.6 Hello, world! (REQ004)", "uid": ""},
{"depth": 2, "text": "2.1 Plantuml (REQ002)", "uid": ""},
{"depth": 2, "text": "2.1 Hello, world! (REQ2-001)", "uid": ""},
{"depth": 1, "text": "3.0 My Heading", "uid": ""},
]
html_publisher = publisher.check(".html", self.document)
toc = html_publisher.table_of_contents(linkify=None, obj=self.document)
Expand All @@ -345,6 +346,7 @@ def test_toc_no_links(self):
{"depth": 2, "text": "Hello, world! (REQ004)", "uid": ""},
{"depth": 2, "text": "Plantuml (REQ002)", "uid": ""},
{"depth": 2, "text": "Hello, world! (REQ2-001)", "uid": ""},
{"depth": 1, "text": "My Heading", "uid": ""},
]

html_publisher = publisher.check(".html", self.document)
Expand Down Expand Up @@ -373,6 +375,7 @@ def test_toc(self):
"text": "2.1 Hello, world! (REQ2-001)",
"uid": UID("REQ2-001"),
},
{"depth": 1, "text": "3.0 My Heading", "uid": UID("REQ007")},
]
html_publisher = publisher.check(".html", self.document)
toc = html_publisher.table_of_contents(linkify=True, obj=self.document)
Expand Down
7 changes: 5 additions & 2 deletions doorstop/core/publishers/tests/test_publisher_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ def test_toc_no_links_or_heading_levels(self):
* 1.5 Hello, world! (REQ006)
* 1.6 Hello, world! (REQ004)
* 2.1 Plantuml (REQ002)
* 2.1 Hello, world! (REQ2-001)\n"""
* 2.1 Hello, world! (REQ2-001)
* 3.0 My Heading\n"""
md_publisher = publisher.check(".md", self.document)
toc = md_publisher.table_of_contents(linkify=None, obj=self.document)
self.assertEqual(expected, toc)
Expand All @@ -246,6 +247,7 @@ def test_toc_no_links(self):
* Hello, world! (REQ004)
* Plantuml (REQ002)
* Hello, world! (REQ2-001)
* My Heading
"""
md_publisher = publisher.check(".md", self.document)
toc = md_publisher.table_of_contents(linkify=None, obj=self.document)
Expand All @@ -260,7 +262,8 @@ def test_toc(self):
* [1.5 Hello, world! (REQ006)](#15-req006-req006)
* [1.6 Hello, world! (REQ004)](#16-req004-req004)
* [2.1 Plantuml (REQ002)](#21-plantuml-req002-req002)
* [2.1 Hello, world! (REQ2-001)](#21-req2-001-req2-001)\n"""
* [2.1 Hello, world! (REQ2-001)](#21-req2-001-req2-001)
* [3.0 My Heading](#30-my-heading-req007)\n"""
self.maxDiff = None
md_publisher = publisher.check(".md", self.document)
toc = md_publisher.table_of_contents(linkify=True, obj=self.document)
Expand Down
13 changes: 13 additions & 0 deletions doorstop/core/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@

TESTS_ROOT = os.path.dirname(__file__)
FILES = os.path.join(os.path.dirname(__file__), "files")
# Files that use the golden master pattern and are intentionally
# updated by tests - these should not be reset after each test run
GOLDEN_MASTER_FILES = {
os.path.join(FILES, "exported.yml"),
os.path.join(FILES, "exported.csv"),
os.path.join(FILES, "exported.tsv"),
os.path.join(FILES, "published.html"),
os.path.join(FILES, "published.md"),
os.path.join(FILES, "published.txt"),
os.path.join(FILES, "published2.html"),
os.path.join(FILES, "published2.md"),
os.path.join(FILES, "published2.txt"),
}
FILES_MD = os.path.join(os.path.dirname(__file__), "files_md")
SYS = os.path.join(FILES, "parent")
TST = os.path.join(FILES, "child")
Expand Down
10 changes: 10 additions & 0 deletions doorstop/core/tests/files/REQ007.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
active: true
derived: false
header: |
My Heading
level: 3.0
links: []
normative: false
ref: ''
reviewed: null
text: ''
1 change: 1 addition & 0 deletions doorstop/core/tests/files/exported.csv
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ Test Math Expressions in Latex Style:
Inline Style 1: $a \ne 0$
Inline Style 2: \(ax^2 + bx + c = 0\)
Multiline: $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$",,,REQ001,True,False,,True,
REQ007,3.0,,,,,True,False,My Heading,False,
1 change: 1 addition & 0 deletions doorstop/core/tests/files/exported.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ Test Math Expressions in Latex Style:
Inline Style 1: $a \ne 0$
Inline Style 2: \(ax^2 + bx + c = 0\)
Multiline: $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$" REQ001 True False True
REQ007 3.0 True False My Heading False
12 changes: 12 additions & 0 deletions doorstop/core/tests/files/exported.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,15 @@ REQ2-001:
Inline Style 2: \(ax^2 + bx + c = 0\)
Multiline: $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
REQ007:
active: true
derived: false
header: |
My Heading
level: 3.0
links: []
normative: false
ref: ''
reviewed: null
text: ''

10 changes: 9 additions & 1 deletion doorstop/core/tests/files/published.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@
data-bs-placement="left"
title="REQ2-001">2.1 Hello, world! (REQ2-001)</a>
</li>
</ul>
</ul>
<li>
<a class="dropdown-item text-truncate"
href="#REQ007"
data-bs-toggle="tooltip"
data-bs-placement="left"
title="REQ007">3.0 My Heading</a>
</li>
</ul>
</ul>
</li>
Expand Down Expand Up @@ -186,6 +193,7 @@ <h2 id="REQ2-001">2.1 REQ2-001</h2>
Multiline: $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$</p>
<p><em>Parent links:</em> <a href="REQ.html#REQ001">REQ001</a></p>
<p><em>Child links:</em> <a href="TST.html#TST001">TST001</a></p>
<h1 id="REQ007">3.0 My Heading</h1>
</div>
</main>
</div>
Expand Down
2 changes: 2 additions & 0 deletions doorstop/core/tests/files/published.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ Multiline: $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$

*Child links: TST001*

# 3.0 My Heading {#REQ007}

2 changes: 2 additions & 0 deletions doorstop/core/tests/files/published.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@

Child links: TST001

3.0 My Heading

10 changes: 9 additions & 1 deletion doorstop/core/tests/files/published2.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@
data-bs-placement="left"
title="REQ2-001">2.1 Hello, world! (REQ2-001)</a>
</li>
</ul>
</ul>
<li>
<a class="dropdown-item text-truncate"
href="#REQ007"
data-bs-toggle="tooltip"
data-bs-placement="left"
title="REQ007">3.0 My Heading</a>
</li>
</ul>
</ul>
</li>
Expand Down Expand Up @@ -184,6 +191,7 @@ <h2 id="REQ2-001">2.1 REQ2-001</h2>
Inline Style 2: (ax^2 + bx + c = 0)
Multiline: $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$</p>
<p><em>Links: REQ001</em></p>
<h1 id="REQ007">3.0 My Heading</h1>
</div>
</main>
</div>
Expand Down
2 changes: 2 additions & 0 deletions doorstop/core/tests/files/published2.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ Multiline: $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$

*Links: REQ001*

# 3.0 My Heading {#REQ007}

2 changes: 2 additions & 0 deletions doorstop/core/tests/files/published2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@

Links: REQ001

3.0 My Heading

55 changes: 43 additions & 12 deletions doorstop/core/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ENV,
FILES,
FILES_MD,
GOLDEN_MASTER_FILES,
REASON,
ROOT,
SYS,
Expand Down Expand Up @@ -77,6 +78,17 @@ def cleanup_test_yml_files():
if result.returncode == 0 and result.stdout.strip():
yaml_files = result.stdout.strip().split("\n")

# Exclude golden master files from reset
yaml_files = [
f
for f in yaml_files
if os.path.abspath(os.path.join(repo_root, f))
not in GOLDEN_MASTER_FILES
]

if not yaml_files:
continue

# Reset only these YAML files
subprocess.run(
["git", "-c", "core.autocrlf=false", "checkout", "--"] + yaml_files,
Expand Down Expand Up @@ -215,7 +227,7 @@ def test_load(self):
self.assertEqual("REQ", doc.prefix)
self.assertEqual("yaml", doc.itemformat)
self.assertEqual(2, doc.digits)
self.assertEqual(6, len(doc.items))
self.assertEqual(7, len(doc.items))

def test_new(self):
"""Verify a new document can be created."""
Expand All @@ -238,7 +250,7 @@ def test_issues_count(self):
issues = self.document.issues
for issue in self.document.issues:
logging.info(repr(issue))
self.assertEqual(13, len(issues))
self.assertEqual(15, len(issues))

@patch("doorstop.settings.REORDER", False)
@patch("doorstop.settings.REVIEW_NEW_ITEMS", False)
Expand Down Expand Up @@ -394,7 +406,7 @@ def test_issues_count(self):
issues = self.tree.issues
for issue in self.tree.issues:
logging.info(repr(issue))
self.assertEqual(15, len(issues))
self.assertEqual(17, len(issues))

@patch("doorstop.settings.REORDER", False)
@patch("doorstop.settings.REVIEW_NEW_ITEMS", False)
Expand Down Expand Up @@ -600,8 +612,13 @@ def test_export_yml(self):
# Assert
self.assertIs(temp, path2)
actual = read_yml(temp)
# Assert
if actual != expected:
common.log.error(f"Published content changed: {path}")
move_file(temp, path)
else:
common.delete(temp) # clean up in case the file didn't change
self.assertEqual(expected, actual)
move_file(temp, path)

def test_export_csv(self):
"""Verify a document can be exported as a CSV file."""
Expand All @@ -613,8 +630,13 @@ def test_export_csv(self):
# Assert
self.assertIs(temp, path2)
actual = read_csv(temp)
# Assert
if actual != expected:
common.log.error(f"Published content changed: {path}")
move_file(temp, path)
else:
common.delete(temp) # clean up in case the file didn't change
self.assertEqual(expected, actual)
move_file(temp, path)

@patch("doorstop.settings.REVIEW_NEW_ITEMS", False)
def test_export_tsv(self):
Expand All @@ -627,8 +649,13 @@ def test_export_tsv(self):
# Assert
self.assertIs(temp, path2)
actual = read_csv(temp, delimiter="\t")
# Assert
if actual != expected:
common.log.error(f"Published content changed: {path}")
move_file(temp, path)
else:
common.delete(temp) # clean up in case the file didn't change
self.assertEqual(expected, actual)
move_file(temp, path)


class TestPublisher(unittest.TestCase):
Expand Down Expand Up @@ -684,8 +711,10 @@ def test_lines_text_document(self):
lines = core.publisher.publish_lines(self.document, ".txt")
text = "".join(line + "\n" for line in lines)
# Assert
if text != expected:
common.log.error(f"Published content changed: {path}")
common.write_text(text, path)
self.assertEqual(expected, text)
common.write_text(text, path)

@patch("doorstop.settings.PUBLISH_CHILD_LINKS", False)
def test_lines_text_document_without_child_links(self):
Expand All @@ -696,8 +725,10 @@ def test_lines_text_document_without_child_links(self):
lines = core.publisher.publish_lines(self.document, ".txt")
text = "".join(line + "\n" for line in lines)
# Assert
if text != expected:
common.log.error(f"Published content changed: {path}")
common.write_text(text, path)
self.assertEqual(expected, text)
common.write_text(text, path)

def test_lines_markdown_document(self):
"""Verify Markdown can be published from a document."""
Expand All @@ -709,7 +740,7 @@ def test_lines_markdown_document(self):
# Assert
if text != expected:
common.log.error(f"Published content changed: {path}")
common.write_text(text, path)
common.write_text(text, path)
self.assertEqual(expected, text)

@patch("doorstop.settings.PUBLISH_CHILD_LINKS", False)
Expand All @@ -723,7 +754,7 @@ def test_lines_markdown_document_without_child_links(self):
# Assert
if text != expected:
common.log.error(f"Published content changed: {path}")
common.write_text(text, path)
common.write_text(text, path)
self.assertEqual(expected, text)

@patch("plantuml_markdown.PlantUMLPreprocessor.run")
Expand Down Expand Up @@ -751,7 +782,7 @@ def run(lines: List[str]) -> List[str]:
# Assert
if actual != expected:
common.log.error(f"Published content changed: {path}")
common.write_text(actual, path)
common.write_text(actual, path)
self.assertEqual(expected, actual)

@patch("plantuml_markdown.PlantUMLPreprocessor.run")
Expand All @@ -776,7 +807,7 @@ def run(lines: List[str]) -> List[str]:
# Assert
if actual != expected:
common.log.error(f"Published content changed: {path}")
common.write_text(actual, path)
common.write_text(actual, path)
self.assertEqual(expected, actual)


Expand Down
Loading
Loading