printer-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.
- printer_claim_audit-0.1.0/LICENSE +21 -0
- printer_claim_audit-0.1.0/MANIFEST.in +3 -0
- printer_claim_audit-0.1.0/PKG-INFO +68 -0
- printer_claim_audit-0.1.0/README.md +58 -0
- printer_claim_audit-0.1.0/printer_claim_audit/__init__.py +158 -0
- printer_claim_audit-0.1.0/printer_claim_audit/__main__.py +40 -0
- printer_claim_audit-0.1.0/printer_claim_audit/phrases.py +2 -0
- printer_claim_audit-0.1.0/printer_claim_audit.egg-info/PKG-INFO +68 -0
- printer_claim_audit-0.1.0/printer_claim_audit.egg-info/SOURCES.txt +73 -0
- printer_claim_audit-0.1.0/printer_claim_audit.egg-info/dependency_links.txt +1 -0
- printer_claim_audit-0.1.0/printer_claim_audit.egg-info/entry_points.txt +2 -0
- printer_claim_audit-0.1.0/printer_claim_audit.egg-info/top_level.txt +1 -0
- printer_claim_audit-0.1.0/pyproject.toml +17 -0
- printer_claim_audit-0.1.0/setup.cfg +4 -0
- printer_claim_audit-0.1.0/tests/__init__.py +0 -0
- printer_claim_audit-0.1.0/tests/fixtures/.env +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/bad/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/bad/app.py +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_01/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_01/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_02/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_02/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_03/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_03/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_04/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_04/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_05/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_05/app.py +2 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_06/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_06/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_07/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_07/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_08/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_08/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_09/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_09/app.py +2 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_10/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_10/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_11/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_11/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_12/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_12/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_13/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_13/app.py +2 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_14/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_14/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_15/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_15/app.py +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_16/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_16/app.py +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_17/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_17/app.py +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_18/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_18/app.py +2 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_19/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_19/app.py +2 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_20/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_20/app.py +2 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_21/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_21/app.py +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_22/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_22/app.py +2 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_23/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_23/app.py +4 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_24/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_24/app.py +2 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_25/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_25/app.py +2 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_26/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/case_26/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/good/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/good/app.py +3 -0
- printer_claim_audit-0.1.0/tests/fixtures/no_printer/README.md +1 -0
- printer_claim_audit-0.1.0/tests/fixtures/no_printer/app.py +3 -0
- printer_claim_audit-0.1.0/tests/test_audit.py +209 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 printer-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,68 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: printer-claim-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Static audit of local hardcopy job submission claims
|
|
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
|
+
# printer-claim-audit
|
|
12
|
+
|
|
13
|
+
An offline static audit for local hardcopy job submission claims. It compares
|
|
14
|
+
root README.md and Markdown files beneath a docs path component against Python
|
|
15
|
+
AST evidence of attached printing device intake. Source is never executed.
|
|
16
|
+
No runtime dependencies are required. Python 3.9 or newer is required.
|
|
17
|
+
|
|
18
|
+
Install and run:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
python3 -m pip install .
|
|
22
|
+
printer-claim-audit /path/to/project --json
|
|
23
|
+
python3 -m printer_claim_audit /path/to/project --verbose
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Options: `--ignore <glob>` is repeatable and matches root-relative paths;
|
|
27
|
+
`--fail-on HIGH` is the default; `--fail-on MEDIUM` also fails on evidence
|
|
28
|
+
found only in test source. `--version` reports 0.1.0. JSON includes verdict,
|
|
29
|
+
findings, production and test evidence locations, claim flags, and parse errors.
|
|
30
|
+
Human output lists findings; verbose output also lists evidence and parse errors.
|
|
31
|
+
Exit 0 means PASS, exit 2 means findings meet the severity threshold, and exit 1
|
|
32
|
+
means invalid usage or an inaccessible root. Findings below the threshold remain
|
|
33
|
+
visible even when the verdict is PASS. At most one finding per claim family is emitted.
|
|
34
|
+
|
|
35
|
+
## Limitations
|
|
36
|
+
|
|
37
|
+
Only the exact phrase templates in the package's `phrases.py` are recognized.
|
|
38
|
+
A bare device noun, tool name, dependency list, user instruction, console message,
|
|
39
|
+
PDF export, file save, screen grab, audio capture, or network send is outside
|
|
40
|
+
that vocabulary. Fenced blocks are excluded; inline code counts. Paragraphs are
|
|
41
|
+
normalized for case, contractions, hyphens, and whitespace. Denial spans are
|
|
42
|
+
removed before affirmative matching.
|
|
43
|
+
|
|
44
|
+
Evidence recognizes bound cups Connection job methods, win32print handle writes,
|
|
45
|
+
and escpos.printer object job methods. Imports, constructors alone, previews,
|
|
46
|
+
strings, comments, and docstrings do not establish capability. Shell spool helpers
|
|
47
|
+
such as lp, lpr, and lpstat are outside the recognized routes.
|
|
48
|
+
|
|
49
|
+
Bindings and aliases are module-local syntactic approximations; this tool does
|
|
50
|
+
not prove execution, device availability, delivery, control flow, or runtime name
|
|
51
|
+
identity. Syntax errors are reported and contribute no evidence. Test source can
|
|
52
|
+
reduce an unsupported affirmative assertion to MEDIUM; a denial contradicted by
|
|
53
|
+
production evidence is HIGH. An affirmative assertion without source is HIGH;
|
|
54
|
+
a denial without source passes. No recognized assertion means PASS.
|
|
55
|
+
|
|
56
|
+
Production excludes tests, test-named modules, fixtures, docs, examples, and
|
|
57
|
+
symlinked files or directories. Environment files are never opened. Ignore globs
|
|
58
|
+
apply to documentation and source. Markdown under any docs path component counts,
|
|
59
|
+
including documentation beneath test directories.
|
|
60
|
+
|
|
61
|
+
Run checks and build distributions:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
python3 -m unittest discover
|
|
65
|
+
python3 -m build
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The tests and fixtures are included in the source distribution. License: MIT.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# printer-claim-audit
|
|
2
|
+
|
|
3
|
+
An offline static audit for local hardcopy job submission claims. It compares
|
|
4
|
+
root README.md and Markdown files beneath a docs path component against Python
|
|
5
|
+
AST evidence of attached printing device intake. Source is never executed.
|
|
6
|
+
No runtime dependencies are required. Python 3.9 or newer is required.
|
|
7
|
+
|
|
8
|
+
Install and run:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
python3 -m pip install .
|
|
12
|
+
printer-claim-audit /path/to/project --json
|
|
13
|
+
python3 -m printer_claim_audit /path/to/project --verbose
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Options: `--ignore <glob>` is repeatable and matches root-relative paths;
|
|
17
|
+
`--fail-on HIGH` is the default; `--fail-on MEDIUM` also fails on evidence
|
|
18
|
+
found only in test source. `--version` reports 0.1.0. JSON includes verdict,
|
|
19
|
+
findings, production and test evidence locations, claim flags, and parse errors.
|
|
20
|
+
Human output lists findings; verbose output also lists evidence and parse errors.
|
|
21
|
+
Exit 0 means PASS, exit 2 means findings meet the severity threshold, and exit 1
|
|
22
|
+
means invalid usage or an inaccessible root. Findings below the threshold remain
|
|
23
|
+
visible even when the verdict is PASS. At most one finding per claim family is emitted.
|
|
24
|
+
|
|
25
|
+
## Limitations
|
|
26
|
+
|
|
27
|
+
Only the exact phrase templates in the package's `phrases.py` are recognized.
|
|
28
|
+
A bare device noun, tool name, dependency list, user instruction, console message,
|
|
29
|
+
PDF export, file save, screen grab, audio capture, or network send is outside
|
|
30
|
+
that vocabulary. Fenced blocks are excluded; inline code counts. Paragraphs are
|
|
31
|
+
normalized for case, contractions, hyphens, and whitespace. Denial spans are
|
|
32
|
+
removed before affirmative matching.
|
|
33
|
+
|
|
34
|
+
Evidence recognizes bound cups Connection job methods, win32print handle writes,
|
|
35
|
+
and escpos.printer object job methods. Imports, constructors alone, previews,
|
|
36
|
+
strings, comments, and docstrings do not establish capability. Shell spool helpers
|
|
37
|
+
such as lp, lpr, and lpstat are outside the recognized routes.
|
|
38
|
+
|
|
39
|
+
Bindings and aliases are module-local syntactic approximations; this tool does
|
|
40
|
+
not prove execution, device availability, delivery, control flow, or runtime name
|
|
41
|
+
identity. Syntax errors are reported and contribute no evidence. Test source can
|
|
42
|
+
reduce an unsupported affirmative assertion to MEDIUM; a denial contradicted by
|
|
43
|
+
production evidence is HIGH. An affirmative assertion without source is HIGH;
|
|
44
|
+
a denial without source passes. No recognized assertion means PASS.
|
|
45
|
+
|
|
46
|
+
Production excludes tests, test-named modules, fixtures, docs, examples, and
|
|
47
|
+
symlinked files or directories. Environment files are never opened. Ignore globs
|
|
48
|
+
apply to documentation and source. Markdown under any docs path component counts,
|
|
49
|
+
including documentation beneath test directories.
|
|
50
|
+
|
|
51
|
+
Run checks and build distributions:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
python3 -m unittest discover
|
|
55
|
+
python3 -m build
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The tests and fixtures are included in the source distribution. License: MIT.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""Static local hardcopy job submission audit."""
|
|
2
|
+
import ast
|
|
3
|
+
import fnmatch
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from .phrases import PRINTER, NOPRINTER
|
|
8
|
+
|
|
9
|
+
__version__ = '0.1.0'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def normalize(text):
|
|
13
|
+
return re.sub(r'\s+', ' ', text.lower().replace("n't", ' not').replace('-', ' ')).strip()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def claims(text):
|
|
17
|
+
paragraphs = []
|
|
18
|
+
lines = []
|
|
19
|
+
fence = None
|
|
20
|
+
for line in text.splitlines():
|
|
21
|
+
mark = re.match(r'^\s{0,3}(`{3,}|~{3,})', line)
|
|
22
|
+
if mark:
|
|
23
|
+
token = mark.group(1)
|
|
24
|
+
if fence is None:
|
|
25
|
+
fence = token
|
|
26
|
+
elif token[0] == fence[0] and len(token) >= len(fence):
|
|
27
|
+
fence = None
|
|
28
|
+
continue
|
|
29
|
+
if fence is not None:
|
|
30
|
+
continue
|
|
31
|
+
if not line.strip():
|
|
32
|
+
paragraphs.append(normalize(' '.join(lines)))
|
|
33
|
+
lines = []
|
|
34
|
+
else:
|
|
35
|
+
lines.append(line)
|
|
36
|
+
paragraphs.append(normalize(' '.join(lines)))
|
|
37
|
+
positive = negative = False
|
|
38
|
+
for paragraph in paragraphs:
|
|
39
|
+
for phrase in sorted(NOPRINTER, key=len, reverse=True):
|
|
40
|
+
paragraph, count = re.subn(r'\b' + re.escape(phrase) + r'\b', ' ', paragraph)
|
|
41
|
+
negative |= bool(count)
|
|
42
|
+
positive |= any(re.search(r'\b' + re.escape(phrase) + r'\b', paragraph) for phrase in PRINTER)
|
|
43
|
+
return positive, negative
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def dotted(node):
|
|
47
|
+
if isinstance(node, ast.Name):
|
|
48
|
+
return node.id
|
|
49
|
+
if isinstance(node, ast.Attribute):
|
|
50
|
+
base = dotted(node.value)
|
|
51
|
+
return base + '.' + node.attr if base else ''
|
|
52
|
+
return ''
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def evidence(source):
|
|
56
|
+
"""Resolve provider constructors and submission calls within one module."""
|
|
57
|
+
tree = ast.parse(source)
|
|
58
|
+
aliases = {}
|
|
59
|
+
for node in ast.walk(tree):
|
|
60
|
+
if isinstance(node, ast.Import):
|
|
61
|
+
for alias in node.names:
|
|
62
|
+
aliases[alias.asname or alias.name.split('.')[0]] = alias.name if alias.asname else alias.name.split('.')[0]
|
|
63
|
+
elif isinstance(node, ast.ImportFrom) and node.module and node.level == 0:
|
|
64
|
+
for alias in node.names:
|
|
65
|
+
aliases[alias.asname or alias.name] = node.module + '.' + alias.name
|
|
66
|
+
|
|
67
|
+
def resolve(node):
|
|
68
|
+
path = dotted(node)
|
|
69
|
+
first, sep, rest = path.partition('.')
|
|
70
|
+
return aliases.get(first, first) + (sep + rest if sep else '') if path else ''
|
|
71
|
+
|
|
72
|
+
def constructor(node):
|
|
73
|
+
if not isinstance(node, ast.Call):
|
|
74
|
+
return None
|
|
75
|
+
path = resolve(node.func)
|
|
76
|
+
module, _, name = path.rpartition('.')
|
|
77
|
+
if (module == 'cups' or module.startswith('cups.')) and name == 'Connection':
|
|
78
|
+
return 'cups'
|
|
79
|
+
if (module == 'win32print' or module.startswith('win32print.')) and name == 'OpenPrinter':
|
|
80
|
+
return 'win32print'
|
|
81
|
+
if (module == 'escpos.printer' or module.startswith('escpos.printer.')) and name in {'Usb', 'Network', 'Serial', 'File'}:
|
|
82
|
+
return 'escpos'
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
bindings = {}
|
|
86
|
+
for node in ast.walk(tree):
|
|
87
|
+
if isinstance(node, ast.Assign):
|
|
88
|
+
provider = constructor(node.value)
|
|
89
|
+
if provider:
|
|
90
|
+
for target in node.targets:
|
|
91
|
+
if isinstance(target, ast.Name) or (isinstance(target, ast.Attribute) and isinstance(target.value, ast.Name) and target.value.id == 'self'):
|
|
92
|
+
bindings[dotted(target)] = provider
|
|
93
|
+
|
|
94
|
+
def bound(node, provider):
|
|
95
|
+
return constructor(node) == provider or (isinstance(node, (ast.Name, ast.Attribute)) and bindings.get(dotted(node)) == provider)
|
|
96
|
+
|
|
97
|
+
found = []
|
|
98
|
+
for node in ast.walk(tree):
|
|
99
|
+
if not isinstance(node, ast.Call):
|
|
100
|
+
continue
|
|
101
|
+
func = node.func
|
|
102
|
+
route = None
|
|
103
|
+
if isinstance(func, ast.Attribute):
|
|
104
|
+
if func.attr in {'printFile', 'printFiles'} and bound(func.value, 'cups'):
|
|
105
|
+
route = 'cups'
|
|
106
|
+
elif func.attr in {'text', 'image', 'cut', 'qr', 'barcode'} and bound(func.value, 'escpos'):
|
|
107
|
+
route = 'escpos'
|
|
108
|
+
path = resolve(func)
|
|
109
|
+
module, _, name = path.rpartition('.')
|
|
110
|
+
if name == 'WritePrinter' and (module == 'win32print' or module.startswith('win32print.')) and node.args and bound(node.args[0], 'win32print'):
|
|
111
|
+
route = 'win32print'
|
|
112
|
+
if route:
|
|
113
|
+
found.append({'line': node.lineno, 'provider': route})
|
|
114
|
+
return found
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def audit(root, ignore=(), fail_on='HIGH'):
|
|
118
|
+
root = Path(root)
|
|
119
|
+
if not root.is_dir() or not os.access(root, os.R_OK | os.X_OK):
|
|
120
|
+
raise ValueError('root must be a readable directory')
|
|
121
|
+
positive = negative = False
|
|
122
|
+
production = []
|
|
123
|
+
test_evidence = []
|
|
124
|
+
errors = []
|
|
125
|
+
for directory, dirs, files in os.walk(root, followlinks=False):
|
|
126
|
+
dirs[:] = sorted(d for d in dirs if not (Path(directory) / d).is_symlink())
|
|
127
|
+
for filename in sorted(files):
|
|
128
|
+
path = Path(directory) / filename
|
|
129
|
+
rel = path.relative_to(root)
|
|
130
|
+
name = rel.as_posix()
|
|
131
|
+
if path.is_symlink() or any(fnmatch.fnmatchcase(name, pattern) for pattern in ignore):
|
|
132
|
+
continue
|
|
133
|
+
is_doc = name == 'README.md' or (path.suffix.lower() == '.md' and 'docs' in rel.parts[:-1])
|
|
134
|
+
if is_doc:
|
|
135
|
+
a, b = claims(path.read_text(encoding='utf-8'))
|
|
136
|
+
positive |= a
|
|
137
|
+
negative |= b
|
|
138
|
+
if path.suffix != '.py':
|
|
139
|
+
continue
|
|
140
|
+
parts = rel.parts[:-1]
|
|
141
|
+
if any(p in {'fixtures', 'docs', 'examples'} for p in parts):
|
|
142
|
+
continue
|
|
143
|
+
test = 'tests' in parts or filename.startswith('test_') or filename.endswith('_test.py')
|
|
144
|
+
try:
|
|
145
|
+
hits = evidence(path.read_text(encoding='utf-8'))
|
|
146
|
+
except (SyntaxError, UnicodeError) as exc:
|
|
147
|
+
errors.append({'path': name, 'message': str(exc)})
|
|
148
|
+
continue
|
|
149
|
+
for hit in hits:
|
|
150
|
+
hit['path'] = name
|
|
151
|
+
(test_evidence if test else production).append(hit)
|
|
152
|
+
findings = []
|
|
153
|
+
if positive and not production:
|
|
154
|
+
findings.append({'rule': 'documented-printer-claim-false', 'severity': 'MEDIUM' if test_evidence else 'HIGH', 'message': 'Local-job claim lacks production submission evidence.'})
|
|
155
|
+
if negative and production:
|
|
156
|
+
findings.append({'rule': 'documented-no-printer-claim-false', 'severity': 'HIGH', 'message': 'Local-job denial conflicts with production submission evidence.'})
|
|
157
|
+
failed = any(f['severity'] == 'HIGH' or fail_on == 'MEDIUM' for f in findings)
|
|
158
|
+
return {'verdict': 'FAIL' if failed else 'PASS', 'findings': findings, 'evidence': production, 'test_evidence': test_evidence, 'parse_errors': errors, 'claims': {'positive': positive, 'negative': negative}}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
from . import __version__, audit
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Parser(argparse.ArgumentParser):
|
|
8
|
+
def error(self, message):
|
|
9
|
+
self.print_usage(sys.stderr)
|
|
10
|
+
self.exit(1, self.prog + ': error: ' + message + '\n')
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main(argv=None):
|
|
14
|
+
parser = Parser(description='Audit local hardcopy job submission claims.')
|
|
15
|
+
parser.add_argument('root')
|
|
16
|
+
parser.add_argument('--json', action='store_true')
|
|
17
|
+
parser.add_argument('--verbose', action='store_true')
|
|
18
|
+
parser.add_argument('--ignore', action='append', default=[])
|
|
19
|
+
parser.add_argument('--fail-on', choices=['HIGH', 'MEDIUM'], default='HIGH')
|
|
20
|
+
parser.add_argument('--version', action='version', version=__version__)
|
|
21
|
+
args = parser.parse_args(argv)
|
|
22
|
+
try:
|
|
23
|
+
result = audit(args.root, args.ignore, args.fail_on)
|
|
24
|
+
except (OSError, ValueError) as exc:
|
|
25
|
+
parser.exit(1, 'error: ' + str(exc) + '\n')
|
|
26
|
+
if args.json:
|
|
27
|
+
print(json.dumps(result))
|
|
28
|
+
else:
|
|
29
|
+
print(result['verdict'])
|
|
30
|
+
for finding in result['findings']:
|
|
31
|
+
print('{severity} {rule}: {message}'.format(**finding))
|
|
32
|
+
if args.verbose:
|
|
33
|
+
for key in ('evidence', 'test_evidence', 'parse_errors'):
|
|
34
|
+
for item in result[key]:
|
|
35
|
+
print(key + ': ' + json.dumps(item))
|
|
36
|
+
return 2 if result['verdict'] == 'FAIL' else 0
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == '__main__':
|
|
40
|
+
sys.exit(main())
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
PRINTER = ('prints documents to your printer', 'print documents to your printer', 'prints files to your printer', 'print files to your printer', 'prints receipts to your printer', 'print receipts to your printer', 'prints labels to your printer', 'print labels to your printer', 'sends documents to your printer', 'send documents to your printer', 'sends files to your printer', 'send files to your printer', 'sends receipts to your printer', 'send receipts to your printer', 'prints to your printer', 'print to your printer', 'uses your printer to print', 'supports printer output', 'printer output support', 'supports direct printing', 'direct printing support', 'receipt printing support', 'label printing support', 'thermal printer support', 'supports thermal printing', 'prints documents', 'print documents', 'prints receipts', 'print receipts', 'prints labels', 'print labels')
|
|
2
|
+
NOPRINTER = ('does not print documents to your printer', 'does not print files to your printer', 'does not print receipts to your printer', 'does not print labels to your printer', 'does not send documents to your printer', 'does not print to your printer', 'does not use your printer', 'does not access your printer', 'printer output not supported', 'direct printing not supported', 'receipt printing not supported', 'label printing not supported', 'no printer output', 'no direct printing', 'without printer output', 'without direct printing', 'no printer support', 'no receipt printing')
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: printer-claim-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Static audit of local hardcopy job submission claims
|
|
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
|
+
# printer-claim-audit
|
|
12
|
+
|
|
13
|
+
An offline static audit for local hardcopy job submission claims. It compares
|
|
14
|
+
root README.md and Markdown files beneath a docs path component against Python
|
|
15
|
+
AST evidence of attached printing device intake. Source is never executed.
|
|
16
|
+
No runtime dependencies are required. Python 3.9 or newer is required.
|
|
17
|
+
|
|
18
|
+
Install and run:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
python3 -m pip install .
|
|
22
|
+
printer-claim-audit /path/to/project --json
|
|
23
|
+
python3 -m printer_claim_audit /path/to/project --verbose
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Options: `--ignore <glob>` is repeatable and matches root-relative paths;
|
|
27
|
+
`--fail-on HIGH` is the default; `--fail-on MEDIUM` also fails on evidence
|
|
28
|
+
found only in test source. `--version` reports 0.1.0. JSON includes verdict,
|
|
29
|
+
findings, production and test evidence locations, claim flags, and parse errors.
|
|
30
|
+
Human output lists findings; verbose output also lists evidence and parse errors.
|
|
31
|
+
Exit 0 means PASS, exit 2 means findings meet the severity threshold, and exit 1
|
|
32
|
+
means invalid usage or an inaccessible root. Findings below the threshold remain
|
|
33
|
+
visible even when the verdict is PASS. At most one finding per claim family is emitted.
|
|
34
|
+
|
|
35
|
+
## Limitations
|
|
36
|
+
|
|
37
|
+
Only the exact phrase templates in the package's `phrases.py` are recognized.
|
|
38
|
+
A bare device noun, tool name, dependency list, user instruction, console message,
|
|
39
|
+
PDF export, file save, screen grab, audio capture, or network send is outside
|
|
40
|
+
that vocabulary. Fenced blocks are excluded; inline code counts. Paragraphs are
|
|
41
|
+
normalized for case, contractions, hyphens, and whitespace. Denial spans are
|
|
42
|
+
removed before affirmative matching.
|
|
43
|
+
|
|
44
|
+
Evidence recognizes bound cups Connection job methods, win32print handle writes,
|
|
45
|
+
and escpos.printer object job methods. Imports, constructors alone, previews,
|
|
46
|
+
strings, comments, and docstrings do not establish capability. Shell spool helpers
|
|
47
|
+
such as lp, lpr, and lpstat are outside the recognized routes.
|
|
48
|
+
|
|
49
|
+
Bindings and aliases are module-local syntactic approximations; this tool does
|
|
50
|
+
not prove execution, device availability, delivery, control flow, or runtime name
|
|
51
|
+
identity. Syntax errors are reported and contribute no evidence. Test source can
|
|
52
|
+
reduce an unsupported affirmative assertion to MEDIUM; a denial contradicted by
|
|
53
|
+
production evidence is HIGH. An affirmative assertion without source is HIGH;
|
|
54
|
+
a denial without source passes. No recognized assertion means PASS.
|
|
55
|
+
|
|
56
|
+
Production excludes tests, test-named modules, fixtures, docs, examples, and
|
|
57
|
+
symlinked files or directories. Environment files are never opened. Ignore globs
|
|
58
|
+
apply to documentation and source. Markdown under any docs path component counts,
|
|
59
|
+
including documentation beneath test directories.
|
|
60
|
+
|
|
61
|
+
Run checks and build distributions:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
python3 -m unittest discover
|
|
65
|
+
python3 -m build
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The tests and fixtures are included in the source distribution. License: MIT.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
printer_claim_audit/__init__.py
|
|
6
|
+
printer_claim_audit/__main__.py
|
|
7
|
+
printer_claim_audit/phrases.py
|
|
8
|
+
printer_claim_audit.egg-info/PKG-INFO
|
|
9
|
+
printer_claim_audit.egg-info/SOURCES.txt
|
|
10
|
+
printer_claim_audit.egg-info/dependency_links.txt
|
|
11
|
+
printer_claim_audit.egg-info/entry_points.txt
|
|
12
|
+
printer_claim_audit.egg-info/top_level.txt
|
|
13
|
+
tests/__init__.py
|
|
14
|
+
tests/test_audit.py
|
|
15
|
+
tests/fixtures/.env
|
|
16
|
+
tests/fixtures/bad/README.md
|
|
17
|
+
tests/fixtures/bad/app.py
|
|
18
|
+
tests/fixtures/case_01/README.md
|
|
19
|
+
tests/fixtures/case_01/app.py
|
|
20
|
+
tests/fixtures/case_02/README.md
|
|
21
|
+
tests/fixtures/case_02/app.py
|
|
22
|
+
tests/fixtures/case_03/README.md
|
|
23
|
+
tests/fixtures/case_03/app.py
|
|
24
|
+
tests/fixtures/case_04/README.md
|
|
25
|
+
tests/fixtures/case_04/app.py
|
|
26
|
+
tests/fixtures/case_05/README.md
|
|
27
|
+
tests/fixtures/case_05/app.py
|
|
28
|
+
tests/fixtures/case_06/README.md
|
|
29
|
+
tests/fixtures/case_06/app.py
|
|
30
|
+
tests/fixtures/case_07/README.md
|
|
31
|
+
tests/fixtures/case_07/app.py
|
|
32
|
+
tests/fixtures/case_08/README.md
|
|
33
|
+
tests/fixtures/case_08/app.py
|
|
34
|
+
tests/fixtures/case_09/README.md
|
|
35
|
+
tests/fixtures/case_09/app.py
|
|
36
|
+
tests/fixtures/case_10/README.md
|
|
37
|
+
tests/fixtures/case_10/app.py
|
|
38
|
+
tests/fixtures/case_11/README.md
|
|
39
|
+
tests/fixtures/case_11/app.py
|
|
40
|
+
tests/fixtures/case_12/README.md
|
|
41
|
+
tests/fixtures/case_12/app.py
|
|
42
|
+
tests/fixtures/case_13/README.md
|
|
43
|
+
tests/fixtures/case_13/app.py
|
|
44
|
+
tests/fixtures/case_14/README.md
|
|
45
|
+
tests/fixtures/case_14/app.py
|
|
46
|
+
tests/fixtures/case_15/README.md
|
|
47
|
+
tests/fixtures/case_15/app.py
|
|
48
|
+
tests/fixtures/case_16/README.md
|
|
49
|
+
tests/fixtures/case_16/app.py
|
|
50
|
+
tests/fixtures/case_17/README.md
|
|
51
|
+
tests/fixtures/case_17/app.py
|
|
52
|
+
tests/fixtures/case_18/README.md
|
|
53
|
+
tests/fixtures/case_18/app.py
|
|
54
|
+
tests/fixtures/case_19/README.md
|
|
55
|
+
tests/fixtures/case_19/app.py
|
|
56
|
+
tests/fixtures/case_20/README.md
|
|
57
|
+
tests/fixtures/case_20/app.py
|
|
58
|
+
tests/fixtures/case_21/README.md
|
|
59
|
+
tests/fixtures/case_21/app.py
|
|
60
|
+
tests/fixtures/case_22/README.md
|
|
61
|
+
tests/fixtures/case_22/app.py
|
|
62
|
+
tests/fixtures/case_23/README.md
|
|
63
|
+
tests/fixtures/case_23/app.py
|
|
64
|
+
tests/fixtures/case_24/README.md
|
|
65
|
+
tests/fixtures/case_24/app.py
|
|
66
|
+
tests/fixtures/case_25/README.md
|
|
67
|
+
tests/fixtures/case_25/app.py
|
|
68
|
+
tests/fixtures/case_26/README.md
|
|
69
|
+
tests/fixtures/case_26/app.py
|
|
70
|
+
tests/fixtures/good/README.md
|
|
71
|
+
tests/fixtures/good/app.py
|
|
72
|
+
tests/fixtures/no_printer/README.md
|
|
73
|
+
tests/fixtures/no_printer/app.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
printer_claim_audit
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "printer-claim-audit"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Static audit of local hardcopy job submission claims"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
printer-claim-audit = "printer_claim_audit.__main__:main"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
include = ["printer_claim_audit*"]
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
AUDIT_MARKER_ONLY
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import cups
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import cups
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
print("receipt")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
DEVICE = "printer"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
p.text("job")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prints documents to your printer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
no printer output
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"""Numbered spec tests plus one independently named test per template phrase."""
|
|
2
|
+
import builtins
|
|
3
|
+
import contextlib
|
|
4
|
+
import io
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import re
|
|
8
|
+
import tempfile
|
|
9
|
+
import unittest
|
|
10
|
+
from unittest.mock import patch
|
|
11
|
+
|
|
12
|
+
from printer_claim_audit import audit, claims, evidence, normalize
|
|
13
|
+
from printer_claim_audit.__main__ import main
|
|
14
|
+
from printer_claim_audit.phrases import PRINTER, NOPRINTER
|
|
15
|
+
|
|
16
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
17
|
+
FIXTURES = ROOT / 'tests' / 'fixtures'
|
|
18
|
+
GOOD = (FIXTURES / 'good' / 'app.py').read_text()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class AuditTests(unittest.TestCase):
|
|
22
|
+
def check_project(self, doc, source=None, location='app.py', fail_on='HIGH'):
|
|
23
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
24
|
+
root = Path(tmp)
|
|
25
|
+
(root / 'README.md').write_text(doc)
|
|
26
|
+
if source is not None:
|
|
27
|
+
target = root / location
|
|
28
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
29
|
+
target.write_text(source)
|
|
30
|
+
return audit(root, fail_on=fail_on)
|
|
31
|
+
|
|
32
|
+
def assert_high(self, result, rule='documented-printer-claim-false'):
|
|
33
|
+
self.assertEqual(result['verdict'], 'FAIL')
|
|
34
|
+
self.assertEqual(len(result['findings']), 1)
|
|
35
|
+
self.assertEqual(result['findings'][0]['severity'], 'HIGH')
|
|
36
|
+
self.assertEqual(result['findings'][0]['rule'], rule)
|
|
37
|
+
|
|
38
|
+
def test_27_denial(self):
|
|
39
|
+
self.assert_high(audit(FIXTURES / 'no_printer'), 'documented-no-printer-claim-false')
|
|
40
|
+
|
|
41
|
+
def test_28_no_claim(self):
|
|
42
|
+
self.assertEqual(self.check_project('Local utility.', GOOD)['findings'], [])
|
|
43
|
+
|
|
44
|
+
def test_29_bare_noun(self):
|
|
45
|
+
self.assertEqual(self.check_project('the printer chapter explains delivery', 'import cups')['findings'], [])
|
|
46
|
+
|
|
47
|
+
def test_30_user_instruction(self):
|
|
48
|
+
for doc in ('connect your printer before starting', 'load paper into your printer first'):
|
|
49
|
+
self.assertEqual(self.check_project(doc, 'import cups')['findings'], [])
|
|
50
|
+
|
|
51
|
+
def test_31_console(self):
|
|
52
|
+
self.assertEqual(self.check_project('prints results to the console', 'print("hi")')['findings'], [])
|
|
53
|
+
|
|
54
|
+
def test_32_pdf(self):
|
|
55
|
+
self.assertEqual(self.check_project('exports a PDF for later printing', 'import reportlab')['findings'], [])
|
|
56
|
+
|
|
57
|
+
def test_33_no_source(self):
|
|
58
|
+
self.assert_high(self.check_project(PRINTER[0]))
|
|
59
|
+
self.assertEqual(self.check_project(NOPRINTER[0])['findings'], [])
|
|
60
|
+
|
|
61
|
+
def test_34_test_only(self):
|
|
62
|
+
for location in ('tests/jobs.py', 'test_jobs.py', 'jobs_test.py'):
|
|
63
|
+
for threshold, verdict in [('HIGH', 'PASS'), ('MEDIUM', 'FAIL')]:
|
|
64
|
+
result = self.check_project(PRINTER[0], GOOD, location, threshold)
|
|
65
|
+
self.assertEqual(result['verdict'], verdict)
|
|
66
|
+
self.assertEqual(result['findings'][0]['severity'], 'MEDIUM')
|
|
67
|
+
|
|
68
|
+
def test_35_fences_inline(self):
|
|
69
|
+
for fence in ('```', '~~~~'):
|
|
70
|
+
self.assertEqual(self.check_project(fence + '\n' + PRINTER[0] + '\n' + fence)['findings'], [])
|
|
71
|
+
self.assert_high(self.check_project('`' + PRINTER[0] + '`'))
|
|
72
|
+
|
|
73
|
+
def test_36_negation(self):
|
|
74
|
+
self.assertEqual(claims('does not print documents to your printer'), (False, True))
|
|
75
|
+
|
|
76
|
+
def test_37_self_audit(self):
|
|
77
|
+
self.assertEqual(audit(ROOT)['findings'], [])
|
|
78
|
+
for path in [ROOT / 'README.md'] + list(ROOT.glob('**/docs/**/*.md')):
|
|
79
|
+
text = normalize(path.read_text())
|
|
80
|
+
for phrase in PRINTER + NOPRINTER:
|
|
81
|
+
self.assertIsNone(re.search(r'\b' + re.escape(phrase) + r'\b', text), (path, phrase))
|
|
82
|
+
self.assertIsNone(re.search(r'\b(using|uses|with|via|over|supports|sends|send)\s+printer claim audit\b', text))
|
|
83
|
+
|
|
84
|
+
def invoke(self, args):
|
|
85
|
+
output = io.StringIO()
|
|
86
|
+
with contextlib.redirect_stdout(output), contextlib.redirect_stderr(io.StringIO()):
|
|
87
|
+
try:
|
|
88
|
+
code = main(args)
|
|
89
|
+
except SystemExit as exc:
|
|
90
|
+
code = exc.code
|
|
91
|
+
return code, output.getvalue()
|
|
92
|
+
|
|
93
|
+
def test_38_cli(self):
|
|
94
|
+
self.assertEqual(self.invoke(['--version']), (0, '0.1.0\n'))
|
|
95
|
+
code, output = self.invoke([str(FIXTURES / 'good'), '--json'])
|
|
96
|
+
self.assertEqual(code, 0)
|
|
97
|
+
self.assertEqual(json.loads(output)['verdict'], 'PASS')
|
|
98
|
+
self.assertIn('cups', self.invoke([str(FIXTURES / 'good'), '--verbose'])[1])
|
|
99
|
+
self.assertEqual(self.invoke([str(FIXTURES / 'bad'), '--ignore', 'README.md'])[0], 0)
|
|
100
|
+
self.assertEqual(self.invoke(['/nonexistent/path'])[0], 1)
|
|
101
|
+
self.assertEqual(self.invoke(['--fail-on', 'LOW'])[0], 1)
|
|
102
|
+
self.assertEqual(self.invoke([str(FIXTURES / 'bad')])[0], 2)
|
|
103
|
+
|
|
104
|
+
def test_39_env_guard(self):
|
|
105
|
+
original = io.open
|
|
106
|
+
def guarded(path, *args, **kwargs):
|
|
107
|
+
if str(path).endswith('.env'):
|
|
108
|
+
raise AssertionError('environment file opened')
|
|
109
|
+
return original(path, *args, **kwargs)
|
|
110
|
+
with patch('io.open', guarded), patch('builtins.open', guarded):
|
|
111
|
+
self.assertEqual(audit(ROOT)['verdict'], 'PASS')
|
|
112
|
+
self.assertTrue((FIXTURES / '.env').is_file())
|
|
113
|
+
|
|
114
|
+
def test_40_packaging(self):
|
|
115
|
+
for path in ROOT.rglob('*'):
|
|
116
|
+
if path.is_file() and (path.suffix == '.py' or path.name == 'README.md'):
|
|
117
|
+
self.assertIsNone(re.search(r'\b' + 'py' + r'thon\b', path.read_text()), str(path))
|
|
118
|
+
config = (ROOT / 'pyproject.toml').read_text()
|
|
119
|
+
self.assertIn('setuptools>=77', config)
|
|
120
|
+
self.assertIn('license = "MIT"', config)
|
|
121
|
+
self.assertIn('>=3.9', config)
|
|
122
|
+
self.assertIn('recursive-include tests', (ROOT / 'MANIFEST.in').read_text())
|
|
123
|
+
|
|
124
|
+
def test_41_phrase_inventory(self):
|
|
125
|
+
self.assertEqual(len(PRINTER), 31)
|
|
126
|
+
self.assertEqual(len(NOPRINTER), 18)
|
|
127
|
+
|
|
128
|
+
def test_normalization_boundaries(self):
|
|
129
|
+
self.assertEqual(claims("DOESN'T PRINT\nDOCUMENTS TO YOUR PRINTER"), (False, True))
|
|
130
|
+
self.assertEqual(claims('supports-direct-printing'), (True, False))
|
|
131
|
+
self.assertEqual(claims('reprints documentsXYZ'), (False, False))
|
|
132
|
+
self.assertEqual(claims('prints\n\ndocuments'), (False, False))
|
|
133
|
+
|
|
134
|
+
def test_extra_routes(self):
|
|
135
|
+
for source in [
|
|
136
|
+
'from cups.sub import Connection as C\nC().printFiles([])',
|
|
137
|
+
'from win32print import OpenPrinter as O, WritePrinter as W\nW(O("p"), b"x")',
|
|
138
|
+
'import win32print as w\nh=w.OpenPrinter("p")\nw.WritePrinter(h,b"x")',
|
|
139
|
+
'import escpos.printer\nescpos.printer.File("f").barcode("x")',
|
|
140
|
+
'from escpos.printer.sub import File as F\nF("f").image("x")']:
|
|
141
|
+
with self.subTest(source=source):
|
|
142
|
+
self.assertTrue(evidence(source))
|
|
143
|
+
|
|
144
|
+
def test_extra_non_evidence(self):
|
|
145
|
+
for source in [
|
|
146
|
+
'conn.printFile("x")', 'import escpos\nescpos.Usb(1,2).text("x")',
|
|
147
|
+
'from other import Connection\nConnection().printFile("x")',
|
|
148
|
+
'def print_job():\n print("x")',
|
|
149
|
+
'@app.post("/print")\ndef job():\n return "printer"',
|
|
150
|
+
'preview("receipt")', '# cups.Connection().printFile("x")',
|
|
151
|
+
'"""cups.Connection().printFile("x")"""',
|
|
152
|
+
'import subprocess\nsubprocess.run(["lpr", "f"])',
|
|
153
|
+
'import subprocess\nsubprocess.run(["lpstat"])']:
|
|
154
|
+
with self.subTest(source=source):
|
|
155
|
+
self.assertFalse(evidence(source))
|
|
156
|
+
|
|
157
|
+
def test_scopes_symlinks_ignore_errors(self):
|
|
158
|
+
for location in ('fixtures/job.py', 'docs/job.py', 'examples/job.py'):
|
|
159
|
+
self.assert_high(self.check_project(PRINTER[0], GOOD, location))
|
|
160
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
161
|
+
root = Path(tmp)
|
|
162
|
+
(root / 'README.md').write_text(PRINTER[0])
|
|
163
|
+
(root / 'linked.py').symlink_to(FIXTURES / 'good' / 'app.py')
|
|
164
|
+
self.assert_high(audit(root))
|
|
165
|
+
(root / 'broken.py').write_text('def (')
|
|
166
|
+
self.assertTrue(audit(root)['parse_errors'])
|
|
167
|
+
docs = root / 'tests' / 'docs'
|
|
168
|
+
docs.mkdir(parents=True)
|
|
169
|
+
(docs / 'guide.md').write_text(NOPRINTER[0])
|
|
170
|
+
(root / 'job.py').write_text(GOOD)
|
|
171
|
+
self.assert_high(audit(root), 'documented-no-printer-claim-false')
|
|
172
|
+
self.assertEqual(audit(root, ['tests/docs/*'])['findings'], [])
|
|
173
|
+
|
|
174
|
+
def test_two_families_max(self):
|
|
175
|
+
result = self.check_project('\n\n'.join(PRINTER + NOPRINTER))
|
|
176
|
+
self.assertEqual(len(result['findings']), 1)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def numbered(index):
|
|
180
|
+
def test(self):
|
|
181
|
+
result = audit(FIXTURES / ('case_%02d' % index))
|
|
182
|
+
if index <= 14:
|
|
183
|
+
self.assertEqual(result['findings'], [])
|
|
184
|
+
self.assertTrue(result['evidence'])
|
|
185
|
+
else:
|
|
186
|
+
self.assert_high(result)
|
|
187
|
+
return test
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
for index in range(1, 27):
|
|
191
|
+
setattr(AuditTests, 'test_%02d_fixture' % index, numbered(index))
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def phrase_test(phrase, negative):
|
|
195
|
+
def test(self):
|
|
196
|
+
self.assertEqual(claims(phrase), (not negative, negative))
|
|
197
|
+
if negative:
|
|
198
|
+
self.assert_high(self.check_project(phrase, GOOD), 'documented-no-printer-claim-false')
|
|
199
|
+
self.assertEqual(self.check_project(phrase)['findings'], [])
|
|
200
|
+
else:
|
|
201
|
+
self.assert_high(self.check_project(phrase))
|
|
202
|
+
self.assertEqual(self.check_project(phrase, GOOD)['findings'], [])
|
|
203
|
+
return test
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
# Every generated method covers exactly the phrase encoded in its method name.
|
|
207
|
+
for negative, phrases in [(False, PRINTER), (True, NOPRINTER)]:
|
|
208
|
+
for phrase in phrases:
|
|
209
|
+
setattr(AuditTests, 'test_phrase_' + phrase.replace(' ', '_'), phrase_test(phrase, negative))
|