rolfedh-doc-utils 0.1.16__tar.gz → 0.1.18__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.
Files changed (50) hide show
  1. {rolfedh_doc_utils-0.1.16/rolfedh_doc_utils.egg-info → rolfedh_doc_utils-0.1.18}/PKG-INFO +1 -1
  2. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/unused_attributes.py +77 -1
  3. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/find_unused_attributes.py +12 -1
  4. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/pyproject.toml +1 -1
  5. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18/rolfedh_doc_utils.egg-info}/PKG-INFO +1 -1
  6. rolfedh_doc_utils-0.1.18/tests/test_unused_attributes.py +199 -0
  7. rolfedh_doc_utils-0.1.16/tests/test_unused_attributes.py +0 -44
  8. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/LICENSE +0 -0
  9. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/README.md +0 -0
  10. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/archive_unused_files.py +0 -0
  11. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/archive_unused_images.py +0 -0
  12. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/check_scannability.py +0 -0
  13. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/__init__.py +0 -0
  14. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/extract_link_attributes.py +0 -0
  15. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/file_utils.py +0 -0
  16. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/format_asciidoc_spacing.py +0 -0
  17. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/replace_link_attributes.py +0 -0
  18. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/scannability.py +0 -0
  19. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/spinner.py +0 -0
  20. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/topic_map_parser.py +0 -0
  21. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/unused_adoc.py +0 -0
  22. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/unused_images.py +0 -0
  23. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/validate_links.py +0 -0
  24. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/doc_utils/version_check.py +0 -0
  25. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/extract_link_attributes.py +0 -0
  26. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/format_asciidoc_spacing.py +0 -0
  27. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/replace_link_attributes.py +0 -0
  28. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/rolfedh_doc_utils.egg-info/SOURCES.txt +0 -0
  29. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/rolfedh_doc_utils.egg-info/dependency_links.txt +0 -0
  30. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/rolfedh_doc_utils.egg-info/entry_points.txt +0 -0
  31. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/rolfedh_doc_utils.egg-info/requires.txt +0 -0
  32. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/rolfedh_doc_utils.egg-info/top_level.txt +0 -0
  33. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/setup.cfg +0 -0
  34. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/setup.py +0 -0
  35. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_archive_unused_files.py +0 -0
  36. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_archive_unused_images.py +0 -0
  37. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_auto_discovery.py +0 -0
  38. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_check_scannability.py +0 -0
  39. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_cli_entry_points.py +0 -0
  40. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_extract_link_attributes.py +0 -0
  41. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_file_utils.py +0 -0
  42. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_fixture_archive_unused_files.py +0 -0
  43. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_fixture_archive_unused_images.py +0 -0
  44. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_fixture_check_scannability.py +0 -0
  45. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_parse_exclude_list.py +0 -0
  46. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_replace_link_attributes.py +0 -0
  47. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_symlink_handling.py +0 -0
  48. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_topic_map_parser.py +0 -0
  49. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/tests/test_validate_links.py +0 -0
  50. {rolfedh_doc_utils-0.1.16 → rolfedh_doc_utils-0.1.18}/validate_links.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rolfedh-doc-utils
3
- Version: 0.1.16
3
+ Version: 0.1.18
4
4
  Summary: CLI tools for AsciiDoc documentation projects
5
5
  Author: Rolfe Dlugy-Hegwer
6
6
  License: MIT License
@@ -15,6 +15,29 @@ from pathlib import Path
15
15
  from typing import Set, List, Optional
16
16
 
17
17
  def parse_attributes_file(attr_file: str) -> Set[str]:
18
+ # AsciiDoc configuration attributes that control the processor itself
19
+ # These should be ignored as they won't appear in content
20
+ IGNORED_ATTRIBUTES = {
21
+ 'data-uri',
22
+ 'doctype',
23
+ 'experimental',
24
+ 'idprefix',
25
+ 'imagesdir',
26
+ 'includes',
27
+ 'sectanchors',
28
+ 'sectlinks',
29
+ 'source-highlighter',
30
+ 'linkattrs',
31
+ 'toclevels',
32
+ 'idseparator',
33
+ 'icons',
34
+ 'iconsdir',
35
+ 'generated-dir',
36
+ 'code-examples',
37
+ 'doc-guides',
38
+ 'doc-examples',
39
+ }
40
+
18
41
  attributes = set()
