[lit] Change lit.Test.ResultCode to be unique across pickling.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189549 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2013-08-29 00:48:39 +00:00
parent aee279dad5
commit 8253cc047d

View File

@ -5,6 +5,17 @@ import os
class ResultCode(object): class ResultCode(object):
"""Test result codes.""" """Test result codes."""
# We override __new__ and __getnewargs__ to ensure that pickling still
# provides unique ResultCode objects in any particular instance.
_instances = {}
def __new__(cls, name, isFailure):
res = cls._instances.get(name)
if res is None:
cls._instances[name] = res = super(ResultCode, cls).__new__(cls)
return res
def __getnewargs__(self):
return (self.name, self.isFailure)
def __init__(self, name, isFailure): def __init__(self, name, isFailure):
self.name = name self.name = name
self.isFailure = isFailure self.isFailure = isFailure