camera-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.
Files changed (26) hide show
  1. camera_claim_audit-0.1.0/LICENSE +21 -0
  2. camera_claim_audit-0.1.0/MANIFEST.in +3 -0
  3. camera_claim_audit-0.1.0/PKG-INFO +61 -0
  4. camera_claim_audit-0.1.0/README.md +51 -0
  5. camera_claim_audit-0.1.0/camera_claim_audit/__init__.py +2 -0
  6. camera_claim_audit-0.1.0/camera_claim_audit/__main__.py +43 -0
  7. camera_claim_audit-0.1.0/camera_claim_audit/audit.py +125 -0
  8. camera_claim_audit-0.1.0/camera_claim_audit/phrases.py +2 -0
  9. camera_claim_audit-0.1.0/camera_claim_audit.egg-info/PKG-INFO +61 -0
  10. camera_claim_audit-0.1.0/camera_claim_audit.egg-info/SOURCES.txt +24 -0
  11. camera_claim_audit-0.1.0/camera_claim_audit.egg-info/dependency_links.txt +1 -0
  12. camera_claim_audit-0.1.0/camera_claim_audit.egg-info/entry_points.txt +2 -0
  13. camera_claim_audit-0.1.0/camera_claim_audit.egg-info/top_level.txt +1 -0
  14. camera_claim_audit-0.1.0/pyproject.toml +17 -0
  15. camera_claim_audit-0.1.0/setup.cfg +4 -0
  16. camera_claim_audit-0.1.0/tests/__init__.py +0 -0
  17. camera_claim_audit-0.1.0/tests/fixtures/.env +1 -0
  18. camera_claim_audit-0.1.0/tests/fixtures/bad/README.md +1 -0
  19. camera_claim_audit-0.1.0/tests/fixtures/bad/app.py +1 -0
  20. camera_claim_audit-0.1.0/tests/fixtures/good/README.md +1 -0
  21. camera_claim_audit-0.1.0/tests/fixtures/good/app.py +3 -0
  22. camera_claim_audit-0.1.0/tests/fixtures/no_camera/README.md +1 -0
  23. camera_claim_audit-0.1.0/tests/fixtures/no_camera/app.py +3 -0
  24. camera_claim_audit-0.1.0/tests/fixtures/tests_only/README.md +1 -0
  25. camera_claim_audit-0.1.0/tests/fixtures/tests_only/tests/test_device.py +3 -0
  26. camera_claim_audit-0.1.0/tests/test_audit.py +340 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 camera-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,3 @@
