rolfedh-doc-utils 0.1.16__tar.gz → 0.1.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {rolfedh_doc_utils-0.1.16/rolfedh_doc_utils.egg-info → rolfedh_doc_utils-0.1.17}/PKG-INFO +1 -1
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/unused_attributes.py +50 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/find_unused_attributes.py +12 -1
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/pyproject.toml +1 -1
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17/rolfedh_doc_utils.egg-info}/PKG-INFO +1 -1
- rolfedh_doc_utils-0.1.17/tests/test_unused_attributes.py +199 -0
- rolfedh_doc_utils-0.1.16/tests/test_unused_attributes.py +0 -44
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/LICENSE +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/README.md +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/archive_unused_files.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/archive_unused_images.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/check_scannability.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/__init__.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/extract_link_attributes.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/file_utils.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/format_asciidoc_spacing.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/replace_link_attributes.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/scannability.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/spinner.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/topic_map_parser.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/unused_adoc.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/unused_images.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/validate_links.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/doc_utils/version_check.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/extract_link_attributes.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/format_asciidoc_spacing.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/replace_link_attributes.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/rolfedh_doc_utils.egg-info/SOURCES.txt +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/rolfedh_doc_utils.egg-info/dependency_links.txt +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/rolfedh_doc_utils.egg-info/entry_points.txt +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/rolfedh_doc_utils.egg-info/requires.txt +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/rolfedh_doc_utils.egg-info/top_level.txt +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/setup.cfg +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/setup.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_archive_unused_files.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_archive_unused_images.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_auto_discovery.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_check_scannability.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_cli_entry_points.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_extract_link_attributes.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_file_utils.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_fixture_archive_unused_files.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_fixture_archive_unused_images.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_fixture_check_scannability.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_parse_exclude_list.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_replace_link_attributes.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_symlink_handling.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_topic_map_parser.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_validate_links.py +0 -0
- {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/validate_links.py +0 -0
|
@@ -50,13 +50,22 @@ def find_adoc_files(root_dir: str) -> List[str]:
|
|
|
50
50
|
|
|
51
51
|
def scan_for_attribute_usage(adoc_files: List[str], attributes: Set[str]) -> Set[str]:
|
|
52
52
|
used = set()
|
|
53
|
+
# Pattern for attribute references: {attribute-name}
|
|
53
54
|
attr_pattern = re.compile(r'\{([\w-]+)\}')
|
|
55
|
+
# Patterns for conditional directives: ifdef::attr[], ifndef::attr[], endif::attr[]
|
|
56
|
+
conditional_pattern = re.compile(r'(?:ifdef|ifndef|endif)::([\w-]+)\[')
|
|
57
|
+
|
|
54
58
|
for file in adoc_files:
|
|
55
59
|
with open(file, 'r', encoding='utf-8') as f:
|
|
56
60
|
for line in f:
|
|
61
|
+
# Check for {attribute} references
|
|
57
62
|
for match in attr_pattern.findall(line):
|
|
58
63
|
if match in attributes:
|
|
59
64
|
used.add(match)
|
|
65
|
+
# Check for ifdef::attribute[], ifndef::attribute[], endif::attribute[]
|
|
66
|
+
for match in conditional_pattern.findall(line):
|
|
67
|
+
if match in attributes:
|
|
68
|
+
used.add(match)
|
|
60
69
|
return used
|
|
61
70
|
|
|
62
71
|
def find_attributes_files(root_dir: str = '.') -> List[str]:
|
|
@@ -136,3 +145,44 @@ def find_unused_attributes(attr_file: str, adoc_root: str = '.') -> List[str]:
|
|
|
136
145
|
used = scan_for_attribute_usage(adoc_files, attributes)
|
|
137
146
|
unused = sorted(attributes - used)
|
|
138
147
|
return unused
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def comment_out_unused_attributes(attr_file: str, unused_attrs: List[str]) -> int:
|
|
151
|
+
"""
|
|
152
|
+
Comment out unused attributes in the attributes file.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
attr_file: Path to the attributes file
|
|
156
|
+
unused_attrs: List of unused attribute names
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
Number of attributes commented out
|
|
160
|
+
"""
|
|
161
|
+
if not unused_attrs:
|
|
162
|
+
return 0
|
|
163
|
+
|
|
164
|
+
# Read the file
|
|
165
|
+
with open(attr_file, 'r', encoding='utf-8') as f:
|
|
166
|
+
lines = f.readlines()
|
|
167
|
+
|
|
168
|
+
# Create a set for faster lookup
|
|
169
|
+
unused_set = set(unused_attrs)
|
|
170
|
+
commented_count = 0
|
|
171
|
+
|
|
172
|
+
# Process each line
|
|
173
|
+
new_lines = []
|
|
174
|
+
for line in lines:
|
|
175
|
+
# Check if this line defines an attribute
|
|
176
|
+
match = re.match(r'^:([\w-]+):', line)
|
|
177
|
+
if match and match.group(1) in unused_set:
|
|
178
|
+
# Comment out this line
|
|
179
|
+
new_lines.append(f'// Unused {line}')
|
|
180
|
+
commented_count += 1
|
|
181
|
+
else:
|
|
182
|
+
new_lines.append(line)
|
|
183
|
+
|
|
184
|
+
# Write back to the file
|
|
185
|
+
with open(attr_file, 'w', encoding='utf-8') as f:
|
|
186
|
+
f.writelines(new_lines)
|
|
187
|
+
|
|
188
|
+
return commented_count
|
|
@@ -12,7 +12,7 @@ import argparse
|
|
|
12
12
|
import os
|
|
13
13
|
import sys
|
|
14
14
|
from datetime import datetime
|
|
15
|
-
from doc_utils.unused_attributes import find_unused_attributes, find_attributes_files, select_attributes_file
|
|
15
|
+
from doc_utils.unused_attributes import find_unused_attributes, find_attributes_files, select_attributes_file, comment_out_unused_attributes
|
|
16
16
|
from doc_utils.spinner import Spinner
|
|
17
17
|
from doc_utils.version_check import check_version_on_startup
|
|
18
18
|
|
|
@@ -26,6 +26,7 @@ def main():
|
|
|
26
26
|
help='Path to the attributes file. If not specified, auto-discovers attributes files.'
|
|
27
27
|
)
|
|
28
28
|
parser.add_argument('-o', '--output', action='store_true', help='Write results to a timestamped txt file in your home directory.')
|
|
29
|
+
parser.add_argument('-c', '--comment-out', action='store_true', help='Comment out unused attributes in the attributes file with "// Unused".')
|
|
29
30
|
args = parser.parse_args()
|
|
30
31
|
|
|
31
32
|
# Determine which attributes file to use
|
|
@@ -84,6 +85,16 @@ def main():
|
|
|
84
85
|
f.write(output + '\n')
|
|
85
86
|
print(f'Results written to: {filename}')
|
|
86
87
|
|
|
88
|
+
if args.comment_out and output:
|
|
89
|
+
# Ask for confirmation before modifying the file
|
|
90
|
+
print(f'\nThis will comment out {len(unused)} unused attributes in: {attr_file}')
|
|
91
|
+
response = input('Continue? (y/n): ').strip().lower()
|
|
92
|
+
if response == 'y':
|
|
93
|
+
commented_count = comment_out_unused_attributes(attr_file, unused)
|
|
94
|
+
print(f'Commented out {commented_count} unused attributes in: {attr_file}')
|
|
95
|
+
else:
|
|
96
|
+
print('Operation cancelled.')
|
|
97
|
+
|
|
87
98
|
return 0
|
|
88
99
|
|
|
89
100
|
if __name__ == '__main__':
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import tempfile
|
|
3
|
+
from doc_utils.unused_attributes import parse_attributes_file, find_adoc_files, scan_for_attribute_usage, find_unused_attributes, comment_out_unused_attributes
|
|
4
|
+
|
|
5
|
+
def make_file(path, content):
|
|
6
|
+
with open(path, 'w', encoding='utf-8') as f:
|
|
7
|
+
f.write(content)
|
|
8
|
+
|
|
9
|
+
def test_parse_attributes_file():
|
|
10
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
11
|
+
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
12
|
+
make_file(attr_path, ":foo: bar\n:bar: baz\n:unused: 123\n")
|
|
13
|
+
attrs = parse_attributes_file(attr_path)
|
|
14
|
+
assert 'foo' in attrs
|
|
15
|
+
assert 'bar' in attrs
|
|
16
|
+
assert 'unused' in attrs
|
|
17
|
+
|
|
18
|
+
def test_find_adoc_files_and_usage():
|
|
19
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
20
|
+
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
21
|
+
make_file(attr_path, ":foo: bar\n:bar: baz\n:unused: 123\n")
|
|
22
|
+
adoc1 = os.path.join(tmpdir, 'a.adoc')
|
|
23
|
+
adoc2 = os.path.join(tmpdir, 'b.adoc')
|
|
24
|
+
make_file(adoc1, "This uses {foo} and {bar}.")
|
|
25
|
+
make_file(adoc2, "No attributes here.")
|
|
26
|
+
adoc_files = find_adoc_files(tmpdir)
|
|
27
|
+
attrs = parse_attributes_file(attr_path)
|
|
28
|
+
used = scan_for_attribute_usage(adoc_files, attrs)
|
|
29
|
+
assert 'foo' in used
|
|
30
|
+
assert 'bar' in used
|
|
31
|
+
assert 'unused' not in used
|
|
32
|
+
|
|
33
|
+
def test_find_unused_attributes():
|
|
34
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
35
|
+
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
36
|
+
make_file(attr_path, ":foo: bar\n:bar: baz\n:unused: 123\n")
|
|
37
|
+
adoc1 = os.path.join(tmpdir, 'a.adoc')
|
|
38
|
+
adoc2 = os.path.join(tmpdir, 'b.adoc')
|
|
39
|
+
make_file(adoc1, "This uses {foo} and {bar}.")
|
|
40
|
+
make_file(adoc2, "No attributes here.")
|
|
41
|
+
unused = find_unused_attributes(attr_path, tmpdir)
|
|
42
|
+
assert 'unused' in unused
|
|
43
|
+
assert 'foo' not in unused
|
|
44
|
+
assert 'bar' not in unused
|
|
45
|
+
|
|
46
|
+
def test_conditional_directives_ifdef():
|
|
47
|
+
"""Test that ifdef::attribute:: is recognized as usage."""
|
|
48
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
49
|
+
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
50
|
+
make_file(attr_path, ":rh-only:\n:downstream:\n:unused:\n")
|
|
51
|
+
adoc1 = os.path.join(tmpdir, 'test.adoc')
|
|
52
|
+
make_file(adoc1, "ifdef::rh-only[]\nSome content\nendif::rh-only[]\n")
|
|
53
|
+
attrs = parse_attributes_file(attr_path)
|
|
54
|
+
adoc_files = find_adoc_files(tmpdir)
|
|
55
|
+
used = scan_for_attribute_usage(adoc_files, attrs)
|
|
56
|
+
assert 'rh-only' in used
|
|
57
|
+
assert 'downstream' not in used
|
|
58
|
+
assert 'unused' not in used
|
|
59
|
+
|
|
60
|
+
def test_conditional_directives_ifndef():
|
|
61
|
+
"""Test that ifndef::attribute:: is recognized as usage."""
|
|
62
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
63
|
+
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
64
|
+
make_file(attr_path, ":no-feature:\n:unused:\n")
|
|
65
|
+
adoc1 = os.path.join(tmpdir, 'test.adoc')
|
|
66
|
+
make_file(adoc1, "ifndef::no-feature[]\nContent when feature exists\nendif::no-feature[]\n")
|
|
67
|
+
attrs = parse_attributes_file(attr_path)
|
|
68
|
+
adoc_files = find_adoc_files(tmpdir)
|
|
69
|
+
used = scan_for_attribute_usage(adoc_files, attrs)
|
|
70
|
+
assert 'no-feature' in used
|
|
71
|
+
assert 'unused' not in used
|
|
72
|
+
|
|
73
|
+
def test_conditional_directives_endif():
|
|
74
|
+
"""Test that endif::attribute:: is recognized as usage."""
|
|
75
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
76
|
+
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
77
|
+
make_file(attr_path, ":my-attr:\n:unused:\n")
|
|
78
|
+
adoc1 = os.path.join(tmpdir, 'test.adoc')
|
|
79
|
+
make_file(adoc1, "ifdef::my-attr[]\nSome content\nendif::my-attr[]\n")
|
|
80
|
+
attrs = parse_attributes_file(attr_path)
|
|
81
|
+
adoc_files = find_adoc_files(tmpdir)
|
|
82
|
+
used = scan_for_attribute_usage(adoc_files, attrs)
|
|
83
|
+
assert 'my-attr' in used
|
|
84
|
+
assert 'unused' not in used
|
|
85
|
+
|
|
86
|
+
def test_mixed_usage_patterns():
|
|
87
|
+
"""Test attributes used in both {attr} and ifdef::attr:: forms."""
|
|
88
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
89
|
+
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
90
|
+
make_file(attr_path, ":version: 1.0\n:rh-only:\n:unused:\n")
|
|
91
|
+
adoc1 = os.path.join(tmpdir, 'test.adoc')
|
|
92
|
+
make_file(adoc1, "Version {version}\nifdef::rh-only[]\nRH content\nendif::rh-only[]\n")
|
|
93
|
+
unused = find_unused_attributes(attr_path, tmpdir)
|
|
94
|
+
assert 'unused' in unused
|
|
95
|
+
assert 'version' not in unused
|
|
96
|
+
assert 'rh-only' not in unused
|
|
97
|
+
|
|
98
|
+
def test_no_prefix_attributes():
|
|
99
|
+
"""Test attributes with 'no-' prefix used in ifndef directives."""
|
|
100
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
101
|
+
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
102
|
+
make_file(attr_path, ":no-quarkus-security-jpa-reactive:\n:no-webauthn-authentication:\n:unused:\n")
|
|
103
|
+
adoc1 = os.path.join(tmpdir, 'test.adoc')
|
|
104
|
+
make_file(adoc1, """
|
|
105
|
+
ifndef::no-quarkus-security-jpa-reactive[]
|
|
106
|
+
Content about JPA reactive security
|
|
107
|
+
endif::no-quarkus-security-jpa-reactive[]
|
|
108
|
+
|
|
109
|
+
ifndef::no-webauthn-authentication[]
|
|
110
|
+
Content about WebAuthn
|
|
111
|
+
endif::no-webauthn-authentication[]
|
|
112
|
+
""")
|
|
113
|
+
unused = find_unused_attributes(attr_path, tmpdir)
|
|
114
|
+
assert 'unused' in unused
|
|
115
|
+
assert 'no-quarkus-security-jpa-reactive' not in unused
|
|
116
|
+
assert 'no-webauthn-authentication' not in unused
|
|
117
|
+
|
|
118
|
+
def test_comment_out_unused_attributes():
|
|
119
|
+
"""Test commenting out unused attributes in the attributes file."""
|
|
120
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
121
|
+
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
122
|
+
original_content = """:version: 1.0
|
|
123
|
+
:product: MyApp
|
|
124
|
+
:unused1: value1
|
|
125
|
+
:unused2: value2
|
|
126
|
+
:rh-only:
|
|
127
|
+
"""
|
|
128
|
+
make_file(attr_path, original_content)
|
|
129
|
+
|
|
130
|
+
adoc1 = os.path.join(tmpdir, 'test.adoc')
|
|
131
|
+
make_file(adoc1, "Version {version} Product {product}\nifdef::rh-only[]\nContent\nendif::rh-only[]\n")
|
|
132
|
+
|
|
133
|
+
# Find unused attributes
|
|
134
|
+
unused = find_unused_attributes(attr_path, tmpdir)
|
|
135
|
+
assert 'unused1' in unused
|
|
136
|
+
assert 'unused2' in unused
|
|
137
|
+
assert 'version' not in unused
|
|
138
|
+
assert 'product' not in unused
|
|
139
|
+
assert 'rh-only' not in unused
|
|
140
|
+
|
|
141
|
+
# Comment out unused attributes
|
|
142
|
+
count = comment_out_unused_attributes(attr_path, unused)
|
|
143
|
+
assert count == 2
|
|
144
|
+
|
|
145
|
+
# Verify the file was modified correctly
|
|
146
|
+
with open(attr_path, 'r') as f:
|
|
147
|
+
content = f.read()
|
|
148
|
+
|
|
149
|
+
assert '// Unused :unused1: value1\n' in content
|
|
150
|
+
assert '// Unused :unused2: value2\n' in content
|
|
151
|
+
assert ':version: 1.0\n' in content
|
|
152
|
+
assert ':product: MyApp\n' in content
|
|
153
|
+
assert ':rh-only:\n' in content
|
|
154
|
+
|
|
155
|
+
def test_comment_out_empty_list():
|
|
156
|
+
"""Test that comment_out_unused_attributes handles empty list correctly."""
|
|
157
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
158
|
+
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
159
|
+
original_content = ":version: 1.0\n:product: MyApp\n"
|
|
160
|
+
make_file(attr_path, original_content)
|
|
161
|
+
|
|
162
|
+
# Comment out with empty list
|
|
163
|
+
count = comment_out_unused_attributes(attr_path, [])
|
|
164
|
+
assert count == 0
|
|
165
|
+
|
|
166
|
+
# Verify file was not modified
|
|
167
|
+
with open(attr_path, 'r') as f:
|
|
168
|
+
content = f.read()
|
|
169
|
+
|
|
170
|
+
assert content == original_content
|
|
171
|
+
|
|
172
|
+
def test_comment_out_preserves_formatting():
|
|
173
|
+
"""Test that commenting out preserves line formatting and comments."""
|
|
174
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
175
|
+
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
176
|
+
original_content = """// This is a comment
|
|
177
|
+
:version: 1.0
|
|
178
|
+
|
|
179
|
+
:unused: value with spaces
|
|
180
|
+
// Another comment
|
|
181
|
+
:product: MyApp
|
|
182
|
+
"""
|
|
183
|
+
make_file(attr_path, original_content)
|
|
184
|
+
|
|
185
|
+
adoc1 = os.path.join(tmpdir, 'test.adoc')
|
|
186
|
+
make_file(adoc1, "Version {version} Product {product}\n")
|
|
187
|
+
|
|
188
|
+
unused = find_unused_attributes(attr_path, tmpdir)
|
|
189
|
+
count = comment_out_unused_attributes(attr_path, unused)
|
|
190
|
+
assert count == 1
|
|
191
|
+
|
|
192
|
+
with open(attr_path, 'r') as f:
|
|
193
|
+
content = f.read()
|
|
194
|
+
|
|
195
|
+
assert '// This is a comment\n' in content
|
|
196
|
+
assert '// Unused :unused: value with spaces\n' in content
|
|
197
|
+
assert '// Another comment\n' in content
|
|
198
|
+
assert ':version: 1.0\n' in content
|
|
199
|
+
assert ':product: MyApp\n' in content
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import tempfile
|
|
3
|
-
from doc_utils.unused_attributes import parse_attributes_file, find_adoc_files, scan_for_attribute_usage, find_unused_attributes
|
|
4
|
-
|
|
5
|
-
def make_file(path, content):
|
|
6
|
-
with open(path, 'w', encoding='utf-8') as f:
|
|
7
|
-
f.write(content)
|
|
8
|
-
|
|
9
|
-
def test_parse_attributes_file():
|
|
10
|
-
with tempfile.TemporaryDirectory() as tmpdir:
|
|
11
|
-
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
12
|
-
make_file(attr_path, ":foo: bar\n:bar: baz\n:unused: 123\n")
|
|
13
|
-
attrs = parse_attributes_file(attr_path)
|
|
14
|
-
assert 'foo' in attrs
|
|
15
|
-
assert 'bar' in attrs
|
|
16
|
-
assert 'unused' in attrs
|
|
17
|
-
|
|
18
|
-
def test_find_adoc_files_and_usage():
|
|
19
|
-
with tempfile.TemporaryDirectory() as tmpdir:
|
|
20
|
-
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
21
|
-
make_file(attr_path, ":foo: bar\n:bar: baz\n:unused: 123\n")
|
|
22
|
-
adoc1 = os.path.join(tmpdir, 'a.adoc')
|
|
23
|
-
adoc2 = os.path.join(tmpdir, 'b.adoc')
|
|
24
|
-
make_file(adoc1, "This uses {foo} and {bar}.")
|
|
25
|
-
make_file(adoc2, "No attributes here.")
|
|
26
|
-
adoc_files = find_adoc_files(tmpdir)
|
|
27
|
-
attrs = parse_attributes_file(attr_path)
|
|
28
|
-
used = scan_for_attribute_usage(adoc_files, attrs)
|
|
29
|
-
assert 'foo' in used
|
|
30
|
-
assert 'bar' in used
|
|
31
|
-
assert 'unused' not in used
|
|
32
|
-
|
|
33
|
-
def test_find_unused_attributes():
|
|
34
|
-
with tempfile.TemporaryDirectory() as tmpdir:
|
|
35
|
-
attr_path = os.path.join(tmpdir, 'attributes.adoc')
|
|
36
|
-
make_file(attr_path, ":foo: bar\n:bar: baz\n:unused: 123\n")
|
|
37
|
-
adoc1 = os.path.join(tmpdir, 'a.adoc')
|
|
38
|
-
adoc2 = os.path.join(tmpdir, 'b.adoc')
|
|
39
|
-
make_file(adoc1, "This uses {foo} and {bar}.")
|
|
40
|
-
make_file(adoc2, "No attributes here.")
|
|
41
|
-
unused = find_unused_attributes(attr_path, tmpdir)
|
|
42
|
-
assert 'unused' in unused
|
|
43
|
-
assert 'foo' not in unused
|
|
44
|
-
assert 'bar' not in unused
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/rolfedh_doc_utils.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/rolfedh_doc_utils.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/rolfedh_doc_utils.egg-info/requires.txt
RENAMED
|
File without changes
|
{rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/rolfedh_doc_utils.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_fixture_archive_unused_files.py
RENAMED
|
File without changes
|
{rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_fixture_archive_unused_images.py
RENAMED
|
File without changes
|
{rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.17}/tests/test_fixture_check_scannability.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|