def test_sanitize(): p = ots.sanitize() assert p.returncode == 1 assert len(p.args) == 1 assert p.args[0].endswith("ots-sanitize") assert p.stdout == None assert p.stderr == None
def _get_ots_result(path): """ Sanitize with ots-python and process the result. """ ots_out = ots.sanitize(path, capture_output=True) sanitized = b'File sanitized successfully!' in ots_out.stdout modified = sanitized messages = ots_out.stderr.decode('ascii', errors="ignore") return pyots.OTSResult((sanitized, modified, messages))
def com_google_fonts_check_ots(font): """Checking with ots-sanitize.""" import ots try: process = ots.sanitize(font, check=True, capture_output=True) except ots.CalledProcessError as e: yield FAIL, ( "ots-sanitize returned an error code ({}). Output follows:\n\n{}{}" ).format(e.returncode, e.stderr.decode(), e.stdout.decode()) else: if process.stderr: yield WARN, ( "ots-sanitize passed this file, however warnings were printed:\n\n{}" ).format(process.stderr.decode()) else: yield PASS, "ots-sanitize passed this file"
def main(gf_path): results = [] for p, i, files in os.walk(gf_path): for f in files: if f.endswith('.ttf'): try: font = os.path.join(p, f) process = ots.sanitize(font, check=True, capture_output=True) result = '%s\t%s' % (font, process.stdout) except ots.CalledProcessError as e: result = '%s\t%s' % (font, e.output) results.append(result) print('%s\t%s' % (f, result)) with open('ots_gf_results.txt', 'w') as doc: doc.write(''.join(results)) print('done!')
def main(args=None): if args is None: args = sys.argv[1:] return ots.sanitize(*args).returncode
def test_capture_output(): p = ots.sanitize(capture_output=True) assert len(p.stdout) == 0 stderr = p.stderr.decode() assert stderr.startswith("Usage: ")
def test_check_error(): with pytest.raises(subprocess.CalledProcessError): ots.sanitize("--foo", "bar", check=True)