Last active
August 29, 2015 14:18
-
-
Save retr0h/d0a6773bfe1d697c16c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m = mock.Mock(name='name', | |
description='desc', | |
id='12345', | |
enabled=True) | |
g = {m.name: {'description': m.description, | |
'id': m.id}} | |
print g | |
print yaml.safe_dump(g, default_flow_style=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{<Mock name='name.name' id='4326965456'>: {'description': 'desc', 'id': '12345'}} | |
Traceback (most recent call last): | |
File "test.py", line 17, in <module> | |
print yaml.safe_dump(m, default_flow_style=False) | |
File "/Library/Python/2.7/site-packages/yaml/__init__.py", line 218, in safe_dump | |
return dump_all([data], stream, Dumper=SafeDumper, **kwds) | |
File "/Library/Python/2.7/site-packages/yaml/__init__.py", line 190, in dump_all | |
dumper.represent(data) | |
File "/Library/Python/2.7/site-packages/yaml/representer.py", line 28, in represent | |
node = self.represent_data(data) | |
File "/Library/Python/2.7/site-packages/yaml/representer.py", line 67, in represent_data | |
node = self.yaml_representers[None](self, data) | |
File "/Library/Python/2.7/site-packages/yaml/representer.py", line 247, in represent_undefined | |
raise RepresenterError("cannot represent an object: %s" % data) | |
yaml.representer.RepresenterError: cannot represent an object: <Mock name='name' id='4326915920'> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m = mock.Mock(shit='name', | |
description='desc', | |
id='12345', | |
enabled=True) | |
g = {m.shit: {'description': m.description, | |
'id': m.id}} | |
print g | |
print yaml.safe_dump(g, default_flow_style=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{'name': {'description': 'desc', 'id': '12345'}} | |
name: | |
description: desc | |
id: '12345' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stumbled across blog where the comments suggest using
mock.configure_mock()
. Works great.