-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix money formatting when numeric locale could not be inferred
On windows numeric locale could not be inffered. In case this happens we overwrite environment locale with default pl_PL locale
- Loading branch information
Showing
6 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import logging | ||
|
||
from babel import default_locale | ||
|
||
|
||
def get_numeric_locale() -> str: | ||
if not get_numeric_locale.__numeric_locale: | ||
default_numeric_locale = "pl_PL" | ||
logging.getLogger().warning( | ||
f"Numeric locale could not be deduced from the environment, setting {default_numeric_locale} by default") | ||
get_numeric_locale.__numeric_locale = default_numeric_locale | ||
return get_numeric_locale.__numeric_locale | ||
|
||
|
||
get_numeric_locale.__numeric_locale = default_locale('LC_NUMERIC') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Optional | ||
|
||
import pytest | ||
|
||
from banker.common.locale import get_numeric_locale | ||
|
||
|
||
@pytest.fixture | ||
def numeric_locale_patch(mocker): | ||
def _numeric_locale_patch(locale: Optional[str]) -> str: | ||
return mocker.patch('banker.common.locale.get_numeric_locale.__numeric_locale', locale) | ||
|
||
return _numeric_locale_patch | ||
|
||
|
||
def test_given_locale_read_from_environment_when_get_locale_then_return_environment_locale(numeric_locale_patch): | ||
numeric_locale_patch("en_US") | ||
assert get_numeric_locale() == "en_US" | ||
assert get_numeric_locale() == "en_US" | ||
assert get_numeric_locale() == "en_US" | ||
|
||
|
||
def test_given_no_environment_locale_when_get_locale_then_return_default_locale(numeric_locale_patch): | ||
numeric_locale_patch(None) | ||
assert get_numeric_locale() == "pl_PL" | ||
assert get_numeric_locale() == "pl_PL" | ||
assert get_numeric_locale() == "pl_PL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters