-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Apply
CultureInfo.InvariantCulture
not to be affected by syste…
…m `locale` setting (#386)
- Loading branch information
1 parent
a4a39ab
commit 283c83f
Showing
12 changed files
with
111 additions
and
42 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
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,3 @@ | ||
[pytest] | ||
markers = | ||
locale_specific: marks locale_specific test (deselect with '-m "not locale_specific"') |
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
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
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
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,40 @@ | ||
from decimal import Decimal as PyDecimal | ||
|
||
import pytest | ||
|
||
from stock_indicators._cslib import CsDecimal | ||
from stock_indicators._cstypes import Decimal as CsDecimalConverter | ||
from stock_indicators._cstypes.decimal import to_pydecimal | ||
|
||
@pytest.mark.locale_specific | ||
class TestLocale: | ||
''' | ||
These tests are intended for environments where a comma is used as the decimal separator, | ||
such as when the current system locale is ru_RU.UTF-8. | ||
''' | ||
def test_conversion_to_Python_decimal_with_comma_decimal_separator(self): | ||
cs_decimal = CsDecimal.Parse('1996,1012') | ||
assert '1996,1012' == str(cs_decimal) | ||
assert PyDecimal('1996.1012') == to_pydecimal(cs_decimal) | ||
|
||
def test_conversion_to_CSharp_decimal_with_comma_decimal_separator(self): | ||
# Applied CultureInfo.InvariantCulture, comma as a decimal separator should be ignored. | ||
cs_decimal = CsDecimalConverter('1996,10.12') | ||
assert '199610,12' == str(cs_decimal) | ||
assert PyDecimal('199610.12') == to_pydecimal(cs_decimal) | ||
|
||
def test_re_conversion_to_CSharp_decimal_with_comma_decimal_separator(self): | ||
# result value will be distorted | ||
# if CsDecimal is converted into CsDecimal again, since comma as a decimal separator would be ignored. | ||
# Note: did not add defensive logic to avoid performance loss. | ||
cs_decimal = CsDecimalConverter('1996,10.12') | ||
assert '199610,12' == str(cs_decimal) | ||
|
||
cs_decimal = CsDecimalConverter(cs_decimal) | ||
assert '19961012' == str(cs_decimal) | ||
|
||
def test_conversion_to_double_with_comma_decimal_separator(self): | ||
from System import Double as CsDouble | ||
|
||
cs_double = CsDouble.Parse('1996,1012') | ||
assert 1996.1012 == cs_double # should be period-separated float. |