Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify error about incomplete traceability_relationship_to_string #361

Merged
merged 9 commits into from
Oct 27, 2023
Prev Previous commit
Next Next commit
Refactor test suite by creating init_builder
  • Loading branch information
JasperCraeghs committed Oct 27, 2023
commit 8f3b76b83e725b49cea481a95c9df470ffb5fea1
55 changes: 15 additions & 40 deletions tests/directives/test_item_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,21 @@ def setUp(self):
self.app.config = Mock()
self.app.config.traceability_hyperlink_colors = {}
self.collection = TraceableCollection()

def test_make_internal_item_ref_no_caption(self):
mock_builder = MagicMock(spec=StandaloneHTMLBuilder)
mock_builder.link_suffix = '.html'
self.collection.add_item(self.item)

def init_builder(self, spec=StandaloneHTMLBuilder):
mock_builder = MagicMock(spec=spec)
if spec == StandaloneHTMLBuilder:
mock_builder.link_suffix = '.html'
else:
mock_builder.get_relative_uri = Mock(side_effect=raise_no_uri)
mock_builder.env = BuildEnvironment(self.app)
self.app.builder = mock_builder
self.app.builder.env.traceability_collection = self.collection
self.app.builder.env.traceability_ref_nodes = {}
self.app.builder.env.traceability_collection.add_item(self.item)

def test_make_internal_item_ref_no_caption(self):
self.init_builder()
p_node = self.node.make_internal_item_ref(self.app, self.node['id'])
ref_node = p_node.children[0]
em_node = ref_node.children[0]
Expand All @@ -58,13 +64,7 @@ def test_make_internal_item_ref_no_caption(self):
self.assertNotIn('onlycaptions', cache)

def test_make_internal_item_ref_show_caption(self):
mock_builder = MagicMock(spec=StandaloneHTMLBuilder)
mock_builder.link_suffix = '.html'
mock_builder.env = BuildEnvironment(self.app)
self.app.builder = mock_builder
self.app.builder.env.traceability_collection = self.collection
self.app.builder.env.traceability_ref_nodes = {}
self.app.builder.env.traceability_collection.add_item(self.item)
self.init_builder()
self.item.caption = 'caption text'
p_node = self.node.make_internal_item_ref(self.app, self.node['id'])
ref_node = p_node.children[0]
Expand All @@ -79,13 +79,7 @@ def test_make_internal_item_ref_show_caption(self):
self.assertEqual(p_node, cache['default'][f'{self.node["document"]}.html'])

def test_make_internal_item_ref_only_caption(self):
mock_builder = MagicMock(spec=StandaloneHTMLBuilder)
mock_builder.link_suffix = '.html'
mock_builder.env = BuildEnvironment(self.app)
self.app.builder = mock_builder
self.app.builder.env.traceability_collection = self.collection
self.app.builder.env.traceability_ref_nodes = {}
self.app.builder.env.traceability_collection.add_item(self.item)
self.init_builder()
self.item.caption = 'caption text'
self.node['nocaptions'] = True
self.node['onlycaptions'] = True
Expand All @@ -104,13 +98,7 @@ def test_make_internal_item_ref_only_caption(self):
self.assertEqual(p_node, cache['onlycaptions'][f'{self.node["document"]}.html'])

def test_make_internal_item_ref_hide_caption_html(self):
mock_builder = MagicMock(spec=StandaloneHTMLBuilder)
mock_builder.link_suffix = '.html'
mock_builder.env = BuildEnvironment(self.app)
self.app.builder = mock_builder
self.app.builder.env.traceability_collection = self.collection
self.app.builder.env.traceability_ref_nodes = {}
self.app.builder.env.traceability_collection.add_item(self.item)
self.init_builder()
self.item.caption = 'caption text'
self.node['nocaptions'] = True
p_node = self.node.make_internal_item_ref(self.app, self.node['id'])
Expand All @@ -128,13 +116,7 @@ def test_make_internal_item_ref_hide_caption_html(self):
self.assertEqual(p_node, cache['nocaptions'][f'{self.node["document"]}.html'])

def test_make_internal_item_ref_hide_caption_latex(self):
mock_builder = MagicMock(spec=LaTeXBuilder)
mock_builder.get_relative_uri = Mock(side_effect=raise_no_uri)
mock_builder.env = BuildEnvironment(self.app)
self.app.builder = mock_builder
self.app.builder.env.traceability_collection = self.collection
self.app.builder.env.traceability_ref_nodes = {}
self.app.builder.env.traceability_collection.add_item(self.item)
self.init_builder(spec=LaTeXBuilder)
self.item.caption = 'caption text'
self.node['nocaptions'] = True
p_node = self.node.make_internal_item_ref(self.app, self.node['id'])
Expand All @@ -160,13 +142,6 @@ def test_is_relation_external(self, relation_name, expected):
self.assertEqual(external, expected)

def test_item_node_replacement(self):
mock_builder = MagicMock(spec=StandaloneHTMLBuilder)
mock_builder.link_suffix = '.html'
mock_builder.env = BuildEnvironment(self.app)
self.app.builder = mock_builder
self.app.builder.env.traceability_collection = self.collection
self.app.builder.env.traceability_ref_nodes = {}
self.app.builder.env.traceability_collection.add_item(self.item)
self.collection.add_relation_pair('depends_on', 'impacts_on')
# leaving out depends_on to test warning
self.app.config.traceability_relationship_to_string = {'impacts_on': 'Impacts on'}
Expand Down