Skip to content

Commit

Permalink
fix: encoding detection with new charset_normalizer api
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Nov 13, 2024
1 parent 8402bad commit 5e39587
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions translation_finder/discovery/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class OSXDiscovery(EncodingDiscovery):

file_format = "strings-utf8"
encoding_map = {
"utf-16": "strings",
"utf_16": "strings",
}

def possible_templates(self, language: str, mask: str) -> Generator[str]:
Expand Down Expand Up @@ -249,8 +249,8 @@ class JavaDiscovery(EncodingDiscovery):

file_format = "properties"
encoding_map = {
"utf-8": "properties-utf8",
"utf-16": "properties-utf16",
"utf_8": "properties-utf8",
"utf_16": "properties-utf16",
}
mask = ("*_*.properties", "*.properties")

Expand Down
18 changes: 13 additions & 5 deletions translation_finder/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

from operator import itemgetter
from pathlib import Path, PurePath
from typing import TYPE_CHECKING
from unittest import TestCase

from .discovery.base import DiscoveryResult
from .discovery.base import DiscoveryResult, ResultDict
from .discovery.files import (
AndroidDiscovery,
AppStoreDiscovery,
Expand Down Expand Up @@ -38,6 +39,9 @@
from .discovery.transifex import TransifexDiscovery
from .finder import Finder

if TYPE_CHECKING:
from collections.abc import Iterable

TEST_DATA = Path(__file__).parent / "test_data"


Expand All @@ -60,13 +64,17 @@ def get_finder(paths, dirs=None):
def get_real_finder():
return Finder(TEST_DATA)

def assert_discovery(self, first, second) -> None:
def assert_discovery(
self, actual: Iterable[DiscoveryResult], expected: list[ResultDict]
) -> None:
actual_list = sorted(actual, key=itemgetter("filemask"))
expected_list = sorted(expected, key=itemgetter("filemask"))
self.assertEqual(
sorted(first, key=itemgetter("filemask")),
sorted(second, key=itemgetter("filemask")),
len(actual_list), len(expected_list), "Mismatched count of results"
)
for value in first:
for i, value in enumerate(actual_list):
self.assertIsInstance(value, DiscoveryResult)
self.assertEqual(value.data, expected_list[i])


class GetttetTest(DiscoveryTestCase):
Expand Down

0 comments on commit 5e39587

Please sign in to comment.