[PATCH] [LIT] Add JSONMetricValue type to wrap types supported by the json encoder.

Eric Fiselier eric at efcs.ca
Fri Dec 19 14:27:17 PST 2014


Remove poorly named function. It's unneeded.


http://reviews.llvm.org/D6576

Files:
  utils/lit/lit/Test.py

Index: utils/lit/lit/Test.py
===================================================================
--- utils/lit/lit/Test.py
+++ utils/lit/lit/Test.py
@@ -1,5 +1,6 @@
 import os
 from xml.sax.saxutils import escape
+from json import JSONEncoder
 
 # Test result codes.
 
@@ -73,6 +74,41 @@
     def todata(self):
         return self.value
 
+class JSONMetricValue(MetricValue):
+    """
+        JSONMetricValue is used for types that are representable in the output
+        but that are otherwise uninterpreted.
+    """
+    def __init__(self, value):
+        # Ensure the value is a serializable by trying to encode it.
+        # WARNING: The value may change before it is encoded again, and may
+        #          not be encodable after the change.
+        try:
+            e = JSONEncoder()
+            e.encode(value)
+        except TypeError:
+            raise
+        self.value = value
+
+    def format(self):
+        return str(self.value)
+
+    def todata(self):
+        return self.value
+
+def toMetricValue(value):
+    if isinstance(value, MetricValue):
+        return value
+    elif isinstance(value, int) or isinstance(value, long):
+        return IntMetricValue(value)
+    elif isinstance(value, float):
+        return RealMetricValue(value)
+    else:
+        # Try to create a JSONMetricValue and let the constructor throw
+        # if value is not a valid type.
+        return JSONMetricValue(value)
+
+
 # Test results.
 
 class Result(object):

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6576.17520.patch
Type: text/x-patch
Size: 1488 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141219/7ca17503/attachment.bin>


More information about the llvm-commits mailing list