Skip to content

Commit

Permalink
Display symbolic Enum values in print_computation_log
Browse files Browse the repository at this point in the history
  • Loading branch information
Morendil committed Apr 13, 2019
1 parent f4f1f85 commit 9694f2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions openfisca_core/indexed_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,6 @@ def decode_to_str(self):

def __repr__(self):
return '{}({})'.format(self.__class__.__name__, str(self.decode()))

def __str__(self):
return str(self.decode_to_str())
10 changes: 10 additions & 0 deletions tests/core/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from openfisca_core.tracers import Tracer, TracingParameterNodeAtInstant
from openfisca_core.tools import assert_near

from openfisca_country_template.variables.housing import HousingOccupancyStatus
from .parameters_fancy_indexing.test_fancy_indexing import parameters


Expand Down Expand Up @@ -40,6 +41,15 @@ def test_log_format():
assert lines[1] == ' B<2017> >> 1'


def test_trace_enums():
tracer = Tracer()
tracer.record_calculation_start("A", 2017)
tracer.record_calculation_end("A", 2017, HousingOccupancyStatus.encode(np.array(['tenant'])))

lines = tracer.computation_log()
assert lines[0] == ' A<2017> >> [\'tenant\']'


# Tests on tracing with fancy indexing
zone = np.asarray(['z1', 'z2', 'z2', 'z1'])
housing_occupancy_status = np.asarray(['owner', 'owner', 'tenant', 'tenant'])
Expand Down

0 comments on commit 9694f2c

Please sign in to comment.