Skip to content

Commit 67554f2

Browse files
authored
Merge pull request #1775 from strictdoc-project/stanislaw/fix_document_from_file
document_from_file: fix the resolution of parent Document or Section nodes
2 parents 78d1677 + ec071f5 commit 67554f2

File tree

18 files changed

+254
-6
lines changed

18 files changed

+254
-6
lines changed

strictdoc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from strictdoc.core.environment import SDocRuntimeEnvironment
22

3-
__version__ = "0.0.54a1"
3+
__version__ = "0.0.54a2"
44

55

66
environment = SDocRuntimeEnvironment(__file__)

strictdoc/backend/sdoc/models/document_from_file.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,18 @@ def configure_with_resolved_document(self, resolved_document):
5050
assert resolved_document is not None
5151
self.resolved_document = resolved_document
5252

53-
including_document = self.parent
54-
assert (
55-
including_document.__class__.__name__ == "SDocDocument"
56-
), including_document
53+
including_document_or_section = self.parent
5754

58-
resolved_document.ng_including_document_from_file = self
55+
if including_document_or_section.__class__.__name__ == "SDocDocument":
56+
including_document = including_document_or_section
57+
elif including_document_or_section.__class__.__name__ == "SDocSection":
58+
including_document = including_document_or_section.document
59+
else:
60+
raise AssertionError(including_document_or_section)
5961

62+
resolved_document.ng_including_document_from_file = self
6063
resolved_document.ng_including_document_reference.set_document(
6164
including_document
6265
)
66+
6367
including_document.included_documents.append(resolved_document)

tests/end2end/screens/document/_cross_cutting/included_documents/_outside_fragment/update_included_document__fragment_nested_in_section__create_section_above/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[DOCUMENT]
2+
TITLE: Document 1
3+
4+
[FREETEXT]
5+
Hello world!
6+
[/FREETEXT]
7+
8+
[SECTION]
9+
TITLE: Section that nests a document fragment.
10+
11+
[SECTION]
12+
TITLE: First section
13+
14+
[/SECTION]
15+
16+
[DOCUMENT_FROM_FILE]
17+
FILE: fragment.sdoc
18+
19+
[/SECTION]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[DOCUMENT]
2+
TITLE: Fragment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[DOCUMENT]
2+
TITLE: Document 1
3+
4+
[FREETEXT]
5+
Hello world!
6+
[/FREETEXT]
7+
8+
[SECTION]
9+
TITLE: Section that nests a document fragment.
10+
11+
[DOCUMENT_FROM_FILE]
12+
FILE: fragment.sdoc
13+
14+
[/SECTION]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[DOCUMENT]
2+
TITLE: Fragment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from tests.end2end.e2e_case import E2ECase
2+
from tests.end2end.end2end_test_setup import End2EndTestSetup
3+
from tests.end2end.helpers.components.node.add_node_menu import AddNode_Menu
4+
from tests.end2end.helpers.components.node.section import Section
5+
from tests.end2end.helpers.screens.document.form_edit_section import (
6+
Form_EditSection,
7+
)
8+
from tests.end2end.helpers.screens.project_index.screen_project_index import (
9+
Screen_ProjectIndex,
10+
)
11+
from tests.end2end.server import SDocTestServer
12+
13+
14+
class Test(E2ECase):
15+
def test(self):
16+
test_setup = End2EndTestSetup(path_to_test_file=__file__)
17+
18+
with SDocTestServer(
19+
input_path=test_setup.path_to_sandbox
20+
) as test_server:
21+
self.open(test_server.get_host_and_port())
22+
23+
screen_project_index = Screen_ProjectIndex(self)
24+
25+
screen_project_index.assert_on_screen()
26+
screen_project_index.assert_contains_document("Document 1")
27+
28+
screen_document = screen_project_index.do_click_on_first_document()
29+
30+
screen_document.assert_on_screen_document()
31+
screen_document.assert_header_document_title("Document 1")
32+
33+
screen_document.assert_text("Hello world!")
34+
35+
section: Section = screen_document.get_section(node_order=2)
36+
37+
section_menu: AddNode_Menu = section.do_open_node_menu()
38+
form_edit_section: Form_EditSection = (
39+
section_menu.do_node_add_section_above()
40+
)
41+
42+
form_edit_section.do_fill_in_title("First section")
43+
form_edit_section.do_form_submit()
44+
45+
section: Section = screen_document.get_section(2)
46+
47+
section.assert_section_title("First section")
48+
49+
screen_document.assert_toc_contains("First section")
50+
51+
screen_document.get_root_node().assert_document_title_contains(
52+
"Document 1"
53+
)
54+
55+
assert test_setup.compare_sandbox_and_expected_output()

