Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: tools/telemetry/telemetry/value/value_unittest.py

Issue 417193005: Add Value FromDict to Telemetry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Nat's comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/telemetry/telemetry/value/string_unittest.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/value/value_unittest.py
diff --git a/tools/telemetry/telemetry/value/value_unittest.py b/tools/telemetry/telemetry/value/value_unittest.py
index a7ea0a116b52f099c7411fd905e2fab9f2fc7b8d..84cbd1281a860a384caeb242b2eddaa4b6b75b83 100644
--- a/tools/telemetry/telemetry/value/value_unittest.py
+++ b/tools/telemetry/telemetry/value/value_unittest.py
@@ -44,15 +44,25 @@ class ValueForTest(value.Value):
def GetRepresentativeString(self):
pass
- @classmethod
- def GetJSONTypeName(cls):
+ @staticmethod
+ def GetJSONTypeName():
pass
class ValueForAsDictTest(ValueForTest):
- @classmethod
- def GetJSONTypeName(cls):
+ @staticmethod
+ def GetJSONTypeName():
return 'baz'
+class ValueForFromDictTest(ValueForTest):
+ @staticmethod
+ def FromDict(value_dict, page_dict):
+ kwargs = value.Value.GetConstructorKwArgs(value_dict, page_dict)
+ return ValueForFromDictTest(**kwargs)
+
+ @staticmethod
+ def GetJSONTypeName():
+ return 'value_for_from_dict_test'
+
class ValueTest(TestBase):
def testCompat(self):
page0 = self.pages[0]
@@ -85,7 +95,7 @@ class ValueTest(TestBase):
self.assertEquals(d, {
'name': 'x',
'type': 'baz',
- 'unit': 'unit',
+ 'units': 'unit',
})
def testAsDictWithPage(self):
@@ -112,3 +122,77 @@ class ValueTest(TestBase):
def testAsDictWithoutDescription(self):
v = ValueForAsDictTest(None, 'x', 'unit', important=False, description=None)
self.assertNotIn('description', v.AsDict())
+
+ def testFromDictBaseKeys(self):
+ d = {
+ 'type': 'value_for_from_dict_test',
+ 'name': 'x',
+ 'units': 'unit'
+ }
+
+ v = value.Value.FromDict(d, None)
+ self.assertEquals(v.name, 'x')
+ self.assertTrue(isinstance(v, ValueForFromDictTest))
+ self.assertEquals(v.units, 'unit')
+
+ def testFromDictWithPage(self):
+ page0 = self.pages[0]
+ page_dict = {page0.id: page0}
+
+ d = {
+ 'type': 'value_for_from_dict_test',
+ 'name': 'x',
+ 'units': 'unit',
+ 'page_id': page0.id
+ }
+
+ v = value.Value.FromDict(d, page_dict)
+
+ self.assertEquals(v.page.id, page0.id)
+
+ def testFromDictWithoutPage(self):
+ d = {
+ 'type': 'value_for_from_dict_test',
+ 'name': 'x',
+ 'units': 'unit'
+ }
+
+ v = value.Value.FromDict(d, {})
+
+ self.assertEquals(v.page, None)
+
+ def testFromDictWithDescription(self):
+ d = {
+ 'type': 'value_for_from_dict_test',
+ 'name': 'x',
+ 'units': 'unit',
+ 'description': 'foo'
+ }
+
+ v = value.Value.FromDict(d, {})
+ self.assertEquals(v.description, 'foo')
+
+ def testFromDictWithoutDescription(self):
+ d = {
+ 'type': 'value_for_from_dict_test',
+ 'name': 'x',
+ 'units': 'unit'
+ }
+
+ v = value.Value.FromDict(d, {})
+ self.assertEquals(v.description, None)
+
+ def testListOfValuesFromListOfDicts(self):
+ d0 = {
+ 'type': 'value_for_from_dict_test',
+ 'name': 'x',
+ 'units': 'unit'
+ }
+ d1 = {
+ 'type': 'value_for_from_dict_test',
+ 'name': 'y',
+ 'units': 'unit'
+ }
+ vs = value.Value.ListOfValuesFromListOfDicts([d0, d1], {})
+ self.assertEquals(vs[0].name, 'x')
+ self.assertEquals(vs[1].name, 'y')
« no previous file with comments | « tools/telemetry/telemetry/value/string_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698