19
42
 
20
43
  # Check if file exists
@@ -30,7 +53,10 @@ def parse_attributes_file(attr_file: str) -> Set[str]:
30
53
  for line in f:
31
54
  match = re.match(r'^:([\w-]+):', line.strip())
32
55
  if match:
33
- attributes.add(match.group(1))
56
+ attr_name = match.group(1)
57
+ # Skip ignored configuration attributes
58
+ if attr_name not in IGNORED_ATTRIBUTES:
59
+ attributes.add(attr_name)
34
60
  except PermissionError:
35
61
  raise PermissionError(f"Permission denied reading file: {attr_file}")
36
62
  except UnicodeDecodeError as e:
@@ -50,13 +76,22 @@ def find_adoc_files(root_dir: str) -> List[str]:
50
76
 
51
77
  def scan_for_attribute_usage(adoc_files: List[str], attributes: Set[str]) -> Set[str]:
52
78
  used = set()
79
+ # Pattern for attribute references: {attribute-name}
53
80
  attr_pattern = re.compile(r'\{([\w-]+)\}')
81
+ # Patterns for conditional directives: ifdef::attr[], ifndef::attr[], endif::attr[]
82
+ conditional_pattern = re.compile(r'(?:ifdef|ifndef|endif)::([\w-]+)\[')
83
+
54
84
  for file in adoc_files:
55
85
  with open(file, 'r', encoding='utf-8') as f:
56
86
  for line in f:
87
+ # Check for {attribute} references
57
88
  for match in attr_pattern.findall(line):
58
89
  if match in attributes:
59
90
  used.add(match)
91
+ # Check for ifdef::attribute[], ifndef::attribute[], endif::attribute[]
92
+ for match in conditional_pattern.findall(line):
93
+ if match in attributes:
94
+ used.add(match)
60
95
  return used
61
96
 
62
97
  def find_attributes_files(root_dir: str = '.') -> List[str]:
@@ -136,3 +171,44 @@ def find_unused_attributes(attr_file: str, adoc_root: str = '.') -> List[str]:
136
171
  used = scan_for_attribute_usage(adoc_files, attributes)
137
172
  unused = sorted(attributes - used)
138
173
  return unused
174
+
175
+
176
+ def comment_out_unused_attributes(attr_file: str, unused_attrs: List[str]) -> int:
177
+ """
178
+ Comment out unused attributes in the attributes file.
179
+
180
+ Args:
181
+ attr_file: Path to the attributes file
182
+ unused_attrs: List of unused attribute names
183
+
184
+ Returns:
185
+ Number of attributes commented out
186
+ """
187
+ if not unused_attrs:
188
+ return 0
189
+
190
+ # Read the file
191
+ with open(attr_file, 'r', encoding='utf-8') as f:
192
+ lines = f.readlines()
193
+
194
+ # Create a set for faster lookup
195
+ unused_set = set(unused_attrs)
196
+ commented_count = 0
197
+
198
+ # Process each line
199
+ new_lines = []
200
+ for line in lines:
201
+ # Check if this line defines an attribute
202
+ match = re.match(r'^:([\w-]+):', line)
203
+ if match and match.group(1) in unused_set:
204
+ # Comment out this line
205
+ new_lines.append(f'// Unused {line}')
206
+ commented_count += 1
207
+ else:
208
+ new_lines.append(line)
209
+
210
+ # Write back to the file
211
+ with open(attr_file, 'w', encoding='utf-8') as f:
212
+ f.writelines(new_lines)
213
+
214
+ 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__':
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rolfedh-doc-utils"
7
- version = "0.1.16"
7
+ version = "0.1.18"
8
8
  description = "CLI tools for AsciiDoc documentation projects"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rolfedh-doc-utils
3
- Version: 0.1.16
3
+ Version: 0.1.18
4
4
  Summary: CLI tools for AsciiDoc documentation projects
5
5
  Author: Rolfe Dlugy-Hegwer
6
6
  License: MIT License
@@ -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