speaker-claim-audit 0.1.0__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.
- speaker_claim_audit-0.1.0/LICENSE +21 -0
- speaker_claim_audit-0.1.0/MANIFEST.in +2 -0
- speaker_claim_audit-0.1.0/PKG-INFO +49 -0
- speaker_claim_audit-0.1.0/README.md +39 -0
- speaker_claim_audit-0.1.0/pyproject.toml +17 -0
- speaker_claim_audit-0.1.0/setup.cfg +4 -0
- speaker_claim_audit-0.1.0/speaker_claim_audit/__init__.py +2 -0
- speaker_claim_audit-0.1.0/speaker_claim_audit/__main__.py +42 -0
- speaker_claim_audit-0.1.0/speaker_claim_audit/audit.py +178 -0
- speaker_claim_audit-0.1.0/speaker_claim_audit/phrases.py +3 -0
- speaker_claim_audit-0.1.0/speaker_claim_audit.egg-info/PKG-INFO +49 -0
- speaker_claim_audit-0.1.0/speaker_claim_audit.egg-info/SOURCES.txt +25 -0
- speaker_claim_audit-0.1.0/speaker_claim_audit.egg-info/dependency_links.txt +1 -0
- speaker_claim_audit-0.1.0/speaker_claim_audit.egg-info/entry_points.txt +2 -0
- speaker_claim_audit-0.1.0/speaker_claim_audit.egg-info/top_level.txt +1 -0
- speaker_claim_audit-0.1.0/tests/__init__.py +0 -0
- speaker_claim_audit-0.1.0/tests/cases.py +2 -0
- speaker_claim_audit-0.1.0/tests/fixtures/.env +1 -0
- speaker_claim_audit-0.1.0/tests/fixtures/bad/README.md +1 -0
- speaker_claim_audit-0.1.0/tests/fixtures/bad/app.py +1 -0
- speaker_claim_audit-0.1.0/tests/fixtures/good/README.md +1 -0
- speaker_claim_audit-0.1.0/tests/fixtures/good/app.py +2 -0
- speaker_claim_audit-0.1.0/tests/fixtures/no-speaker/README.md +1 -0
- speaker_claim_audit-0.1.0/tests/fixtures/no-speaker/app.py +2 -0
- speaker_claim_audit-0.1.0/tests/fixtures/testonly/README.md +1 -0
- speaker_claim_audit-0.1.0/tests/fixtures/testonly/tests/test_audio.py +2 -0
- speaker_claim_audit-0.1.0/tests/test_audit.py +211 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 speaker-claim-audit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: speaker-claim-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline static audit of documented local sound emission
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# speaker-claim-audit
|
|
12
|
+
|
|
13
|
+
Version 0.1.0. An offline static audit comparing documentation about local sound emission with Python source evidence. Audited source is parsed as an AST and never executed. No third-party runtime dependencies are required.
|
|
14
|
+
|
|
15
|
+
Install and run:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
python3 -m pip install .
|
|
19
|
+
speaker-claim-audit /path/to/project
|
|
20
|
+
python3 -m speaker_claim_audit /path/to/project --json
|
|
21
|
+
python3 -m speaker_claim_audit /path/to/project --verbose --ignore 'vendor/*' --ignore 'docs/generated/*'
|
|
22
|
+
python3 -m speaker_claim_audit /path/to/project --fail-on MEDIUM
|
|
23
|
+
python3 -m speaker_claim_audit --version
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The positional root must be a readable directory. Repeatable `--ignore` globs match paths relative to that root. Root README.md and Markdown files beneath any docs component are checked. Fenced blocks are excluded; inline code counts. Matching folds case, contractions, hyphens, whitespace, and wrapped paragraph lines. Denials are removed before positive templates are matched.
|
|
27
|
+
|
|
28
|
+
Production source excludes tests, fixtures, docs, examples, test filename patterns, and symlinks. Imports and aliases resolve within each module. Supported providers are playsound, playsound2, pygame, sounddevice, simpleaudio, winsound, pydub.playback and pyaudio. Object routes require construction plus a driving call; pyaudio requires an explicit true output keyword. Verbose output lists source paths, lines and provider routes. JSON includes verdict, findings, evidence, test evidence and matched family flags.
|
|
29
|
+
|
|
30
|
+
A contradicted promise produces HIGH when production evidence is absent, or MEDIUM when evidence exists solely in tests. A contradicted denial produces HIGH when production evidence exists. Each family produces at most one finding. Without a matching template the result is PASS. Missing source contradicts a promise but is consistent with a denial.
|
|
31
|
+
|
|
32
|
+
Default failure threshold is HIGH. MEDIUM is reported with exit 0 unless `--fail-on MEDIUM` is selected. Exit 2 indicates failure at the selected threshold; exit 1 indicates invalid usage or an inaccessible root. `--version` prints 0.1.0.
|
|
33
|
+
|
|
34
|
+
## Limitations
|
|
35
|
+
|
|
36
|
+
Only the fixed documentation templates encoded in `speaker_claim_audit/phrases.py` are recognized. A bare device noun, user setup instructions, speech synthesis promises, file export promises, capture, screenshots and network sends are outside this audit's scope. The templates are deliberately exact; paraphrases may be missed.
|
|
37
|
+
|
|
38
|
+
External player helpers launched through subprocesses are outside the recognized routes. Shell command strings do not establish evidence. Imports, metadata reads, object construction alone, file writes, volume adjustments, capture and speech synthesis alone do not establish evidence either.
|
|
39
|
+
|
|
40
|
+
This is a static fingerprint check, not a hardware test. It cannot prove reachability, device availability or successful execution. Bindings are module-local and do not follow cross-module objects, dynamic imports or runtime reassignment. Invalid source is skipped. Symlinked source is skipped. Environment files are never read.
|
|
41
|
+
|
|
42
|
+
## Development
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
python3 -m unittest discover
|
|
46
|
+
python3 -m build
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The source distribution includes the test suite and fixtures. MIT licensed.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# speaker-claim-audit
|
|
2
|
+
|
|
3
|
+
Version 0.1.0. An offline static audit comparing documentation about local sound emission with Python source evidence. Audited source is parsed as an AST and never executed. No third-party runtime dependencies are required.
|
|
4
|
+
|
|
5
|
+
Install and run:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
python3 -m pip install .
|
|
9
|
+
speaker-claim-audit /path/to/project
|
|
10
|
+
python3 -m speaker_claim_audit /path/to/project --json
|
|
11
|
+
python3 -m speaker_claim_audit /path/to/project --verbose --ignore 'vendor/*' --ignore 'docs/generated/*'
|
|
12
|
+
python3 -m speaker_claim_audit /path/to/project --fail-on MEDIUM
|
|
13
|
+
python3 -m speaker_claim_audit --version
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The positional root must be a readable directory. Repeatable `--ignore` globs match paths relative to that root. Root README.md and Markdown files beneath any docs component are checked. Fenced blocks are excluded; inline code counts. Matching folds case, contractions, hyphens, whitespace, and wrapped paragraph lines. Denials are removed before positive templates are matched.
|
|
17
|
+
|
|
18
|
+
Production source excludes tests, fixtures, docs, examples, test filename patterns, and symlinks. Imports and aliases resolve within each module. Supported providers are playsound, playsound2, pygame, sounddevice, simpleaudio, winsound, pydub.playback and pyaudio. Object routes require construction plus a driving call; pyaudio requires an explicit true output keyword. Verbose output lists source paths, lines and provider routes. JSON includes verdict, findings, evidence, test evidence and matched family flags.
|
|
19
|
+
|
|
20
|
+
A contradicted promise produces HIGH when production evidence is absent, or MEDIUM when evidence exists solely in tests. A contradicted denial produces HIGH when production evidence exists. Each family produces at most one finding. Without a matching template the result is PASS. Missing source contradicts a promise but is consistent with a denial.
|
|
21
|
+
|
|
22
|
+
Default failure threshold is HIGH. MEDIUM is reported with exit 0 unless `--fail-on MEDIUM` is selected. Exit 2 indicates failure at the selected threshold; exit 1 indicates invalid usage or an inaccessible root. `--version` prints 0.1.0.
|
|
23
|
+
|
|
24
|
+
## Limitations
|
|
25
|
+
|
|
26
|
+
Only the fixed documentation templates encoded in `speaker_claim_audit/phrases.py` are recognized. A bare device noun, user setup instructions, speech synthesis promises, file export promises, capture, screenshots and network sends are outside this audit's scope. The templates are deliberately exact; paraphrases may be missed.
|
|
27
|
+
|
|
28
|
+
External player helpers launched through subprocesses are outside the recognized routes. Shell command strings do not establish evidence. Imports, metadata reads, object construction alone, file writes, volume adjustments, capture and speech synthesis alone do not establish evidence either.
|
|
29
|
+
|
|
30
|
+
This is a static fingerprint check, not a hardware test. It cannot prove reachability, device availability or successful execution. Bindings are module-local and do not follow cross-module objects, dynamic imports or runtime reassignment. Invalid source is skipped. Symlinked source is skipped. Environment files are never read.
|
|
31
|
+
|
|
32
|
+
## Development
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
python3 -m unittest discover
|
|
36
|
+
python3 -m build
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The source distribution includes the test suite and fixtures. MIT licensed.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "speaker-claim-audit"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Offline static audit of documented local sound emission"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
speaker-claim-audit = "speaker_claim_audit.__main__:main"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
include = ["speaker_claim_audit*"]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Command line entry point."""
|
|
2
|
+
import argparse
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
from . import __version__
|
|
6
|
+
from .audit import audit
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Parser(argparse.ArgumentParser):
|
|
10
|
+
def error(self, message):
|
|
11
|
+
self.print_usage(sys.stderr)
|
|
12
|
+
self.exit(1, '%s: error: %s\n' % (self.prog, message))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main(argv=None):
|
|
16
|
+
parser = Parser(description='Audit documented local sound emission against static source evidence.')
|
|
17
|
+
parser.add_argument('root')
|
|
18
|
+
parser.add_argument('--json', action='store_true')
|
|
19
|
+
parser.add_argument('--verbose', action='store_true')
|
|
20
|
+
parser.add_argument('--ignore', action='append', default=[])
|
|
21
|
+
parser.add_argument('--fail-on', choices=['HIGH', 'MEDIUM'], default='HIGH')
|
|
22
|
+
parser.add_argument('--version', action='version', version=__version__)
|
|
23
|
+
args = parser.parse_args(argv)
|
|
24
|
+
try:
|
|
25
|
+
result = audit(args.root, args.ignore, args.fail_on)
|
|
26
|
+
except (OSError, ValueError) as exc:
|
|
27
|
+
parser.error(str(exc))
|
|
28
|
+
if args.json:
|
|
29
|
+
print(json.dumps(result))
|
|
30
|
+
else:
|
|
31
|
+
print(result['verdict'])
|
|
32
|
+
for finding in result['findings']:
|
|
33
|
+
print('{severity} {rule}: {message}'.format(**finding))
|
|
34
|
+
if args.verbose:
|
|
35
|
+
for key in ('evidence', 'test_evidence'):
|
|
36
|
+
for hit in result[key]:
|
|
37
|
+
print('%s %s:%s %s' % (key, hit['path'], hit['line'], hit['route']))
|
|
38
|
+
return 2 if result['verdict'] == 'FAIL' else 0
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == '__main__':
|
|
42
|
+
sys.exit(main())
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"""Static claim matching and provider resolution; audited code is never run."""
|
|
2
|
+
import ast
|
|
3
|
+
import fnmatch
|
|
4
|
+
import re
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from .phrases import SPEAKER, NOSPEAKER
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def normalize(text):
|
|
10
|
+
return re.sub(r'\s+', ' ', text.lower().replace("n't", ' not').replace('-', ' ')).strip()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def pattern(phrases):
|
|
14
|
+
return re.compile(r'\b(?:' + '|'.join(re.escape(p) for p in sorted(phrases, key=len, reverse=True)) + r')\b')
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def claims(text):
|
|
18
|
+
paragraphs, current = [], []
|
|
19
|
+
fence = None
|
|
20
|
+
for line in text.splitlines():
|
|
21
|
+
marker = re.match(r'^\s{0,3}(`{3,}|~{3,})', line)
|
|
22
|
+
if marker:
|
|
23
|
+
token = marker.group(1)
|
|
24
|
+
if fence is None:
|
|
25
|
+
if current:
|
|
26
|
+
paragraphs.append(' '.join(current))
|
|
27
|
+
current = []
|
|
28
|
+
fence = token
|
|
29
|
+
elif token[0] == fence[0] and len(token) >= len(fence):
|
|
30
|
+
fence = None
|
|
31
|
+
continue
|
|
32
|
+
if fence:
|
|
33
|
+
continue
|
|
34
|
+
if not line.strip():
|
|
35
|
+
paragraphs.append(' '.join(current))
|
|
36
|
+
current = []
|
|
37
|
+
else:
|
|
38
|
+
current.append(line)
|
|
39
|
+
paragraphs.append(' '.join(current))
|
|
40
|
+
positive = negative = False
|
|
41
|
+
for paragraph in paragraphs:
|
|
42
|
+
text = normalize(paragraph)
|
|
43
|
+
negative |= bool(pattern(NOSPEAKER).search(text))
|
|
44
|
+
positive |= bool(pattern(SPEAKER).search(pattern(NOSPEAKER).sub(' ', text)))
|
|
45
|
+
return positive, negative
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def dotted(node):
|
|
49
|
+
if isinstance(node, ast.Name):
|
|
50
|
+
return node.id
|
|
51
|
+
if isinstance(node, ast.Attribute):
|
|
52
|
+
base = dotted(node.value)
|
|
53
|
+
return base + '.' + node.attr if base else ''
|
|
54
|
+
return ''
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def evidence(source):
|
|
58
|
+
try:
|
|
59
|
+
tree = ast.parse(source)
|
|
60
|
+
except (SyntaxError, ValueError):
|
|
61
|
+
return []
|
|
62
|
+
aliases, imported = {}, set()
|
|
63
|
+
for node in ast.walk(tree):
|
|
64
|
+
if isinstance(node, ast.Import):
|
|
65
|
+
for item in node.names:
|
|
66
|
+
aliases[item.asname or item.name.split('.')[0]] = item.name if item.asname else item.name.split('.')[0]
|
|
67
|
+
elif isinstance(node, ast.ImportFrom) and node.module and not node.level:
|
|
68
|
+
for item in node.names:
|
|
69
|
+
if item.name != '*':
|
|
70
|
+
local = item.asname or item.name
|
|
71
|
+
aliases[local] = node.module + '.' + item.name
|
|
72
|
+
imported.add(local)
|
|
73
|
+
|
|
74
|
+
def resolve(node):
|
|
75
|
+
path = dotted(node)
|
|
76
|
+
first, sep, rest = path.partition('.')
|
|
77
|
+
return aliases.get(first, first) + (sep + rest if sep else '')
|
|
78
|
+
|
|
79
|
+
def provider(path, base):
|
|
80
|
+
return path == base or path.startswith(base + '.')
|
|
81
|
+
|
|
82
|
+
def constructor(node):
|
|
83
|
+
if not isinstance(node, ast.Call):
|
|
84
|
+
return None
|
|
85
|
+
path = resolve(node.func)
|
|
86
|
+
if provider(path, 'pygame') and path.endswith('.mixer.Sound'):
|
|
87
|
+
return 'sound'
|
|
88
|
+
if provider(path, 'simpleaudio') and (path.endswith('.WaveObject') or path.endswith('.WaveObject.from_wave_file')):
|
|
89
|
+
return 'wave'
|
|
90
|
+
if provider(path, 'pyaudio') and path.endswith('.PyAudio'):
|
|
91
|
+
return 'engine'
|
|
92
|
+
if isinstance(node.func, ast.Attribute) and node.func.attr == 'open':
|
|
93
|
+
receiver = node.func.value
|
|
94
|
+
is_engine = provider(resolve(receiver), 'pyaudio') or bindings.get(dotted(receiver)) == 'engine' or constructor(receiver) == 'engine'
|
|
95
|
+
if is_engine and any(k.arg == 'output' and isinstance(k.value, ast.Constant) and k.value.value is True for k in node.keywords):
|
|
96
|
+
return 'stream'
|
|
97
|
+
return None
|
|
98
|
+
|
|
99
|
+
bindings = {}
|
|
100
|
+
assignments = [n for n in ast.walk(tree) if isinstance(n, ast.Assign)]
|
|
101
|
+
# Fixed point permits module-local bindings located in separate methods.
|
|
102
|
+
for _ in range(len(assignments) + 1):
|
|
103
|
+
changed = False
|
|
104
|
+
for node in assignments:
|
|
105
|
+
kind = constructor(node.value)
|
|
106
|
+
if kind:
|
|
107
|
+
for target in node.targets:
|
|
108
|
+
name = dotted(target)
|
|
109
|
+
if name and bindings.get(name) != kind:
|
|
110
|
+
bindings[name] = kind
|
|
111
|
+
changed = True
|
|
112
|
+
if not changed:
|
|
113
|
+
break
|
|
114
|
+
found = []
|
|
115
|
+
for node in ast.walk(tree):
|
|
116
|
+
if not isinstance(node, ast.Call):
|
|
117
|
+
continue
|
|
118
|
+
func = node.func
|
|
119
|
+
path = resolve(func)
|
|
120
|
+
leaf = path.rsplit('.', 1)[-1]
|
|
121
|
+
direct = isinstance(func, ast.Name) and func.id in imported
|
|
122
|
+
route = None
|
|
123
|
+
if any(provider(path, p) for p in ('playsound', 'playsound2')) and (direct or isinstance(func, ast.Attribute) and func.attr == 'playsound'):
|
|
124
|
+
route = 'playsound'
|
|
125
|
+
elif provider(path, 'sounddevice') and leaf == 'play':
|
|
126
|
+
route = 'sounddevice'
|
|
127
|
+
elif provider(path, 'winsound') and leaf in ('PlaySound', 'Beep', 'MessageBeep'):
|
|
128
|
+
route = 'winsound'
|
|
129
|
+
elif direct and provider(path, 'pydub.playback') and leaf == 'play':
|
|
130
|
+
route = 'pydub'
|
|
131
|
+
elif isinstance(func, ast.Attribute):
|
|
132
|
+
receiver = func.value
|
|
133
|
+
kind = bindings.get(dotted(receiver)) or constructor(receiver)
|
|
134
|
+
music = resolve(receiver)
|
|
135
|
+
if func.attr == 'play' and (kind in ('sound', 'wave') or provider(music, 'pygame') and music.endswith('.mixer.music')):
|
|
136
|
+
route = 'pygame' if kind != 'wave' else 'simpleaudio'
|
|
137
|
+
elif func.attr == 'write' and kind == 'stream':
|
|
138
|
+
route = 'pyaudio'
|
|
139
|
+
if route:
|
|
140
|
+
found.append({'line': node.lineno, 'route': route})
|
|
141
|
+
return sorted(found, key=lambda item: item['line'])
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def audit(root, ignores=(), fail_on='HIGH'):
|
|
145
|
+
root = Path(root)
|
|
146
|
+
if not root.is_dir() or not root.stat().st_mode & 0o444 or not root.stat().st_mode & 0o111:
|
|
147
|
+
raise ValueError('root must be a readable directory')
|
|
148
|
+
positive = negative = False
|
|
149
|
+
prod, tests = [], []
|
|
150
|
+
for path in sorted(root.rglob('*')):
|
|
151
|
+
relative = path.relative_to(root)
|
|
152
|
+
parts = relative.parts
|
|
153
|
+
if path.is_symlink() or any(parent.is_symlink() for parent in path.parents if parent != root) or not path.is_file():
|
|
154
|
+
continue
|
|
155
|
+
if any(fnmatch.fnmatch(relative.as_posix(), glob) for glob in ignores):
|
|
156
|
+
continue
|
|
157
|
+
is_doc = relative.as_posix() == 'README.md' or path.suffix.lower() == '.md' and 'docs' in parts[:-1]
|
|
158
|
+
if not is_doc and path.suffix != '.py':
|
|
159
|
+
continue
|
|
160
|
+
text = path.read_text(encoding='utf-8', errors='replace')
|
|
161
|
+
if is_doc:
|
|
162
|
+
yes, no = claims(text)
|
|
163
|
+
positive |= yes
|
|
164
|
+
negative |= no
|
|
165
|
+
else:
|
|
166
|
+
test = 'tests' in parts[:-1] or path.name.startswith('test_') or path.name.endswith('_test.py')
|
|
167
|
+
excluded = any(p in ('fixtures', 'docs', 'examples') for p in parts[:-1])
|
|
168
|
+
if excluded:
|
|
169
|
+
continue
|
|
170
|
+
for hit in evidence(text):
|
|
171
|
+
(tests if test else prod).append(dict(hit, path=relative.as_posix()))
|
|
172
|
+
findings = []
|
|
173
|
+
if positive and not prod:
|
|
174
|
+
findings.append({'rule': 'documented-speaker-claim-false', 'severity': 'MEDIUM' if tests else 'HIGH', 'message': 'Local-emission promise lacks production evidence.'})
|
|
175
|
+
if negative and prod:
|
|
176
|
+
findings.append({'rule': 'documented-no-speaker-claim-false', 'severity': 'HIGH', 'message': 'Local-emission denial conflicts with production evidence.'})
|
|
177
|
+
failed = any(f['severity'] == 'HIGH' or fail_on == 'MEDIUM' for f in findings)
|
|
178
|
+
return {'verdict': 'FAIL' if failed else 'PASS', 'findings': findings, 'evidence': prod, 'test_evidence': tests, 'claims': {'positive': positive, 'negative': negative}}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"""Exact documentation templates."""
|
|
2
|
+
SPEAKER = ('plays audio through your speakers', 'play audio through your speakers', 'plays sound through your speakers', 'play sound through your speakers', 'plays music through your speakers', 'play music through your speakers', 'plays audio on your speakers', 'play audio on your speakers', 'plays notification sounds', 'play notification sounds', 'plays alert sounds', 'play alert sounds', 'plays an alert sound', 'play an alert sound', 'plays sound effects', 'play sound effects', 'plays audio files', 'play audio files', 'plays music files', 'play music files', 'plays sound files', 'play sound files', 'plays wav files', 'play wav files', 'plays mp3 files', 'play mp3 files', 'audio playback through your speakers', 'supports audio playback', 'audio playback support', 'supports speaker output', 'speaker output support', 'plays back audio', 'play back audio', 'plays a sound', 'play a sound', 'plays audio', 'play audio', 'plays music', 'play music', 'plays sounds', 'play sounds', 'audible alerts', 'audible notifications', 'audible alert', 'emits a beep', 'emits beeps', 'beeps when')
|
|
3
|
+
NOSPEAKER = ('does not play audio through your speakers', 'does not play sound through your speakers', 'does not play music through your speakers', 'does not play notification sounds', 'does not play alert sounds', 'does not play audio files', 'does not play music files', 'does not play sound files', 'does not play audio', 'does not play music', 'does not play sounds', 'does not play a sound', 'does not use your speakers', 'does not access your speakers', 'audio playback not supported', 'speaker output not supported', 'sound effects not supported', 'no audio playback', 'without audio playback', 'no speaker output', 'without speaker output', 'no audible alerts', 'no sound effects', 'does not emit beeps', 'does not beep', 'no beeps')
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: speaker-claim-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline static audit of documented local sound emission
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# speaker-claim-audit
|
|
12
|
+
|
|
13
|
+
Version 0.1.0. An offline static audit comparing documentation about local sound emission with Python source evidence. Audited source is parsed as an AST and never executed. No third-party runtime dependencies are required.
|
|
14
|
+
|
|
15
|
+
Install and run:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
python3 -m pip install .
|
|
19
|
+
speaker-claim-audit /path/to/project
|
|
20
|
+
python3 -m speaker_claim_audit /path/to/project --json
|
|
21
|
+
python3 -m speaker_claim_audit /path/to/project --verbose --ignore 'vendor/*' --ignore 'docs/generated/*'
|
|
22
|
+
python3 -m speaker_claim_audit /path/to/project --fail-on MEDIUM
|
|
23
|
+
python3 -m speaker_claim_audit --version
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The positional root must be a readable directory. Repeatable `--ignore` globs match paths relative to that root. Root README.md and Markdown files beneath any docs component are checked. Fenced blocks are excluded; inline code counts. Matching folds case, contractions, hyphens, whitespace, and wrapped paragraph lines. Denials are removed before positive templates are matched.
|
|
27
|
+
|
|
28
|
+
Production source excludes tests, fixtures, docs, examples, test filename patterns, and symlinks. Imports and aliases resolve within each module. Supported providers are playsound, playsound2, pygame, sounddevice, simpleaudio, winsound, pydub.playback and pyaudio. Object routes require construction plus a driving call; pyaudio requires an explicit true output keyword. Verbose output lists source paths, lines and provider routes. JSON includes verdict, findings, evidence, test evidence and matched family flags.
|
|
29
|
+
|
|
30
|
+
A contradicted promise produces HIGH when production evidence is absent, or MEDIUM when evidence exists solely in tests. A contradicted denial produces HIGH when production evidence exists. Each family produces at most one finding. Without a matching template the result is PASS. Missing source contradicts a promise but is consistent with a denial.
|
|
31
|
+
|
|
32
|
+
Default failure threshold is HIGH. MEDIUM is reported with exit 0 unless `--fail-on MEDIUM` is selected. Exit 2 indicates failure at the selected threshold; exit 1 indicates invalid usage or an inaccessible root. `--version` prints 0.1.0.
|
|
33
|
+
|
|
34
|
+
## Limitations
|
|
35
|
+
|
|
36
|
+
Only the fixed documentation templates encoded in `speaker_claim_audit/phrases.py` are recognized. A bare device noun, user setup instructions, speech synthesis promises, file export promises, capture, screenshots and network sends are outside this audit's scope. The templates are deliberately exact; paraphrases may be missed.
|
|
37
|
+
|
|
38
|
+
External player helpers launched through subprocesses are outside the recognized routes. Shell command strings do not establish evidence. Imports, metadata reads, object construction alone, file writes, volume adjustments, capture and speech synthesis alone do not establish evidence either.
|
|
39
|
+
|
|
40
|
+
This is a static fingerprint check, not a hardware test. It cannot prove reachability, device availability or successful execution. Bindings are module-local and do not follow cross-module objects, dynamic imports or runtime reassignment. Invalid source is skipped. Symlinked source is skipped. Environment files are never read.
|
|
41
|
+
|
|
42
|
+
## Development
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
python3 -m unittest discover
|
|
46
|
+
python3 -m build
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The source distribution includes the test suite and fixtures. MIT licensed.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
speaker_claim_audit/__init__.py
|
|
6
|
+
speaker_claim_audit/__main__.py
|
|
7
|
+
speaker_claim_audit/audit.py
|
|
8
|
+
speaker_claim_audit/phrases.py
|
|
9
|
+
speaker_claim_audit.egg-info/PKG-INFO
|
|
10
|
+
speaker_claim_audit.egg-info/SOURCES.txt
|
|
11
|
+
speaker_claim_audit.egg-info/dependency_links.txt
|
|
12
|
+
speaker_claim_audit.egg-info/entry_points.txt
|
|
13
|
+
speaker_claim_audit.egg-info/top_level.txt
|
|
14
|
+
tests/__init__.py
|
|
15
|
+
tests/cases.py
|
|
16
|
+
tests/test_audit.py
|
|
17
|
+
tests/fixtures/.env
|
|
18
|
+
tests/fixtures/bad/README.md
|
|
19
|
+
tests/fixtures/bad/app.py
|
|
20
|
+
tests/fixtures/good/README.md
|
|
21
|
+
tests/fixtures/good/app.py
|
|
22
|
+
tests/fixtures/no-speaker/README.md
|
|
23
|
+
tests/fixtures/no-speaker/app.py
|
|
24
|
+
tests/fixtures/testonly/README.md
|
|
25
|
+
tests/fixtures/testonly/tests/test_audio.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
speaker_claim_audit
|
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
GOOD = ['from playsound import playsound\nplaysound("x.wav")', 'import playsound as ps\nps.playsound("x.wav")', 'import playsound2\nplaysound2.playsound("x.wav")', 'import pygame\npygame.mixer.music.play()', 'import pygame\ns=pygame.mixer.Sound("x.wav")\ns.play()', 'import pygame as pg\npg.mixer.music.play()', 'import pygame\nself.s=pygame.mixer.Sound("x.wav")\nself.s.play()', 'import pygame\npygame.mixer.Sound("x.wav").play()', 'import sounddevice as sd\nsd.play(data)', 'from sounddevice import play\nplay(data)', 'import simpleaudio as sa\nw=sa.WaveObject(data)\nw.play()', 'from simpleaudio import WaveObject\nWaveObject(data).play()', 'import winsound\nwinsound.Beep(440,100)', 'from winsound import PlaySound\nPlaySound("x.wav",0)', 'from pydub.playback import play\nplay(seg)', 'import pyaudio\np=pyaudio.PyAudio()\nstream=p.open(output=True)\nstream.write(data)', 'import pyaudio\np=pyaudio.PyAudio()\np.open(output=True).write(data)']
|
|
2
|
+
BAD = ['import pygame', 'value="speaker"', 'import pygame\ns=pygame.mixer.Sound("x.wav")', 's.play(data)', 'import pygame\npygame.mixer.init()', 'import wave\nw=wave.open("x.wav","wb")\nw.writeframes(data)', 'import subprocess\nsubprocess.run(["ffplay","x.wav"])', 'import pyttsx3\np=pyttsx3.init()\np.say("hello")', 'import sounddevice as sd\nsd.rec(100)', 'import pyaudio\np=pyaudio.PyAudio()\ns=p.open(input=True)\ns.write(data)', 'import pygame\npygame.mixer.music.set_volume(1)']
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MARKER_ONLY_DO_NOT_READ
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
plays audio
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import pygame
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
plays audio
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
no audio playback
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
plays audio
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"""Spec 1–43; generated phrase tests each cover the literal in their name/docstring."""
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import re
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import tempfile
|
|
8
|
+
import unittest
|
|
9
|
+
from unittest.mock import patch
|
|
10
|
+
from speaker_claim_audit.audit import audit, claims, evidence, normalize
|
|
11
|
+
from speaker_claim_audit.phrases import SPEAKER, NOSPEAKER
|
|
12
|
+
from tests.cases import GOOD, BAD
|
|
13
|
+
|
|
14
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AuditTests(unittest.TestCase):
|
|
18
|
+
def fixture(self, doc='plays audio', source=None, filename='app.py'):
|
|
19
|
+
temp = tempfile.TemporaryDirectory()
|
|
20
|
+
self.addCleanup(temp.cleanup)
|
|
21
|
+
root = Path(temp.name)
|
|
22
|
+
(root / 'README.md').write_text(doc)
|
|
23
|
+
if source is not None:
|
|
24
|
+
target = root / filename
|
|
25
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
26
|
+
target.write_text(source)
|
|
27
|
+
return root
|
|
28
|
+
|
|
29
|
+
def cli(self, root, *args):
|
|
30
|
+
return subprocess.run([sys.executable, '-m', 'speaker_claim_audit', str(root), *args], capture_output=True, text=True)
|
|
31
|
+
|
|
32
|
+
def assert_bad(self, source):
|
|
33
|
+
root = self.fixture(source=source)
|
|
34
|
+
result = audit(root)
|
|
35
|
+
self.assertEqual(result['findings'][0]['rule'], 'documented-speaker-claim-false')
|
|
36
|
+
self.assertEqual(result['findings'][0]['severity'], 'HIGH')
|
|
37
|
+
self.assertEqual(len(result['findings']), 1)
|
|
38
|
+
self.assertEqual(self.cli(root).returncode, 2)
|
|
39
|
+
|
|
40
|
+
def test_29_no_speaker(self):
|
|
41
|
+
root = self.fixture('no audio playback', GOOD[0])
|
|
42
|
+
self.assertEqual(audit(root)['findings'], [{'rule':'documented-no-speaker-claim-false','severity':'HIGH','message':'Local-emission denial conflicts with production evidence.'}])
|
|
43
|
+
self.assertEqual(self.cli(root).returncode, 2)
|
|
44
|
+
|
|
45
|
+
def test_30_no_claim(self):
|
|
46
|
+
self.assertEqual(audit(self.fixture('A utility.', GOOD[0]))['verdict'], 'PASS')
|
|
47
|
+
|
|
48
|
+
def test_31_bare_noun(self):
|
|
49
|
+
self.assertEqual(audit(self.fixture('the speaker chapter explains setup', BAD[0]))['claims'], {'positive':False,'negative':False})
|
|
50
|
+
|
|
51
|
+
def test_32_user_instruction(self):
|
|
52
|
+
self.assertEqual(audit(self.fixture('connect your speakers before starting', BAD[0]))['verdict'], 'PASS')
|
|
53
|
+
|
|
54
|
+
def test_33_speech(self):
|
|
55
|
+
self.assertEqual(audit(self.fixture('speaks answers aloud', BAD[7]))['verdict'], 'PASS')
|
|
56
|
+
|
|
57
|
+
def test_34_export(self):
|
|
58
|
+
self.assertEqual(audit(self.fixture('exports audio for later listening', 'seg.export("x.wav")'))['verdict'], 'PASS')
|
|
59
|
+
|
|
60
|
+
def test_35_no_source(self):
|
|
61
|
+
self.assertEqual(audit(self.fixture())['findings'][0]['severity'], 'HIGH')
|
|
62
|
+
self.assertEqual(audit(self.fixture('no audio playback'))['verdict'], 'PASS')
|
|
63
|
+
|
|
64
|
+
def test_36_tests_only(self):
|
|
65
|
+
for filename in ['tests/audio.py', 'test_audio.py', 'audio_test.py']:
|
|
66
|
+
with self.subTest(filename=filename):
|
|
67
|
+
root = self.fixture(source=GOOD[0], filename=filename)
|
|
68
|
+
self.assertEqual(audit(root)['findings'][0]['severity'], 'MEDIUM')
|
|
69
|
+
self.assertEqual(self.cli(root).returncode, 0)
|
|
70
|
+
self.assertEqual(self.cli(root, '--fail-on', 'MEDIUM').returncode, 2)
|
|
71
|
+
|
|
72
|
+
def test_37_fences_inline(self):
|
|
73
|
+
for fence in ['```', '~~~~']:
|
|
74
|
+
self.assertEqual(claims(fence+'\nplays audio\n'+fence), (False,False))
|
|
75
|
+
self.assertEqual(audit(self.fixture('`plays audio`'))['findings'][0]['severity'], 'HIGH')
|
|
76
|
+
|
|
77
|
+
def test_38_negation(self):
|
|
78
|
+
self.assertEqual(claims('does not play audio through your speakers'), (False,True))
|
|
79
|
+
self.assertEqual(claims("doesn't play audio through your speakers"), (False,True))
|
|
80
|
+
|
|
81
|
+
def test_39_self_audit(self):
|
|
82
|
+
result = audit(ROOT)
|
|
83
|
+
self.assertEqual(result['verdict'], 'PASS')
|
|
84
|
+
self.assertEqual(result['claims'], {'positive':False,'negative':False})
|
|
85
|
+
text = normalize((ROOT/'README.md').read_text())
|
|
86
|
+
for phrase in SPEAKER + NOSPEAKER:
|
|
87
|
+
self.assertIsNone(re.search(r'\b'+re.escape(phrase)+r'\b', text), phrase)
|
|
88
|
+
|
|
89
|
+
def test_40_cli(self):
|
|
90
|
+
root = self.fixture(source=GOOD[0])
|
|
91
|
+
self.assertEqual(self.cli(root, '--version').stdout.strip(), '0.1.0')
|
|
92
|
+
self.assertEqual(json.loads(self.cli(root, '--json').stdout)['verdict'], 'PASS')
|
|
93
|
+
self.assertIn('app.py:2 playsound', self.cli(root, '--verbose').stdout)
|
|
94
|
+
self.assertEqual(self.cli(root, '--ignore', 'README.md', '--ignore', '*.py').returncode, 0)
|
|
95
|
+
self.assertEqual(self.cli(root/'missing').returncode, 1)
|
|
96
|
+
self.assertEqual(self.cli(root, '--fail-on', 'LOW').returncode, 1)
|
|
97
|
+
root.chmod(0)
|
|
98
|
+
self.addCleanup(root.chmod, 0o700)
|
|
99
|
+
self.assertEqual(self.cli(root).returncode, 1)
|
|
100
|
+
|
|
101
|
+
def test_41_env_guard(self):
|
|
102
|
+
original = Path.read_text
|
|
103
|
+
def guarded(path, *args, **kwargs):
|
|
104
|
+
self.assertNotEqual(path.name, '.env')
|
|
105
|
+
return original(path, *args, **kwargs)
|
|
106
|
+
with patch.object(Path, 'read_text', guarded):
|
|
107
|
+
audit(ROOT)
|
|
108
|
+
|
|
109
|
+
def test_42_packaging(self):
|
|
110
|
+
for path in list((ROOT/'speaker_claim_audit').glob('*.py')) + list((ROOT/'tests').glob('*.py')) + [ROOT/'README.md', ROOT/'pyproject.toml']:
|
|
111
|
+
self.assertIsNone(re.search(r'(?<![\w-])py' + r'thon(?![\w-])', path.read_text()), str(path))
|
|
112
|
+
config = (ROOT/'pyproject.toml').read_text()
|
|
113
|
+
self.assertIn('setuptools>=77', config)
|
|
114
|
+
self.assertIn('license = "MIT"', config)
|
|
115
|
+
self.assertIn('recursive-include tests', (ROOT/'MANIFEST.in').read_text())
|
|
116
|
+
|
|
117
|
+
def test_aliases_and_constructors(self):
|
|
118
|
+
routes = [
|
|
119
|
+
'from pygame import mixer as mx\nmx.music.play()',
|
|
120
|
+
'from pygame import mixer as mx\nx=mx.Sound("x")\nx.play()',
|
|
121
|
+
'from simpleaudio import WaveObject as W\nself.w=W.from_wave_file("x")\nself.w.play()',
|
|
122
|
+
'from winsound import MessageBeep as b\nb()',
|
|
123
|
+
'from sounddevice.extra import play as go\ngo(data)',
|
|
124
|
+
'from playsound2.extra import playsound as go\ngo("x")',
|
|
125
|
+
'from pydub.playback import play as go\ngo(seg)',
|
|
126
|
+
'from pyaudio import PyAudio as P\nself.p=P()\nself.s=self.p.open(output=True)\nself.s.write(data)',
|
|
127
|
+
'import pyaudio as pa\npa.PyAudio().open(output=True).write(data)',
|
|
128
|
+
]
|
|
129
|
+
for source in routes:
|
|
130
|
+
with self.subTest(source=source):
|
|
131
|
+
self.assertTrue(evidence(source))
|
|
132
|
+
|
|
133
|
+
def test_additional_exclusions(self):
|
|
134
|
+
for source in [
|
|
135
|
+
'from simpleaudio import WaveObject\nw=WaveObject(data)',
|
|
136
|
+
'from pydub import play\nplay(seg)',
|
|
137
|
+
'from pydub import AudioSegment\ns=AudioSegment()\ns.export("x")',
|
|
138
|
+
'import soundfile\nsoundfile.write("x",data)',
|
|
139
|
+
'from scipy.io import wavfile\nwavfile.write("x",1,data)',
|
|
140
|
+
'from gtts import gTTS\ngTTS("hello").save("x")',
|
|
141
|
+
'import mutagen\nmutagen.File("x")',
|
|
142
|
+
'import tinytag\ntinytag.TinyTag.get("x")',
|
|
143
|
+
'def play_sound():\n print("speaker")\nplay_sound()',
|
|
144
|
+
'@app.get("/")\ndef f():\n return "speaker"',
|
|
145
|
+
'import pyaudio\np=pyaudio.PyAudio()\np.open(output=True)',
|
|
146
|
+
'import pyaudio\np=pyaudio.PyAudio()\ns=p.open(output=1)\ns.write(data)',
|
|
147
|
+
'"import winsound; winsound.Beep(1,2)"',
|
|
148
|
+
'# import winsound; winsound.Beep(1,2)',
|
|
149
|
+
'import pygame_fake as pg\npg.mixer.music.play()',
|
|
150
|
+
]:
|
|
151
|
+
with self.subTest(source=source):
|
|
152
|
+
self.assertFalse(evidence(source))
|
|
153
|
+
for library in ['playsound','playsound2','pygame','sounddevice','simpleaudio','winsound','pyaudio','pydub.playback']:
|
|
154
|
+
self.assertFalse(evidence('import '+library))
|
|
155
|
+
for player in ['ffplay','aplay','paplay','afplay']:
|
|
156
|
+
self.assertFalse(evidence('import subprocess\nsubprocess.run(["'+player+'","x"])'))
|
|
157
|
+
|
|
158
|
+
def test_scope_binding_and_symlinks(self):
|
|
159
|
+
root = self.fixture(source='s.play()')
|
|
160
|
+
(root/'other.py').write_text('import pygame\ns=pygame.mixer.Sound("x")')
|
|
161
|
+
self.assertEqual(audit(root)['verdict'], 'FAIL')
|
|
162
|
+
for folder in ['docs','examples','fixtures']:
|
|
163
|
+
target=root/folder/'emit.py';target.parent.mkdir(exist_ok=True);target.write_text(GOOD[0])
|
|
164
|
+
(root/'link.py').symlink_to(root/'examples/emit.py')
|
|
165
|
+
self.assertEqual(audit(root)['verdict'], 'FAIL')
|
|
166
|
+
|
|
167
|
+
def test_docs_scope_and_asymmetry(self):
|
|
168
|
+
root = self.fixture('neutral', GOOD[0])
|
|
169
|
+
doc=root/'tests/docs/nested/guide.md';doc.parent.mkdir(parents=True);doc.write_text('no audio playback')
|
|
170
|
+
self.assertEqual(audit(root)['findings'][0]['severity'], 'HIGH')
|
|
171
|
+
self.assertEqual(audit(root, ['tests/docs/*'])['verdict'], 'PASS')
|
|
172
|
+
|
|
173
|
+
def test_normalization_boundaries_paragraphs(self):
|
|
174
|
+
self.assertEqual(claims('PLAYS-AUDIO\n through your speakers'), (True,False))
|
|
175
|
+
self.assertEqual(claims('plays\n\naudio'), (False,False))
|
|
176
|
+
self.assertEqual(claims('displays audio'), (False,False))
|
|
177
|
+
self.assertEqual(claims('plays audio. no audio playback.'), (True,True))
|
|
178
|
+
root=self.fixture('plays audio. no audio playback.')
|
|
179
|
+
self.assertEqual(len(audit(root)['findings']),1)
|
|
180
|
+
|
|
181
|
+
def test_syntax_error(self):
|
|
182
|
+
self.assertFalse(evidence('def broken('))
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def add_good(index, source):
|
|
186
|
+
def test(self):
|
|
187
|
+
root = self.fixture(source=source)
|
|
188
|
+
self.assertEqual(audit(root)['verdict'], 'PASS')
|
|
189
|
+
self.assertTrue(audit(root)['evidence'])
|
|
190
|
+
self.assertEqual(self.cli(root).returncode, 0)
|
|
191
|
+
setattr(AuditTests, 'test_%02d_good_route' % index, test)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
for index, source in enumerate(GOOD, 1):
|
|
195
|
+
add_good(index, source)
|
|
196
|
+
for index, source in enumerate(BAD, 18):
|
|
197
|
+
def test(self, source=source):
|
|
198
|
+
self.assert_bad(source)
|
|
199
|
+
setattr(AuditTests, 'test_%02d_bad_route' % index, test)
|
|
200
|
+
|
|
201
|
+
# Exhaustion: one individually discoverable test for every exact template.
|
|
202
|
+
for family, phrases in [('positive',SPEAKER), ('negative',NOSPEAKER)]:
|
|
203
|
+
for index, phrase in enumerate(phrases):
|
|
204
|
+
def test(self, phrase=phrase, family=family):
|
|
205
|
+
expected = (True,False) if family == 'positive' else (False,True)
|
|
206
|
+
self.assertEqual(claims(phrase), expected)
|
|
207
|
+
root = self.fixture(phrase, None if family == 'positive' else GOOD[0])
|
|
208
|
+
self.assertEqual(len(audit(root)['findings']), 1)
|
|
209
|
+
self.assertEqual(audit(root)['findings'][0]['severity'], 'HIGH')
|
|
210
|
+
test.__doc__ = phrase
|
|
211
|
+
setattr(AuditTests, 'test_43_%s_%02d_%s' % (family,index,phrase.replace(' ','_')), test)
|