From c403271ec9e89595ed4b82a4fc2a7bcbae4d7126 Mon Sep 17 00:00:00 2001 From: David Seddon Date: Wed, 25 Jun 2025 17:51:40 +0100 Subject: [PATCH] Add test for handling Python files that are not in UTF8 --- .../encodingpackage/shift_jis_importer.py | 3 +++ tests/functional/test_encoding_handling.py | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/assets/encodingpackage/shift_jis_importer.py diff --git a/tests/assets/encodingpackage/shift_jis_importer.py b/tests/assets/encodingpackage/shift_jis_importer.py new file mode 100644 index 00000000..d239fb28 --- /dev/null +++ b/tests/assets/encodingpackage/shift_jis_importer.py @@ -0,0 +1,3 @@ +# -*- coding: shift_jis -*- + +from .imported import ƒÎ diff --git a/tests/functional/test_encoding_handling.py b/tests/functional/test_encoding_handling.py index 6f9b7588..21a8f5a2 100644 --- a/tests/functional/test_encoding_handling.py +++ b/tests/functional/test_encoding_handling.py @@ -19,3 +19,23 @@ def test_build_graph_of_non_ascii_source(): "line_contents": "from .imported import Ï€", }, ] == result + + +def test_build_graph_of_non_utf8_source(): + """ + Tests we can cope with non UTF-8 Python source files. + """ + graph = grimp.build_graph("encodingpackage", cache_dir=None) + + result = graph.get_import_details( + importer="encodingpackage.shift_jis_importer", imported="encodingpackage.imported" + ) + + assert [ + { + "importer": "encodingpackage.shift_jis_importer", + "imported": "encodingpackage.imported", + "line_number": 3, + "line_contents": "from .imported import Ï€", + }, + ] == result