Skip to content

Commit

Permalink
added in method that converts any SpockSpace derived from the SpockBu…
Browse files Browse the repository at this point in the history
…ilder into its dictionary representation. added unit test. (#213)
  • Loading branch information
ncilfone committed Jan 26, 2022
1 parent a8e7547 commit 15aa79c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
12 changes: 12 additions & 0 deletions spock/builder.py
Expand Up @@ -573,6 +573,18 @@ def config_2_dict(self):
"""Dictionary representation of the arg payload"""
return self._saver_obj.dict_payload(self._arg_namespace)

def spockspace_2_dict(self, payload: Spockspace):
"""Converts an input SpockSpace into a dictionary
Args:
payload: SpockSpace generated by the ConfigArgBuilder
Returns:
dictionary representation of the SpockSpace
"""
return self._saver_obj.dict_payload(payload)

def evolve(self, *args: typing.Type[_CLS]):
"""Function that allows a user to evolve the underlying spock classes with instantiated spock objects
Expand Down
26 changes: 25 additions & 1 deletion tests/base/test_evolve.py
Expand Up @@ -89,7 +89,6 @@ def arg_builder(monkeypatch):
return config

def test_evolve(self, arg_builder):

evolve_nested_stuff = EvolveNestedStuff(
one=12345, two='abcdef'
)
Expand Down Expand Up @@ -148,3 +147,28 @@ def test_raise_not_input(self, arg_builder):
evolve_not_evolved = NotEvolved(one=100)
with pytest.raises(_SpockEvolveError):
new_class = arg_builder.evolve(evolve_not_evolved)

def test_2_dict(self, arg_builder):
evolve_nested_stuff = EvolveNestedStuff(
one=12345, two='abcdef'
)
evolve_type_config = TypeThinDefaultConfig(
bool_p_set_def=False,
int_p_def=16,
float_p_def=16.0,
string_p_def="Spocked",
list_p_float_def=[16.0, 26.0],
list_p_int_def=[16, 26],
list_p_str_def=["Spocked", "Packaged"],
list_p_bool_def=[False, True],
tuple_p_float_def=(16.0, 26.0),
tuple_p_int_def=(16, 26),
tuple_p_str_def=("Spocked", "Packaged"),
tuple_p_bool_def=(False, True),
choice_p_str_def="option_1",
list_choice_p_str_def=["option_2"],
list_list_choice_p_str_def=[["option_2"], ["option_2"]]
)
# Evolve the class
new_class = arg_builder.evolve(evolve_nested_stuff, evolve_type_config)
assert isinstance(arg_builder.spockspace_2_dict(new_class), dict) is True

0 comments on commit 15aa79c

Please sign in to comment.