diff --git a/brel/brel_fact.py b/brel/brel_fact.py index 2bf76733..281ad9bc 100644 --- a/brel/brel_fact.py +++ b/brel/brel_fact.py @@ -71,9 +71,7 @@ def get_context(self) -> Context: return self.__context def get_value_as_str(self) -> str: - """ - :returns str: The value of the fact as a string. - """ + """[DEPRECATED] Use str() instead.""" return self.__value def get_value_as_int(self) -> int: @@ -141,27 +139,21 @@ def get_value(self) -> Any: def get_precision(self) -> float | None: """ - :returns Any: The precision of the fact. Only applies to numeric facts. + :returns float: The precision of the fact. Only applies to numeric facts. """ return self.__precision def get_decimals(self) -> float | None: """ - :returns Any: The decimals property of the fact. Only applies to numeric facts. + :returns float: The decimals property of the fact. Only applies to numeric facts. """ return self.__decimals def __str__(self) -> str: """ - :returns str: The fact represented as a string. + :returns str: The fact value as a string. """ - output = "" - for aspect in self.__context.get_aspects(): - aspect_name = aspect.get_name() - aspect_value = self.__context.get_characteristic(aspect) - output += f"{aspect_name}: {aspect_value}, " - output += f"value: {self.__value}" - return output + return self.__value # 2nd class citizens def get_concept(self) -> ConceptCharacteristic: diff --git a/tests/core_tests/test_fact.py b/tests/core_tests/test_fact.py index a195427b..43a05256 100644 --- a/tests/core_tests/test_fact.py +++ b/tests/core_tests/test_fact.py @@ -9,6 +9,7 @@ """ import brel +import json def test_qname_getters(): @@ -17,12 +18,12 @@ def test_qname_getters(): # check if a fact with value = "true" is parsed correctly as a bool fact = filing.get_facts_by_concept_name("dei:DocumentQuarterlyReport")[0] - assert fact._get_id() == "f-2", "Expected fact id to be 'f-2'" # type: ignore + assert fact.get_id() == "f-2", "Expected fact id to be 'f-2'" # type: ignore context = fact.get_context() assert context._get_id() == "c-1", "Expected context id to be 'c-1'" # type: ignore - assert fact.get_value_as_str() == "true", "Expected 'true' as fact value is 'true'" + assert str(fact) == "true", "Expected 'true' as fact value is 'true'" assert bool(fact) == True, "Expected True as fact value is 'true'" try: int(fact) @@ -47,17 +48,15 @@ def test_qname_getters(): fact.get_entity() ), "Expected '320193' to be in fact entity string" - fact_str = str(fact) - assert "concept" in fact_str, "Expected 'concept' to be in fact string" - assert "period" in fact_str, "Expected 'period' to be in fact string" - assert "entity" in fact_str, "Expected 'entity' to be in fact string" - assert "unit" not in fact_str, "Expected 'unit' not to be in fact string" + fact_str = json.dumps(dict(fact)) + assert "concept" in fact_str, "Expected 'concept' to be in fact dict" + assert "period" in fact_str, "Expected 'period' to be in fact dict" + assert "entity" in fact_str, "Expected 'entity' to be in fact dict" + assert "unit" not in fact_str, "Expected 'unit' not to be in fact dict" # check if parsing a false fact as bool works fact = filing.get_facts_by_concept_name("dei:AmendmentFlag")[0] - assert ( - fact.get_value_as_str() == "false" - ), "Expected 'false' as fact value is 'false'" + assert str(fact) == "false", "Expected 'false' as fact value is 'false'" assert bool(fact) == False, "Expected False as fact value is 'false'" # check for an integer fact