tests/end2end/screens/document/_cross_cutting/included_documents/update_included_document__fragment_nested_in_section__create_section/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[DOCUMENT]
2+
TITLE: Document 1
3+
4+
[FREETEXT]
5+
Hello world!
6+
[/FREETEXT]
7+
8+
[SECTION]
9+
TITLE: Section that nests a document fragment.
10+
11+
[DOCUMENT_FROM_FILE]
12+
FILE: fragment.sdoc
13+
14+
[/SECTION]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[DOCUMENT]
2+
TITLE: Fragment
3+
4+
[SECTION]
5+
TITLE: First section
6+
7+
[SECTION]
8+
TITLE: Second section
9+
10+
[/SECTION]
11+
12+
[/SECTION]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[DOCUMENT]
2+
TITLE: Document 1
3+
4+
[FREETEXT]
5+
Hello world!
6+
[/FREETEXT]
7+
8+
[SECTION]
9+
TITLE: Section that nests a document fragment.
10+
11+
[DOCUMENT_FROM_FILE]
12+
FILE: fragment.sdoc
13+
14+
[/SECTION]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[DOCUMENT]
2+
TITLE: Fragment
3+
4+
[SECTION]
5+
TITLE: First section
6+
7+
[/SECTION]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from tests.end2end.e2e_case import E2ECase
2+
from tests.end2end.end2end_test_setup import End2EndTestSetup
3+
from tests.end2end.helpers.components.node.add_node_menu import AddNode_Menu
4+
from tests.end2end.helpers.components.node.section import Section
5+
from tests.end2end.helpers.screens.document.form_edit_section import (
6+
Form_EditSection,
7+
)
8+
from tests.end2end.helpers.screens.project_index.screen_project_index import (
9+
Screen_ProjectIndex,
10+
)
11+
from tests.end2end.server import SDocTestServer
12+
13+
14+
class Test(E2ECase):
15+
def test(self):
16+
test_setup = End2EndTestSetup(path_to_test_file=__file__)
17+
18+
with SDocTestServer(
19+
input_path=test_setup.path_to_sandbox
20+
) as test_server:
21+
self.open(test_server.get_host_and_port())
22+
23+
screen_project_index = Screen_ProjectIndex(self)
24+
25+
screen_project_index.assert_on_screen()
26+
screen_project_index.assert_contains_document("Document 1")
27+
28+
screen_document = screen_project_index.do_click_on_first_document()
29+
30+
screen_document.assert_on_screen_document()
31+
screen_document.assert_header_document_title("Document 1")
32+
33+
screen_document.assert_text("Hello world!")
34+
35+
section: Section = screen_document.get_section(node_order=3)
36+
37+
section_menu: AddNode_Menu = section.do_open_node_menu()
38+
form_edit_section: Form_EditSection = (
39+
section_menu.do_node_add_section_child()
40+
)
41+
42+
form_edit_section.do_fill_in_title("Second section")
43+
form_edit_section.do_form_submit()
44+
45+
section: Section = screen_document.get_section(4)
46+
47+
section.assert_section_title("Second section")
48+
49+
screen_document.assert_toc_contains("Second section")
50+
51+
screen_document.get_root_node().assert_document_title_contains(
52+
"Document 1"
53+
)
54+
55+
assert test_setup.compare_sandbox_and_expected_output()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[DOCUMENT]
2+
TITLE: Hello world doc
3+
OPTIONS:
4+
AUTO_LEVELS: On
5+
6+
[SECTION]
7+
TITLE: Section that nests a fragment
8+
9+
[DOCUMENT_FROM_FILE]
10+
FILE: nested.sdoc
11+
12+
[/SECTION]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[DOCUMENT]
2+
TITLE: Hello world doc 2
3+
OPTIONS:
4+
AUTO_LEVELS: On
5+
6+
[DOCUMENT_FROM_FILE]
7+
FILE: subnested.sdoc
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[DOCUMENT]
2+
TITLE: Hello world doc 3
3+
OPTIONS:
4+
AUTO_LEVELS: On
5+
6+
[SECTION]
7+
TITLE: Section 1.2.3
8+
9+
[COMPOSITE_REQUIREMENT]
10+
TITLE: Composite requirement 4.5.6
11+
12+
[REQUIREMENT]
13+
TITLE: Requirement 7.8.9
14+
15+
[/COMPOSITE_REQUIREMENT]
16+
17+
[/SECTION]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
RUN: %strictdoc export %S --output-dir Output/ | filecheck %s --dump-input=fail
2+
CHECK: Published: Hello world doc
3+
4+
RUN: %cat %S/Output/html/10_nested_fragments_inserted_to_section/input.html | filecheck %s --dump-input=fail --check-prefix CHECK-HTML
5+
6+
CHECK-HTML:data-level="1"
7+
CHECK-HTML:1. Section that nests a fragment
8+
CHECK-HTML:data-level="1.1"
9+
CHECK-HTML:1.1. Hello world doc 2
10+
CHECK-HTML:data-level="1.1.1"
11+
CHECK-HTML:data-level="1.1.1.1"
12+
CHECK-HTML:data-level="1.1.1.1.1"
13+
CHECK-HTML:data-level="1.1.1.1.1.1"
14+
CHECK-HTML:1.1.1.1.1.1. Requirement 7.8.9

0 commit comments

Comments
 (0)