Telemetry Pages support AsDict()

We will be using the AsDict() call to support JSON output of Telemetry results.
This CL adds the ability to output the important information associated with a
page to the Telemetry Page class.

BUG=375541

Review URL: https://codereview.chromium.org/388653002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282776 0039d316-1c4b-4281-b951-d872f2087c98
parent 539d6202
......@@ -57,6 +57,16 @@ class Page(object):
assert browser_info
return True
def AsDict(self):
"""Converts a page object to a dict suitable for JSON output."""
d = {
'id': self._id,
'url': self._url,
}
if self._name:
d['name'] = self._name
return d
@property
def page_set(self):
return self._page_set
......
......@@ -117,6 +117,23 @@ class TestPage(unittest.TestCase):
self.assertEquals(ps[0].display_name, 'foo')
def testPagesHaveDifferentIds(self):
p = page.Page("http://example.com")
p2 = page.Page("http://example.com")
self.assertNotEqual(p.id, p2.id)
p0 = page.Page("http://example.com")
p1 = page.Page("http://example.com")
self.assertNotEqual(p0.id, p1.id)
def testNamelessPageAsDict(self):
nameless_dict = page.Page('http://example.com/').AsDict()
self.assertIn('id', nameless_dict)
del nameless_dict['id']
self.assertEquals({
'url': 'http://example.com/',
}, nameless_dict)
def testNamedPageAsDict(self):
named_dict = page.Page('http://example.com/', name='Example').AsDict()
self.assertIn('id', named_dict)
del named_dict['id']
self.assertEquals({
'url': 'http://example.com/',
'name': 'Example'
}, named_dict)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment