From 9b0fce3faccbc52c8b22770a016bb7f8fbf92cbd Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Tue, 12 May 2026 09:47:43 +0200 Subject: [PATCH] test(license): cover Python shebang and encoding-declaration placement (ref #81) Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/test_license_headers.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_license_headers.py b/tests/test_license_headers.py index 32bb3807..8a57ac91 100644 --- a/tests/test_license_headers.py +++ b/tests/test_license_headers.py @@ -132,3 +132,26 @@ def test_apply_foreign_python_unchanged(): src = "# SPDX-License-Identifier: MIT\nprint('x')\n" out = license_headers.apply(src, ".py") assert out == src + + +def test_apply_python_with_shebang(): + src = '#!/usr/bin/env python3\nprint("x")\n' + out = license_headers.apply(src, ".py") + assert out.startswith("#!/usr/bin/env python3\n") + assert out.splitlines()[1] == "# SPDX-License-Identifier: LicenseRef-CMSD-1.0" + + +def test_apply_python_with_encoding(): + src = '# -*- coding: utf-8 -*-\nprint("x")\n' + out = license_headers.apply(src, ".py") + assert out.startswith("# -*- coding: utf-8 -*-\n") + assert out.splitlines()[1] == "# SPDX-License-Identifier: LicenseRef-CMSD-1.0" + + +def test_apply_python_with_shebang_and_encoding(): + src = '#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\nprint("x")\n' + out = license_headers.apply(src, ".py") + lines = out.splitlines() + assert lines[0] == "#!/usr/bin/env python3" + assert lines[1] == "# -*- coding: utf-8 -*-" + assert lines[2] == "# SPDX-License-Identifier: LicenseRef-CMSD-1.0"