diff --git a/gclient.py b/gclient.py index f568662ba..c038738c1 100644 --- a/gclient.py +++ b/gclient.py @@ -585,11 +585,15 @@ class Dependency(GClientKeywords, gclient_utils.WorkItem): def __str__(self): out = [] for i in ('name', 'url', 'parsed_url', 'safesync_url', 'custom_deps', - 'custom_vars', 'deps_hooks', '_file_list', 'should_process', + 'custom_vars', 'deps_hooks', 'file_list', 'should_process', 'processed', 'hooks_ran', 'deps_parsed', 'requirements'): - # 'deps_file' - if self.__dict__[i]: - out.append('%s: %s' % (i, self.__dict__[i])) + # First try the native property if it exists. + if hasattr(self, '_' + i): + value = getattr(self, '_' + i, False) + else: + value = getattr(self, i, False) + if value: + out.append('%s: %s' % (i, value)) for d in self.dependencies: out.extend([' ' + x for x in str(d).splitlines()]) diff --git a/tests/gclient_test.py b/tests/gclient_test.py index 0a5da250f..86aa89384 100755 --- a/tests/gclient_test.py +++ b/tests/gclient_test.py @@ -203,6 +203,34 @@ class GclientTest(trial_dir.TestCase): None, '', True) self.assertEquals('proto://host/path@revision', d.url) + def testStr(self): + # Make sure __str__() works fine. + # pylint: disable=W0212 + parser = gclient.Parser() + options, _ = parser.parse_args([]) + obj = gclient.GClient('foo', options) + obj.dependencies.append( + gclient.Dependency(obj, 'foo', 'url', None, None, None, 'DEPS', True)) + obj.dependencies.append( + gclient.Dependency(obj, 'bar', 'url', None, None, None, 'DEPS', True)) + obj.dependencies[0].dependencies.append( + gclient.Dependency( + obj.dependencies[0], 'foo/dir1', 'url', None, None, None, 'DEPS', + True)) + obj.dependencies[0].dependencies.append( + gclient.Dependency( + obj.dependencies[0], 'foo/dir2', + gclient.GClientKeywords.FromImpl('bar'), None, None, None, 'DEPS', + True)) + obj.dependencies[0].dependencies.append( + gclient.Dependency( + obj.dependencies[0], 'foo/dir3', + gclient.GClientKeywords.FileImpl('url'), None, None, None, 'DEPS', + True)) + obj.dependencies[0]._file_list.append('foo') + self.assertEquals(434, len(str(obj)), '%d\n%s' % (len(str(obj)), str(obj))) + + if __name__ == '__main__': logging.basicConfig( level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][