Added __str__ to ClusterSpec. This will improve the logs users are attaching to github issues.
For example : #14942 PiperOrigin-RevId: 178296636
This commit is contained in:
parent
daab44f7af
commit
2d4c29cd6a
@ -307,6 +307,12 @@ class ClusterSpec(object):
|
||||
def __ne__(self, other):
|
||||
return self._cluster_spec != other
|
||||
|
||||
def __str__(self):
|
||||
key_values = self.as_dict()
|
||||
string_items = [
|
||||
repr(k) + ": " + repr(key_values[k]) for k in sorted(key_values)]
|
||||
return "ClusterSpec({" + ", ".join(string_items) + "})"
|
||||
|
||||
def as_dict(self):
|
||||
"""Returns a dictionary from job names to their tasks.
|
||||
|
||||
|
@ -421,6 +421,17 @@ class ServerDefTest(test.TestCase):
|
||||
|
||||
class ClusterSpecTest(test.TestCase):
|
||||
|
||||
def testStringConversion(self):
|
||||
cluster_spec = server_lib.ClusterSpec({
|
||||
"ps": ["ps0:1111"],
|
||||
"worker": ["worker0:3333", "worker1:4444"]
|
||||
})
|
||||
|
||||
expected_str = (
|
||||
"ClusterSpec({'ps': ['ps0:1111'], 'worker': ['worker0:3333', "
|
||||
"'worker1:4444']})")
|
||||
self.assertEqual(expected_str, str(cluster_spec))
|
||||
|
||||
def testProtoDictDefEquivalences(self):
|
||||
cluster_spec = server_lib.ClusterSpec({
|
||||
"ps": ["ps0:2222", "ps1:2222"],
|
||||
|
Loading…
Reference in New Issue
Block a user