Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions brel/brel_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 9 additions & 10 deletions tests/core_tests/test_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import brel
import json


def test_qname_getters():
Expand All @@ -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)
Expand All @@ -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
Expand Down
Loading