1
+ include LICENSE README.md
2
+ recursive-include tests *.py
3
+ recursive-include tests/fixtures *
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.4
2
+ Name: camera-claim-audit
3
+ Version: 0.1.0
4
+ Summary: Offline static audit of documented local device image intake
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
+ # camera-claim-audit
12
+
13
+ An offline static auditor for documentation about local device image capture
14
+ and attached imaging device intake. Source is parsed, never imported or run.
15
+ No runtime dependencies are required. Requires Python 3.9 or later.
16
+
17
+ Install and run:
18
+
19
+ ```sh
20
+ python3 -m pip install .
21
+ camera-claim-audit /path/to/project
22
+ python3 -m camera_claim_audit /path/to/project --json --verbose
23
+ python3 -m unittest discover
24
+ ```
25
+
26
+ Root README.md and Markdown beneath any docs path component supply claims.
27
+ Fenced blocks are excluded; inline code counts. Matching lowercases text,
28
+ expands negative contractions, replaces hyphens with spaces, and joins lines
29
+ within paragraphs. Exact word-boundary templates alone count; negative spans
30
+ are removed first. Bare device nouns and instructions to the user do not count.
31
+ Screen grabs, audio, speech, key input, clipboard operations and network sends
32
+ are outside this audit's scope.
33
+
34
+ Production evidence requires a provider-resolved cv2 VideoCapture device read,
35
+ a bound picamera2 Picamera2 capture method, or a bound legacy picamera PiCamera
36
+ capture or recording method. Plain assignments, self attributes and chained
37
+ calls are recognized per module. A string first argument to VideoCapture is a
38
+ file source. Object construction alone is insufficient. Tests, fixtures, docs,
39
+ examples and symlinks are excluded from production evidence. Evidence solely
40
+ in tests produces MEDIUM. Missing positive evidence and contradictory negative
41
+ documentation produce HIGH, at most one finding per family. Without source,
42
+ a positive assertion fails and a negative assertion passes. Without claims,
43
+ the result passes regardless of source evidence.
44
+
45
+ Options: --json emits structured findings and evidence; --verbose shows source
46
+ paths; repeat --ignore GLOB to exclude relative paths; --fail-on HIGH is the
47
+ default, while --fail-on MEDIUM also fails on test-only evidence. --version
48
+ prints 0.1.0. Exit codes are 0 for passing the threshold, 2 for findings meeting
49
+ the threshold, and 1 for invalid usage or unreadable roots. MEDIUM findings
50
+ remain visible even when the verdict is PASS.
51
+
52
+ ## Limitations
53
+
54
+ Only the fixed templates in the package phrase table are recognized. This is
55
+ static evidence, not a hardware or runtime guarantee. Scope and control flow
56
+ are not modeled; bindings and imports are tracked per module. Dynamic imports,
57
+ wrapper functions, cross-module receivers, assignment aliases and shell imaging
58
+ helpers (ffmpeg, fswebcam, imagesnap) are not resolved. Strings, comments,
59
+ docstrings, file loaders, screen grabs, display and save operations alone are
60
+ insufficient. Environment files are never opened. Invalid source syntax supplies
61
+ no evidence. Ignore patterns use relative paths and standard glob matching.
@@ -0,0 +1,51 @@
1
+ # camera-claim-audit
2
+
3
+ An offline static auditor for documentation about local device image capture
4
+ and attached imaging device intake. Source is parsed, never imported or run.
5
+ No runtime dependencies are required. Requires Python 3.9 or later.
6
+
7
+ Install and run:
8
+
9
+ ```sh
10
+ python3 -m pip install .
11
+ camera-claim-audit /path/to/project
12
+ python3 -m camera_claim_audit /path/to/project --json --verbose
13
+ python3 -m unittest discover
14
+ ```
15
+
16
+ Root README.md and Markdown beneath any docs path component supply claims.
17
+ Fenced blocks are excluded; inline code counts. Matching lowercases text,
18
+ expands negative contractions, replaces hyphens with spaces, and joins lines
19
+ within paragraphs. Exact word-boundary templates alone count; negative spans
20
+ are removed first. Bare device nouns and instructions to the user do not count.
21
+ Screen grabs, audio, speech, key input, clipboard operations and network sends
22
+ are outside this audit's scope.
23
+
24
+ Production evidence requires a provider-resolved cv2 VideoCapture device read,
25
+ a bound picamera2 Picamera2 capture method, or a bound legacy picamera PiCamera
26
+ capture or recording method. Plain assignments, self attributes and chained
27
+ calls are recognized per module. A string first argument to VideoCapture is a
28
+ file source. Object construction alone is insufficient. Tests, fixtures, docs,
29
+ examples and symlinks are excluded from production evidence. Evidence solely
30
+ in tests produces MEDIUM. Missing positive evidence and contradictory negative
31
+ documentation produce HIGH, at most one finding per family. Without source,
32
+ a positive assertion fails and a negative assertion passes. Without claims,
33
+ the result passes regardless of source evidence.
34
+
35
+ Options: --json emits structured findings and evidence; --verbose shows source
36
+ paths; repeat --ignore GLOB to exclude relative paths; --fail-on HIGH is the
37
+ default, while --fail-on MEDIUM also fails on test-only evidence. --version
38
+ prints 0.1.0. Exit codes are 0 for passing the threshold, 2 for findings meeting
39
+ the threshold, and 1 for invalid usage or unreadable roots. MEDIUM findings
40
+ remain visible even when the verdict is PASS.
41
+
42
+ ## Limitations
43
+
44
+ Only the fixed templates in the package phrase table are recognized. This is
45
+ static evidence, not a hardware or runtime guarantee. Scope and control flow
46
+ are not modeled; bindings and imports are tracked per module. Dynamic imports,
47
+ wrapper functions, cross-module receivers, assignment aliases and shell imaging
48
+ helpers (ffmpeg, fswebcam, imagesnap) are not resolved. Strings, comments,
49
+ docstrings, file loaders, screen grabs, display and save operations alone are
50
+ insufficient. Environment files are never opened. Invalid source syntax supplies
51
+ no evidence. Ignore patterns use relative paths and standard glob matching.
@@ -0,0 +1,2 @@
1
+ """Static documentation and device evidence audit."""
2
+ __version__ = '0.1.0'
@@ -0,0 +1,43 @@
1
+ import argparse
2
+ import json
3
+ import sys
4
+ from . import __version__
5
+ from .audit import audit
6
+
7
+
8
+ class Parser(argparse.ArgumentParser):
9
+ def error(self, message):
10
+ self.print_usage(sys.stderr)
11
+ self.exit(1, self.prog + ': error: ' + message + '\n')
12
+
13
+
14
+ def main(argv=None):
15
+ parser = Parser(description='Audit documented local device image intake against static source evidence.')
16
+ parser.add_argument('root')
17
+ parser.add_argument('--json', action='store_true')
18
+ parser.add_argument('--verbose', action='store_true')
19
+ parser.add_argument('--ignore', action='append', default=[])
20
+ parser.add_argument('--fail-on', choices=['HIGH', 'MEDIUM'], default='HIGH')
21
+ parser.add_argument('--version', action='version', version=__version__)
22
+ args = parser.parse_args(argv)
23
+ try:
24
+ result = audit(args.root, args.ignore)
25
+ except (OSError, ValueError, UnicodeError) as exc:
26
+ print(str(exc), file=sys.stderr)
27
+ return 1
28
+ failed = any(f['severity'] == 'HIGH' or args.fail_on == 'MEDIUM' for f in result['findings'])
29
+ result['verdict'] = 'FAIL' if failed else 'PASS'
30
+ if args.json:
31
+ print(json.dumps(result))
32
+ else:
33
+ print(result['verdict'])
34
+ for finding in result['findings']:
35
+ print('{severity} {rule}: {message}'.format(**finding))
36
+ if args.verbose:
37
+ print('Evidence: ' + ', '.join(result['evidence']))
38
+ print('Test evidence: ' + ', '.join(result['test_evidence']))
39
+ return 2 if failed else 0
40
+
41
+
42
+ if __name__ == '__main__':
43
+ sys.exit(main())
@@ -0,0 +1,125 @@
1
+ """Offline AST inspection. Audited source is never executed."""
2
+ import ast
3
+ import fnmatch
4
+ import re
5
+ from pathlib import Path
6
+ from .phrases import CAMERA, NOCAMERA
7
+
8
+
9
+ def normalize(text):
10
+ return re.sub(r'\s+', ' ', text.lower().replace("n't", ' not').replace('-', ' ')).strip()
11
+
12
+
13
+ def claims(text):
14
+ lines = []
15
+ fence = None
16
+ for line in text.splitlines():
17
+ marker = re.match(r'^\s{0,3}(`{3,}|~{3,})', line)
18
+ if marker:
19
+ token = marker.group(1)
20
+ if fence is None:
21
+ fence = token
22
+ elif token[0] == fence[0] and len(token) >= len(fence):
23
+ fence = None
24
+ lines.append('')
25
+ elif fence is None:
26
+ lines.append(line)
27
+ positive = negative = False
28
+ for paragraph in re.split(r'\n\s*\n', '\n'.join(lines)):
29
+ paragraph = normalize(paragraph)
30
+ for phrase in sorted(NOCAMERA, key=len, reverse=True):
31
+ paragraph, count = re.subn(r'\b' + re.escape(phrase) + r'\b', ' ', paragraph)
32
+ negative |= bool(count)
33
+ positive |= any(re.search(r'\b' + re.escape(p) + r'\b', paragraph) for p in CAMERA)
34
+ return positive, negative
35
+
36
+
37
+ def dotted(node):
38
+ if isinstance(node, ast.Name):
39
+ return node.id
40
+ if isinstance(node, ast.Attribute):
41
+ base = dotted(node.value)
42
+ return base + '.' + node.attr if base else ''
43
+ return ''
44
+
45
+
46
+ def evidence(source):
47
+ try:
48
+ tree = ast.parse(source)
49
+ except SyntaxError:
50
+ return False
51
+ aliases = {}
52
+ providers = ('cv2', 'picamera2', 'picamera')
53
+ for node in ast.walk(tree):
54
+ if isinstance(node, ast.Import):
55
+ for item in node.names:
56
+ if item.name.split('.')[0] in providers:
57
+ aliases[item.asname or item.name.split('.')[0]] = item.name if item.asname else item.name.split('.')[0]
58
+ elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module:
59
+ if node.module.split('.')[0] in providers:
60
+ for item in node.names:
61
+ aliases[item.asname or item.name] = node.module + '.' + item.name
62
+
63
+ def creation(node):
64
+ if not isinstance(node, ast.Call):
65
+ return None
66
+ path = dotted(node.func).split('.')
67
+ resolved = aliases.get(path[0], '')
68
+ if not resolved:
69
+ return None
70
+ path = (resolved + ('.' + '.'.join(path[1:]) if len(path) > 1 else '')).split('.')
71
+ provider, name = path[0], path[-1]
72
+ if provider == 'cv2' and name == 'VideoCapture':
73
+ if node.args and isinstance(node.args[0], ast.Constant) and isinstance(node.args[0].value, str):
74
+ return None
75
+ return provider
76
+ if (provider, name) in {('picamera2', 'Picamera2'), ('picamera', 'PiCamera')}:
77
+ return provider
78
+ return None
79
+
80
+ bindings = {}
81
+ for node in ast.walk(tree):
82
+ if isinstance(node, ast.Assign):
83
+ provider = creation(node.value)
84
+ for target in node.targets:
85
+ key = dotted(target)
86
+ if isinstance(target, ast.Name) or (isinstance(target, ast.Attribute) and isinstance(target.value, ast.Name) and target.value.id == 'self'):
87
+ if provider:
88
+ bindings[key] = provider
89
+ methods = {'cv2': {'read'}, 'picamera2': {'capture_file', 'capture_array', 'capture_image', 'capture_buffer', 'capture_metadata'}, 'picamera': {'capture', 'start_recording'}}
90
+ for node in ast.walk(tree):
91
+ if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute):
92
+ provider = creation(node.func.value) or bindings.get(dotted(node.func.value))
93
+ if provider and node.func.attr in methods[provider]:
94
+ return True
95
+ return False
96
+
97
+
98
+ def audit(root, ignores=()):
99
+ root = Path(root)
100
+ if not root.is_dir() or not root.stat().st_mode & 0o444 or not root.stat().st_mode & 0o111:
101
+ raise ValueError('Root must be a readable directory')
102
+ positive = negative = False
103
+ production, testing = [], []
104
+ excluded = {'fixtures', 'docs', 'examples'}
105
+ for path in sorted(root.rglob('*')):
106
+ relative = path.relative_to(root)
107
+ if path.is_symlink() or any(parent.is_symlink() for parent in path.parents if parent != root) or not path.is_file():
108
+ continue
109
+ if any(fnmatch.fnmatch(relative.as_posix(), pattern) for pattern in ignores):
110
+ continue
111
+ if path.suffix.lower() == '.md' and (relative.as_posix() == 'README.md' or 'docs' in relative.parts[:-1]):
112
+ pos, neg = claims(path.read_text(encoding='utf-8'))
113
+ positive |= pos
114
+ negative |= neg
115
+ if path.suffix != '.py' or excluded.intersection(relative.parts[:-1]):
116
+ continue
117
+ test = 'tests' in relative.parts[:-1] or path.name.startswith('test_') or path.name.endswith('_test.py')
118
+ if evidence(path.read_text(encoding='utf-8')):
119
+ (testing if test else production).append(relative.as_posix())
120
+ findings = []
121
+ if positive and not production:
122
+ findings.append({'rule': 'documented-camera-claim-false', 'severity': 'MEDIUM' if testing else 'HIGH', 'message': 'Documented device intake lacks production capture evidence.'})
123
+ if negative and production:
124
+ findings.append({'rule': 'documented-no-camera-claim-false', 'severity': 'HIGH', 'message': 'Documented absence conflicts with production capture evidence.'})
125
+ return {'findings': findings, 'evidence': production, 'test_evidence': testing, 'claims': {'camera': positive, 'no_camera': negative}}
@@ -0,0 +1,2 @@
1
+ CAMERA = ('captures photos from your camera', 'capture photos from your camera', 'captures images from your camera', 'capture images from your camera', 'takes photos with your camera', 'take photos with your camera', 'takes pictures with your camera', 'take pictures with your camera', 'captures video from your camera', 'capture video from your camera', 'records video from your camera', 'record video from your camera', 'captures webcam video', 'capture webcam video', 'captures webcam images', 'capture webcam images', 'takes webcam photos', 'take webcam photos', 'supports camera capture', 'camera capture support', 'camera photo capture', 'camera video capture', 'webcam capture support', 'supports webcam capture', 'camera input support', 'uses your camera to capture', 'captures from your camera', 'capture from your camera', 'records from your camera', 'record from your camera')
2
+ NOCAMERA = ('does not capture photos from your camera', 'does not capture images from your camera', 'does not take photos with your camera', 'does not capture video from your camera', 'does not record video from your camera', 'does not capture from your camera', 'does not record from your camera', 'does not use your camera', 'does not access your camera', 'camera capture not supported', 'webcam capture not supported', 'camera input not supported', 'no camera capture', 'no webcam capture', 'without camera capture', 'without webcam capture', 'no camera input', 'no camera access')
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.4
2
+ Name: camera-claim-audit
3
+ Version: 0.1.0
4
+ Summary: Offline static audit of documented local device image intake
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
+ # camera-claim-audit
12
+
13
+ An offline static auditor for documentation about local device image capture
14
+ and attached imaging device intake. Source is parsed, never imported or run.
15
+ No runtime dependencies are required. Requires Python 3.9 or later.
16
+
17
+ Install and run:
18
+
19
+ ```sh
20
+ python3 -m pip install .
21
+ camera-claim-audit /path/to/project
22
+ python3 -m camera_claim_audit /path/to/project --json --verbose
23
+ python3 -m unittest discover
24
+ ```
25
+
26
+ Root README.md and Markdown beneath any docs path component supply claims.
27
+ Fenced blocks are excluded; inline code counts. Matching lowercases text,
28
+ expands negative contractions, replaces hyphens with spaces, and joins lines
29
+ within paragraphs. Exact word-boundary templates alone count; negative spans
30
+ are removed first. Bare device nouns and instructions to the user do not count.
31
+ Screen grabs, audio, speech, key input, clipboard operations and network sends
32
+ are outside this audit's scope.
33
+
34
+ Production evidence requires a provider-resolved cv2 VideoCapture device read,
35
+ a bound picamera2 Picamera2 capture method, or a bound legacy picamera PiCamera
36
+ capture or recording method. Plain assignments, self attributes and chained
37
+ calls are recognized per module. A string first argument to VideoCapture is a
38
+ file source. Object construction alone is insufficient. Tests, fixtures, docs,
39
+ examples and symlinks are excluded from production evidence. Evidence solely
40
+ in tests produces MEDIUM. Missing positive evidence and contradictory negative
41
+ documentation produce HIGH, at most one finding per family. Without source,
42
+ a positive assertion fails and a negative assertion passes. Without claims,
43
+ the result passes regardless of source evidence.
44
+
45
+ Options: --json emits structured findings and evidence; --verbose shows source
46
+ paths; repeat --ignore GLOB to exclude relative paths; --fail-on HIGH is the
47
+ default, while --fail-on MEDIUM also fails on test-only evidence. --version
48
+ prints 0.1.0. Exit codes are 0 for passing the threshold, 2 for findings meeting
49
+ the threshold, and 1 for invalid usage or unreadable roots. MEDIUM findings
50
+ remain visible even when the verdict is PASS.
51
+
52
+ ## Limitations
53
+
54
+ Only the fixed templates in the package phrase table are recognized. This is
55
+ static evidence, not a hardware or runtime guarantee. Scope and control flow
56
+ are not modeled; bindings and imports are tracked per module. Dynamic imports,
57
+ wrapper functions, cross-module receivers, assignment aliases and shell imaging
58
+ helpers (ffmpeg, fswebcam, imagesnap) are not resolved. Strings, comments,
59
+ docstrings, file loaders, screen grabs, display and save operations alone are
60
+ insufficient. Environment files are never opened. Invalid source syntax supplies
61
+ no evidence. Ignore patterns use relative paths and standard glob matching.
@@ -0,0 +1,24 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ camera_claim_audit/__init__.py
6
+ camera_claim_audit/__main__.py
7
+ camera_claim_audit/audit.py
8
+ camera_claim_audit/phrases.py
9
+ camera_claim_audit.egg-info/PKG-INFO
10
+ camera_claim_audit.egg-info/SOURCES.txt
11
+ camera_claim_audit.egg-info/dependency_links.txt
12
+ camera_claim_audit.egg-info/entry_points.txt
13
+ camera_claim_audit.egg-info/top_level.txt
14
+ tests/__init__.py
15
+ tests/test_audit.py
16
+ tests/fixtures/.env
17
+ tests/fixtures/bad/README.md
18
+ tests/fixtures/bad/app.py
19
+ tests/fixtures/good/README.md
20
+ tests/fixtures/good/app.py
21
+ tests/fixtures/no_camera/README.md
22
+ tests/fixtures/no_camera/app.py
23
+ tests/fixtures/tests_only/README.md
24
+ tests/fixtures/tests_only/tests/test_device.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ camera-claim-audit = camera_claim_audit.__main__:main
@@ -0,0 +1 @@
1
+ camera_claim_audit
@@ -0,0 +1,17 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "camera-claim-audit"
7
+ version = "0.1.0"
8
+ description = "Offline static audit of documented local device image intake"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+
13
+ [project.scripts]
14
+ camera-claim-audit = "camera_claim_audit.__main__:main"
15
+
16
+ [tool.setuptools.packages.find]
17
+ include = ["camera_claim_audit*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1 @@
1
+ MARKER_ONLY_NOT_A_SECRET
@@ -0,0 +1 @@
1
+ captures photos from your camera
@@ -0,0 +1 @@
1
+ import cv2
@@ -0,0 +1 @@
1
+ captures photos from your camera
@@ -0,0 +1,3 @@
1
+ import cv2
2
+ cap = cv2.VideoCapture(0)
3
+ cap.read()
@@ -0,0 +1 @@
1
+ no camera capture
@@ -0,0 +1,3 @@
1
+ import cv2
2
+ cap = cv2.VideoCapture(0)
3
+ cap.read()
@@ -0,0 +1 @@
1
+ captures photos from your camera
@@ -0,0 +1,3 @@
1
+ import cv2
2
+ cap = cv2.VideoCapture(0)
3
+ cap.read()
@@ -0,0 +1,340 @@
1
+ """Spec cases 01–35. Added phrase-exhaustion coverage:
2
+ test_phrase_camera_00 covers: captures photos from your camera
3
+ test_phrase_camera_01 covers: capture photos from your camera
4
+ test_phrase_camera_02 covers: captures images from your camera
5
+ test_phrase_camera_03 covers: capture images from your camera
6
+ test_phrase_camera_04 covers: takes photos with your camera
7
+ test_phrase_camera_05 covers: take photos with your camera
8
+ test_phrase_camera_06 covers: takes pictures with your camera
9
+ test_phrase_camera_07 covers: take pictures with your camera
10
+ test_phrase_camera_08 covers: captures video from your camera
11
+ test_phrase_camera_09 covers: capture video from your camera
12
+ test_phrase_camera_10 covers: records video from your camera
13
+ test_phrase_camera_11 covers: record video from your camera
14
+ test_phrase_camera_12 covers: captures webcam video
15
+ test_phrase_camera_13 covers: capture webcam video
16
+ test_phrase_camera_14 covers: captures webcam images
17
+ test_phrase_camera_15 covers: capture webcam images
18
+ test_phrase_camera_16 covers: takes webcam photos
19
+ test_phrase_camera_17 covers: take webcam photos
20
+ test_phrase_camera_18 covers: supports camera capture
21
+ test_phrase_camera_19 covers: camera capture support
22
+ test_phrase_camera_20 covers: camera photo capture
23
+ test_phrase_camera_21 covers: camera video capture
24
+ test_phrase_camera_22 covers: webcam capture support
25
+ test_phrase_camera_23 covers: supports webcam capture
26
+ test_phrase_camera_24 covers: camera input support
27
+ test_phrase_camera_25 covers: uses your camera to capture
28
+ test_phrase_camera_26 covers: captures from your camera
29
+ test_phrase_camera_27 covers: capture from your camera
30
+ test_phrase_camera_28 covers: records from your camera
31
+ test_phrase_camera_29 covers: record from your camera
32
+ test_phrase_nocamera_00 covers: does not capture photos from your camera
33
+ test_phrase_nocamera_01 covers: does not capture images from your camera
34
+ test_phrase_nocamera_02 covers: does not take photos with your camera
35
+ test_phrase_nocamera_03 covers: does not capture video from your camera
36
+ test_phrase_nocamera_04 covers: does not record video from your camera
37
+ test_phrase_nocamera_05 covers: does not capture from your camera
38
+ test_phrase_nocamera_06 covers: does not record from your camera
39
+ test_phrase_nocamera_07 covers: does not use your camera
40
+ test_phrase_nocamera_08 covers: does not access your camera
41
+ test_phrase_nocamera_09 covers: camera capture not supported
42
+ test_phrase_nocamera_10 covers: webcam capture not supported
43
+ test_phrase_nocamera_11 covers: camera input not supported
44
+ test_phrase_nocamera_12 covers: no camera capture
45
+ test_phrase_nocamera_13 covers: no webcam capture
46
+ test_phrase_nocamera_14 covers: without camera capture
47
+ test_phrase_nocamera_15 covers: without webcam capture
48
+ test_phrase_nocamera_16 covers: no camera input
49
+ test_phrase_nocamera_17 covers: no camera access
50
+ """
51
+ import contextlib
52
+ import io
53
+ import json
54
+ import re
55
+ import tempfile
56
+ import unittest
57
+ from pathlib import Path
58
+ from unittest.mock import patch
59
+ from camera_claim_audit.audit import audit, claims, evidence
60
+ from camera_claim_audit.__main__ import main
61
+ from camera_claim_audit.phrases import CAMERA, NOCAMERA
62
+
63
+ ROOT = Path(__file__).resolve().parents[1]
64
+ GOOD = 'import cv2\ncap = cv2.VideoCapture(0)\ncap.read()'
65
+ CLAIM = CAMERA[0]
66
+
67
+ class AuditTests(unittest.TestCase):
68
+ def project(self, source=None, doc=CLAIM, path='app.py'):
69
+ tmp = tempfile.TemporaryDirectory()
70
+ self.addCleanup(tmp.cleanup)
71
+ root = Path(tmp.name)
72
+ (root/'README.md').write_text(doc)
73
+ if source is not None:
74
+ target = root/path
75
+ target.parent.mkdir(parents=True, exist_ok=True)
76
+ target.write_text(source)
77
+ return root
78
+
79
+ def run_cli(self, root, *args):
80
+ out = io.StringIO()
81
+ with contextlib.redirect_stdout(out):
82
+ code = main([str(root), '--json', *args])
83
+ return code, json.loads(out.getvalue())
84
+
85
+ def check(self, source=None, doc=CLAIM, expected='HIGH', path='app.py'):
86
+ root = self.project(source, doc, path)
87
+ code, result = self.run_cli(root)
88
+ self.assertEqual(result['findings'], [] if expected is None else [dict(rule='documented-no-camera-claim-false' if doc in NOCAMERA else 'documented-camera-claim-false', severity=expected, message='Documented absence conflicts with production capture evidence.' if doc in NOCAMERA else 'Documented device intake lacks production capture evidence.')])
89
+ self.assertEqual(code, 2 if expected == 'HIGH' else 0)
90
+ return root
91
+
92
+ def test_01_plain(self): self.check(GOOD, expected=None)
93
+ def test_02_alias(self): self.check('import cv2 as cv\ncap=cv.VideoCapture(0)\ncap.read()', expected=None)
94
+ def test_03_from(self): self.check('from cv2 import VideoCapture\ncap=VideoCapture(0)\ncap.read()', expected=None)
95
+ def test_04_self(self): self.check('import cv2\nself.cap=cv2.VideoCapture(0)\nself.cap.read()', expected=None)
96
+ def test_05_chain(self): self.check('import cv2\ncv2.VideoCapture(0).read()', expected=None)
97
+ def test_06_constant(self): self.check(GOOD.replace('(0)', '(CAMERA_INDEX)'), expected=None)
98
+ def test_07_pi2(self): self.check('from picamera2 import Picamera2\ncam=Picamera2()\ncam.capture_file("x")', expected=None)
99
+ def test_08_pi2_chain(self): self.check('from picamera2 import Picamera2\nPicamera2().capture_array()', expected=None)
100
+ def test_09_pi2_self(self): self.check('from picamera2 import Picamera2\nself.cam=Picamera2()\nself.cam.capture_image()', expected=None)
101
+ def test_10_legacy(self): self.check('from picamera import PiCamera\ncam=PiCamera()\ncam.capture("x")', expected=None)
102
+ def test_11_record(self): self.check('from picamera import PiCamera\ncam=PiCamera()\ncam.start_recording("x")', expected=None)
103
+ def test_12_import(self): self.check('import cv2')
104
+ def test_13_string(self): self.check('word="camera"')
105
+ def test_14_object(self): self.check('import cv2\ncap=cv2.VideoCapture(0)')
106
+ def test_15_pi2_object(self): self.check('from picamera2 import Picamera2\ncam=Picamera2()')
107
+ def test_16_unbound_read(self): self.check('cap.read()')
108
+ def test_17_unbound_capture(self): self.check('cam.capture_file("x")')
109
+ def test_18_file(self): self.check(GOOD.replace('(0)', '("video.mp4")'))
110
+ def test_19_load(self): self.check('import cv2\nfrom PIL import Image\ncv2.imread("x")\nImage.open("x")')
111
+ def test_20_screen(self): self.check('import pyautogui\npyautogui.screenshot()')
112
+ def test_21_display(self): self.check('import cv2\ncv2.imshow("x", frame)\ncv2.imwrite("x", frame)')
113
+ def test_22_negative(self): self.check(GOOD, 'no camera capture')
114
+ def test_23_no_claim(self): self.check(GOOD, 'A useful tool.', None)
115
+ def test_24_noun(self): self.check('import cv2', 'the camera chapter explains delivery', None)
116
+ def test_25_user(self): self.check('import cv2', 'point your camera at the scene before starting', None)
117
+ def test_26_screenshot(self): self.check('pyautogui.screenshot()', 'takes screenshots', None)
118
+ def test_27_no_source(self):
119
+ self.check()
120
+ self.check(None, 'no camera capture', None)
121
+ def test_28_tests_only(self):
122
+ root = self.check(GOOD, expected='MEDIUM', path='tests/test_device.py')
123
+ self.assertEqual(self.run_cli(root, '--fail-on', 'MEDIUM')[0], 2)
124
+ def test_29_fences_inline(self):
125
+ self.check(None, '```text\n'+CLAIM+'\n```', None)
126
+ self.check(None, '`'+CLAIM+'`')
127
+ def test_30_negation(self): self.assertEqual(claims('does not capture photos from your camera'), (False, True))
128
+ def test_31_self(self):
129
+ result = audit(ROOT)
130
+ self.assertEqual(result['findings'], [])
131
+ self.assertEqual(result['claims'], {'camera': False, 'no_camera': False})
132
+ self.assertEqual(claims((ROOT/'README.md').read_text()), (False, False))
133
+ text = (ROOT/'README.md').read_text().lower().replace('-', ' ')
134
+ self.assertFalse(any(p in text for p in CAMERA+NOCAMERA))
135
+ def test_32_cli(self):
136
+ out=io.StringIO()
137
+ with contextlib.redirect_stdout(out), self.assertRaises(SystemExit) as exc: main(['--version'])
138
+ self.assertEqual(exc.exception.code, 0)
139
+ self.assertEqual(out.getvalue().strip(), '0.1.0')
140
+ root=self.project(GOOD, 'Overview')
141
+ (root/'docs').mkdir()
142
+ (root/'docs/claim.md').write_text('no camera capture')
143
+ self.assertEqual(self.run_cli(root)[0], 2)
144
+ self.assertEqual(self.run_cli(root, '--ignore', 'docs/*')[0], 0)
145
+ out=io.StringIO()
146
+ with contextlib.redirect_stdout(out): self.assertEqual(main([str(root), '--verbose', '--ignore', 'docs/*']), 0)
147
+ self.assertIn('app.py', out.getvalue())
148
+ with contextlib.redirect_stderr(io.StringIO()): self.assertEqual(main([str(root/'missing')]), 1)
149
+ with contextlib.redirect_stderr(io.StringIO()), self.assertRaises(SystemExit) as exc: main([])
150
+ self.assertEqual(exc.exception.code, 1)
151
+ def test_33_env(self):
152
+ original = Path.read_text
153
+ def guarded(path, *args, **kwargs):
154
+ self.assertNotEqual(path.name, '.env')
155
+ return original(path, *args, **kwargs)
156
+ with patch.object(Path, 'read_text', guarded): audit(ROOT)
157
+ def test_34_packaging(self):
158
+ for path in list((ROOT/'camera_claim_audit').glob('*.py')) + list((ROOT/'tests').glob('*.py')) + [ROOT/'README.md']:
159
+ self.assertIsNone(re.search(r'\b' + 'py' + r'thon\b', path.read_text()))
160
+ config=(ROOT/'pyproject.toml').read_text()
161
+ self.assertIn('setuptools>=77', config)
162
+ self.assertIn('license = "MIT"', config)
163
+ self.assertIn('recursive-include tests', (ROOT/'MANIFEST.in').read_text())
164
+ def test_35_phrase_inventory(self):
165
+ self.assertEqual(len(CAMERA), 30)
166
+ self.assertEqual(len(NOCAMERA), 18)
167
+
168
+ def test_phrase_camera_00(self):
169
+ self.check(None, 'captures photos from your camera')
170
+ def test_phrase_camera_01(self):
171
+ self.check(None, 'capture photos from your camera')
172
+ def test_phrase_camera_02(self):
173
+ self.check(None, 'captures images from your camera')
174
+ def test_phrase_camera_03(self):
175
+ self.check(None, 'capture images from your camera')
176
+ def test_phrase_camera_04(self):
177
+ self.check(None, 'takes photos with your camera')
178
+ def test_phrase_camera_05(self):
179
+ self.check(None, 'take photos with your camera')
180
+ def test_phrase_camera_06(self):
181
+ self.check(None, 'takes pictures with your camera')
182
+ def test_phrase_camera_07(self):
183
+ self.check(None, 'take pictures with your camera')
184
+ def test_phrase_camera_08(self):
185
+ self.check(None, 'captures video from your camera')
186
+ def test_phrase_camera_09(self):
187
+ self.check(None, 'capture video from your camera')
188
+ def test_phrase_camera_10(self):
189
+ self.check(None, 'records video from your camera')
190
+ def test_phrase_camera_11(self):
191
+ self.check(None, 'record video from your camera')
192
+ def test_phrase_camera_12(self):
193
+ self.check(None, 'captures webcam video')
194
+ def test_phrase_camera_13(self):
195
+ self.check(None, 'capture webcam video')
196
+ def test_phrase_camera_14(self):
197
+ self.check(None, 'captures webcam images')
198
+ def test_phrase_camera_15(self):
199
+ self.check(None, 'capture webcam images')
200
+ def test_phrase_camera_16(self):
201
+ self.check(None, 'takes webcam photos')
202
+ def test_phrase_camera_17(self):
203
+ self.check(None, 'take webcam photos')
204
+ def test_phrase_camera_18(self):
205
+ self.check(None, 'supports camera capture')
206
+ def test_phrase_camera_19(self):
207
+ self.check(None, 'camera capture support')
208
+ def test_phrase_camera_20(self):
209
+ self.check(None, 'camera photo capture')
210
+ def test_phrase_camera_21(self):
211
+ self.check(None, 'camera video capture')
212
+ def test_phrase_camera_22(self):
213
+ self.check(None, 'webcam capture support')
214
+ def test_phrase_camera_23(self):
215
+ self.check(None, 'supports webcam capture')
216
+ def test_phrase_camera_24(self):
217
+ self.check(None, 'camera input support')
218
+ def test_phrase_camera_25(self):
219
+ self.check(None, 'uses your camera to capture')
220
+ def test_phrase_camera_26(self):
221
+ self.check(None, 'captures from your camera')
222
+ def test_phrase_camera_27(self):
223
+ self.check(None, 'capture from your camera')
224
+ def test_phrase_camera_28(self):
225
+ self.check(None, 'records from your camera')
226
+ def test_phrase_camera_29(self):
227
+ self.check(None, 'record from your camera')
228
+ def test_phrase_nocamera_00(self):
229
+ self.assertEqual(claims('does not capture photos from your camera'), (False, True))
230
+ self.check(GOOD, 'does not capture photos from your camera')
231
+ self.check(None, 'does not capture photos from your camera', None)
232
+ def test_phrase_nocamera_01(self):
233
+ self.assertEqual(claims('does not capture images from your camera'), (False, True))
234
+ self.check(GOOD, 'does not capture images from your camera')
235
+ self.check(None, 'does not capture images from your camera', None)
236
+ def test_phrase_nocamera_02(self):
237
+ self.assertEqual(claims('does not take photos with your camera'), (False, True))
238
+ self.check(GOOD, 'does not take photos with your camera')
239
+ self.check(None, 'does not take photos with your camera', None)
240
+ def test_phrase_nocamera_03(self):
241
+ self.assertEqual(claims('does not capture video from your camera'), (False, True))
242
+ self.check(GOOD, 'does not capture video from your camera')
243
+ self.check(None, 'does not capture video from your camera', None)
244
+ def test_phrase_nocamera_04(self):
245
+ self.assertEqual(claims('does not record video from your camera'), (False, True))
246
+ self.check(GOOD, 'does not record video from your camera')
247
+ self.check(None, 'does not record video from your camera', None)
248
+ def test_phrase_nocamera_05(self):
249
+ self.assertEqual(claims('does not capture from your camera'), (False, True))
250
+ self.check(GOOD, 'does not capture from your camera')
251
+ self.check(None, 'does not capture from your camera', None)
252
+ def test_phrase_nocamera_06(self):
253
+ self.assertEqual(claims('does not record from your camera'), (False, True))
254
+ self.check(GOOD, 'does not record from your camera')
255
+ self.check(None, 'does not record from your camera', None)
256
+ def test_phrase_nocamera_07(self):
257
+ self.assertEqual(claims('does not use your camera'), (False, True))
258
+ self.check(GOOD, 'does not use your camera')
259
+ self.check(None, 'does not use your camera', None)
260
+ def test_phrase_nocamera_08(self):
261
+ self.assertEqual(claims('does not access your camera'), (False, True))
262
+ self.check(GOOD, 'does not access your camera')
263
+ self.check(None, 'does not access your camera', None)
264
+ def test_phrase_nocamera_09(self):
265
+ self.assertEqual(claims('camera capture not supported'), (False, True))
266
+ self.check(GOOD, 'camera capture not supported')
267
+ self.check(None, 'camera capture not supported', None)
268
+ def test_phrase_nocamera_10(self):
269
+ self.assertEqual(claims('webcam capture not supported'), (False, True))
270
+ self.check(GOOD, 'webcam capture not supported')
271
+ self.check(None, 'webcam capture not supported', None)
272
+ def test_phrase_nocamera_11(self):
273
+ self.assertEqual(claims('camera input not supported'), (False, True))
274
+ self.check(GOOD, 'camera input not supported')
275
+ self.check(None, 'camera input not supported', None)
276
+ def test_phrase_nocamera_12(self):
277
+ self.assertEqual(claims('no camera capture'), (False, True))
278
+ self.check(GOOD, 'no camera capture')
279
+ self.check(None, 'no camera capture', None)
280
+ def test_phrase_nocamera_13(self):
281
+ self.assertEqual(claims('no webcam capture'), (False, True))
282
+ self.check(GOOD, 'no webcam capture')
283
+ self.check(None, 'no webcam capture', None)
284
+ def test_phrase_nocamera_14(self):
285
+ self.assertEqual(claims('without camera capture'), (False, True))
286
+ self.check(GOOD, 'without camera capture')
287
+ self.check(None, 'without camera capture', None)
288
+ def test_phrase_nocamera_15(self):
289
+ self.assertEqual(claims('without webcam capture'), (False, True))
290
+ self.check(GOOD, 'without webcam capture')
291
+ self.check(None, 'without webcam capture', None)
292
+ def test_phrase_nocamera_16(self):
293
+ self.assertEqual(claims('no camera input'), (False, True))
294
+ self.check(GOOD, 'no camera input')
295
+ self.check(None, 'no camera input', None)
296
+ def test_phrase_nocamera_17(self):
297
+ self.assertEqual(claims('no camera access'), (False, True))
298
+ self.check(GOOD, 'no camera access')
299
+ self.check(None, 'no camera access', None)
300
+
301
+ def test_provider_matrix(self):
302
+ for provider, constructor, methods in [('cv2','VideoCapture',['read']), ('picamera2','Picamera2',['capture_file','capture_array','capture_image','capture_buffer','capture_metadata']), ('picamera','PiCamera',['capture','start_recording'])]:
303
+ for method in methods:
304
+ for source in [f'import {provider} as p\np.{constructor}().{method}()', f'from {provider}.device import {constructor} as C\nc=C()\nc.{method}()', f'import {provider}\nself.c={provider}.{constructor}()\nself.c.{method}()']:
305
+ with self.subTest(source=source): self.assertTrue(evidence(source))
306
+ self.assertFalse(evidence('from picamera2 import PiCamera\nPiCamera().capture()'))
307
+ self.assertFalse(evidence('from picamera import Picamera2\nPicamera2().capture_file()'))
308
+
309
+ def test_explicit_non_evidence(self):
310
+ for source in ['input("device")', 'from picamera import PiCamera\nc=PiCamera()', 'c.capture()', 'import imageio\nimageio.imread("x")', 'import mss\nmss.mss().grab({})', 'import cv2\ncv2.CascadeClassifier().detectMultiScale(cv2.imread("x"))', 'def capture():\n print("camera")\n return 1', '@app.get("/capture")\ndef route():\n return "camera"', 'import subprocess\nsubprocess.run(["fswebcam"])', '"""import cv2; cv2.VideoCapture(0).read()"""', '# import cv2; cv2.VideoCapture(0).read()']:
311
+ with self.subTest(source=source): self.assertFalse(evidence(source))
312
+
313
+ def test_normalization_boundaries_and_paragraphs(self):
314
+ self.assertEqual(claims("SUPPORTS-CAMERA\nCAPTURE"), (True, False))
315
+ self.assertEqual(claims("doesn't capture photos from your camera"), (False, True))
316
+ self.assertEqual(claims('supports camera\n\ncapture'), (False, False))
317
+ self.assertEqual(claims('xsupports camera capturex'), (False, False))
318
+ self.assertEqual(claims('~~~md\n'+CLAIM+'\n~~~'), (False, False))
319
+
320
+ def test_scope_symlinks_and_two_families(self):
321
+ for path in ['tests/a.py', 'test_a.py', 'a_test.py']:
322
+ root=self.project(GOOD, path=path)
323
+ self.assertEqual(audit(root)['findings'][0]['severity'], 'MEDIUM')
324
+ for path in ['fixtures/a.py', 'docs/a.py', 'examples/a.py']:
325
+ root=self.project(GOOD, path=path)
326
+ self.assertEqual(audit(root)['findings'][0]['severity'], 'HIGH')
327
+ root=self.project(GOOD, path='external.py')
328
+ (root/'external.py').unlink()
329
+ (root/'external.py').symlink_to(ROOT/'tests/fixtures/good/app.py')
330
+ self.assertEqual(audit(root)['findings'][0]['severity'], 'HIGH')
331
+ root=self.project(None, CLAIM+'\n\nno camera capture')
332
+ self.assertEqual(len(audit(root)['findings']), 1)
333
+ (root/'app.py').write_text(GOOD)
334
+ result=audit(root)
335
+ self.assertEqual(len(result['findings']), 1)
336
+ self.assertEqual(result['findings'][0]['rule'], 'documented-no-camera-claim-false')
337
+ root=self.project(GOOD, 'Overview')
338
+ (root/'tests/docs').mkdir(parents=True)
339
+ (root/'tests/docs/negative.md').write_text('no camera capture')
340
+ self.assertEqual(audit(root)['findings'][0]['severity'], 'HIGH')