Skip to content

Commit

Permalink
Fixing __doc__ and __name__ storage in Transportable Object (#1112)
Browse files Browse the repository at this point in the history
* Fixing  and  storage in Transportable Object

* Fixing  and  storage in Transportable Object

* Added test
  • Loading branch information
kessler-frost authored Aug 23, 2022
1 parent 4b2db7c commit d08e8bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UNRELEASED]

### Fixed

- Function's `__doc__` and `__name__` storage in dict/json for transportable object fixed.

### Tests

- Added unit test for the above fix.

## [0.184.0] - 2022-08-22

### Authors
Expand Down
2 changes: 1 addition & 1 deletion covalent/_workflow/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, obj: Any) -> None:
except TypeError as ex:
self._json = ""

self.attrs = {"doc": getattr(obj, "doc", ""), "name": getattr(obj, "name", "")}
self.attrs = {"doc": getattr(obj, "__doc__", ""), "name": getattr(obj, "__name__", "")}

def __eq__(self, obj) -> bool:
if not isinstance(obj, TransportableObject):
Expand Down
11 changes: 10 additions & 1 deletion tests/covalent_tests/workflow/transport_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def subtask(x):


def subtask_2(x):
"""Workflow subtask."""
"""Workflow subtask 2."""

return x

Expand Down Expand Up @@ -133,6 +133,15 @@ def test_transportable_object_from_dict(transportable_object):
assert to == to_new


def test_transportable_object_to_dict_attributes(transportable_object):
"""Test attributes from `to_dict` contain correct name and docstrings"""

tr_dict = transportable_object.to_dict()

assert tr_dict["attributes"]["attrs"]["doc"] == subtask.__doc__
assert tr_dict["attributes"]["attrs"]["name"] == subtask.__name__


def test_transportable_object_serialize_to_json(transportable_object):
import json

Expand Down

0 comments on commit d08e8bf

Please sign in to comment.