-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Decimal comparision to load decimal value at load time instead of…
… check time * Added custom tag "!decimal" and "!decimallist" and use them to load decimal value as decimal
- Loading branch information
1 parent
6cf036e
commit 5cc3c8c
Showing
12 changed files
with
123 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from decimal import Decimal | ||
from typing import NamedTuple | ||
|
||
from bft.core.yaml_parser import BaseYamlParser | ||
|
||
|
||
class TestDecimalResult(NamedTuple): | ||
cases: Decimal | list[Decimal] | ||
|
||
class TestCaseVisitor(): | ||
def visit(self, testcase): | ||
return TestDecimalResult(testcase) | ||
class DecimalTestCaseParser(BaseYamlParser[TestDecimalResult]): | ||
def get_visitor(self) -> TestCaseVisitor: | ||
return TestCaseVisitor() | ||
|
||
def test_yaml_parser_decimal_tag(): | ||
parser = DecimalTestCaseParser() | ||
# parser returns list of parsed values | ||
assert parser.parse(b"!decimal 1") == [TestDecimalResult(Decimal('1'))] | ||
assert parser.parse(b"!decimal 1.78766") == [TestDecimalResult(Decimal('1.78766'))] | ||
assert parser.parse(b"!decimal null") == [TestDecimalResult(None)] | ||
assert parser.parse(b"!decimallist [1.2, null, 7.547]") == [TestDecimalResult([Decimal('1.2'), None, Decimal('7.547')])] |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.