"""Test that the print layer reports failure honestly instead of always True.""" import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) os.chdir(os.path.dirname(os.path.abspath(__file__))) from print_label import print_to_printer, _sumatra_print, SUMATRA_EXIT_CODES SUMATRA = os.path.join(os.path.dirname(os.path.abspath(__file__)), "SumatraPDF", "SumatraPDF.exe") def main() -> int: print("1. SumatraPDF exit-code handling") # Nonexistent printer must fail, not silently succeed. ok, message = _sumatra_print(SUMATRA, "NoSuchPrinter_XYZ", "nope.pdf", "noscale") print(f" missing file + printer -> success={ok}") print(f" message: {message}") file_missing_ok = not ok print("\n2. Documented exit codes are mapped") for code in sorted(SUMATRA_EXIT_CODES): print(f" {code}: {SUMATRA_EXIT_CODES[code]}") print("\n3. print_to_printer on a nonexistent PDF must return False") result = print_to_printer("Brother PT-E560BT", "does_not_exist.pdf", settings="noscale") print(f" returned: {result} {'PASS' if result is False else 'FAIL'}") print("\n" + "=" * 60) passed = file_missing_ok and result is False print("RESULT:", "PASS" if passed else "FAIL") return 0 if passed else 1 if __name__ == "__main__": raise SystemExit(main())