1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
# -*- coding: utf8 -*-
########################################################################################
# This file is part of exhale. Copyright (c) 2017-2024, Stephen McDowell. #
# Full BSD 3-Clause license available here: #
# #
# https://github.com/svenevs/exhale/blob/master/LICENSE #
########################################################################################
"""
Tests for the ``cpp_dir_underscores`` project.
"""
from __future__ import unicode_literals
import os
from testing.base import ExhaleTestCase
from testing.hierarchies import \
class_hierarchy, compare_class_hierarchy, compare_file_hierarchy, file_hierarchy
class CPPDirUnderscores(ExhaleTestCase):
"""
Primary test class for project ``cpp_dir_underscores``.
"""
test_project = "cpp_dir_underscores"
""".. testproject:: cpp_dir_underscores"""
def test_hierarchies(self):
"""Verify the class and file hierarchies."""
compare_class_hierarchy(self, class_hierarchy(self.class_hierarchy_dict()))
compare_file_hierarchy(self, file_hierarchy(self.file_hierarchy_dict()))
def check_title_link(self, name_map, node_map, t_type):
"""
Verify the ``title`` and ``link_name`` of the specified nodes.
.. note::
It is assumed that the ``name_map`` and ``node_map`` parameters have the
exact same set of keys.
**Parameters**
``name_map`` : :class:`python:dict`
Mapping of "dirname/filename" => expected [title, link_name].
``node_map`` : :class:`python:dict`
Mapping of "dirname/filename" => ExhaleNode objects
``t_type`` : :class:`python:str`
For formatting the error message. Should be ``"file"`` or
``"directory"``.
"""
for name, (title, link_name) in name_map.items():
node = node_map[name]
self.assertTrue(
node.title == title,
(
"Wrong title for {t_type} {name}! Expected {title}, but got "
"{node_title}"
).format(
t_type=t_type,
name=node.name,
title=title,
node_title=node.title))
self.assertTrue(
node.link_name == link_name,
(
"Wrong link_name for {t_type} {name}! Expected {link_name}, but "
"got {node_link_name}"
).format(
t_type=t_type,
name=node.name,
link_name=link_name,
node_link_name=node.link_name))
def test_files(self):
"""Verify that file nodes have correct title and link."""
# include/
# ├── interface_alpha
# │ ├── alpha.hpp
# │ ├── one_two_three
# │ │ └── one_two_three.hpp
# │ └── __four_five_six__
# │ └── __four_five_six__.hpp
# └── interface_beta
# └── beta.hpp
# Map: filename => [title, link_name]
f_map = {
"alpha.hpp": [
"File alpha.hpp",
"file_include_interface_alpha_alpha.hpp"
],
"one_two_three.hpp": [
"File one_two_three.hpp",
"file_include_interface_alpha_one_two_three_one_two_three.hpp"
],
"__four_five_six__.hpp": [
"File __four_five_six__.hpp",
"file_include_interface_alpha___four_five_six_____four_five_six__.hpp"
],
"beta.hpp": [
"File beta.hpp",
"file_include_interface_beta_beta.hpp"
]
}
node_map = {
f.name: f for f in self.app.exhale_root.all_nodes if f.kind == "file"
}
self.check_title_link(f_map, node_map, "file")
def test_directories(self):
"""Verify that file nodes have correct title and link."""
# include/
# ├── interface_alpha
# │ ├── alpha.hpp
# │ ├── one_two_three
# │ │ └── one_two_three.hpp
# │ └── __four_five_six__
# │ └── __four_five_six__.hpp
# └── interface_beta
# └── beta.hpp
# Map: filename => [title, link_name]
d_map = {
"interface_alpha": [
"Directory interface_alpha",
"dir_include_interface_alpha"
],
"one_two_three": [
"Directory one_two_three",
"dir_include_interface_alpha_one_two_three"
],
"__four_five_six__": [
"Directory __four_five_six__",
"dir_include_interface_alpha___four_five_six__"
],
"interface_beta": [
"Directory interface_beta",
"dir_include_interface_beta"
]
}
node_map = {
# directory.name has the full path in it, just get the basename
os.path.basename(d.name): d
for d in self.app.exhale_root.all_nodes if d.kind == "dir"
}
self.check_title_link(d_map, node_map, "directory")
|