mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 10:59:40 +00:00
Prefer country over language family + MATCH_ALL (#91753)
* Prefer country over language family * More test fixes
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
"""Test Home Assistant language util methods."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.const import MATCH_ALL
|
||||
from homeassistant.util import language
|
||||
|
||||
|
||||
def test_match_all() -> None:
|
||||
"""Test MATCH_ALL."""
|
||||
assert language.matches(MATCH_ALL, ["fr-Fr", "en-US", "en-GB"]) == [
|
||||
"fr-Fr",
|
||||
"en-US",
|
||||
"en-GB",
|
||||
]
|
||||
|
||||
|
||||
def test_region_match() -> None:
|
||||
"""Test that an exact language/region match is preferred."""
|
||||
assert language.matches("en-GB", ["fr-Fr", "en-US", "en-GB"]) == [
|
||||
@@ -53,6 +63,26 @@ def test_country_preferred() -> None:
|
||||
]
|
||||
|
||||
|
||||
def test_country_preferred_over_family() -> None:
|
||||
"""Test that country hint is preferred over language family."""
|
||||
assert (
|
||||
language.matches(
|
||||
"de",
|
||||
["de", "de-CH", "de-DE"],
|
||||
country="CH",
|
||||
)[0]
|
||||
== "de-CH"
|
||||
)
|
||||
assert (
|
||||
language.matches(
|
||||
"de",
|
||||
["de", "de-CH", "de-DE"],
|
||||
country="DE",
|
||||
)[0]
|
||||
== "de-DE"
|
||||
)
|
||||
|
||||
|
||||
def test_language_as_region() -> None:
|
||||
"""Test that the language itself can be interpreted as a region."""
|
||||
assert language.matches(
|
||||
|
||||
Reference in New Issue
Block a user