112882Sspwilson2@wisc.edu# Copyright (c) 2017 Mark D. Hill and David A. Wood 212882Sspwilson2@wisc.edu# All rights reserved. 312882Sspwilson2@wisc.edu# 412882Sspwilson2@wisc.edu# Redistribution and use in source and binary forms, with or without 512882Sspwilson2@wisc.edu# modification, are permitted provided that the following conditions are 612882Sspwilson2@wisc.edu# met: redistributions of source code must retain the above copyright 712882Sspwilson2@wisc.edu# notice, this list of conditions and the following disclaimer; 812882Sspwilson2@wisc.edu# redistributions in binary form must reproduce the above copyright 912882Sspwilson2@wisc.edu# notice, this list of conditions and the following disclaimer in the 1012882Sspwilson2@wisc.edu# documentation and/or other materials provided with the distribution; 1112882Sspwilson2@wisc.edu# neither the name of the copyright holders nor the names of its 1212882Sspwilson2@wisc.edu# contributors may be used to endorse or promote products derived from 1312882Sspwilson2@wisc.edu# this software without specific prior written permission. 1412882Sspwilson2@wisc.edu# 1512882Sspwilson2@wisc.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612882Sspwilson2@wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712882Sspwilson2@wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812882Sspwilson2@wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912882Sspwilson2@wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012882Sspwilson2@wisc.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112882Sspwilson2@wisc.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212882Sspwilson2@wisc.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312882Sspwilson2@wisc.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412882Sspwilson2@wisc.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512882Sspwilson2@wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612882Sspwilson2@wisc.edu# 2712882Sspwilson2@wisc.edu# Authors: Sean Wilson 2812882Sspwilson2@wisc.edu 2912882Sspwilson2@wisc.eduimport os 3012882Sspwilson2@wisc.eduimport itertools 3112882Sspwilson2@wisc.edu 3212882Sspwilson2@wisc.eduimport config 3312882Sspwilson2@wisc.edu 3412882Sspwilson2@wisc.educlass UID(object): 3512882Sspwilson2@wisc.edu sep = ':' 3612882Sspwilson2@wisc.edu type_idx, path_idx = range(2) 3712882Sspwilson2@wisc.edu 3812882Sspwilson2@wisc.edu def __init__(self, path, *args): 3912882Sspwilson2@wisc.edu self.path = self._shorten_path(path) 4012882Sspwilson2@wisc.edu self.attributes = args 4112882Sspwilson2@wisc.edu 4212882Sspwilson2@wisc.edu @staticmethod 4312882Sspwilson2@wisc.edu def _shorten_path(path): 4412882Sspwilson2@wisc.edu return os.path.relpath(path, 4512882Sspwilson2@wisc.edu os.path.commonprefix((config.constants.testing_base, 4612882Sspwilson2@wisc.edu path))) 4712882Sspwilson2@wisc.edu 4812882Sspwilson2@wisc.edu @staticmethod 4912882Sspwilson2@wisc.edu def _full_path(short_path): 5012882Sspwilson2@wisc.edu return os.path.join(config.constants.testing_base, short_path) 5112882Sspwilson2@wisc.edu 5212882Sspwilson2@wisc.edu @classmethod 5312882Sspwilson2@wisc.edu def uid_to_path(cls, uid): 5412882Sspwilson2@wisc.edu split_path = str(uid).split(cls.sep)[cls.path_idx] 5512882Sspwilson2@wisc.edu return cls._full_path(split_path) 5612882Sspwilson2@wisc.edu 5712882Sspwilson2@wisc.edu @classmethod 5812882Sspwilson2@wisc.edu def uid_to_class(cls, uid): 5912882Sspwilson2@wisc.edu return globals()[uid.split(cls.sep)[cls.type_idx]] 6012882Sspwilson2@wisc.edu 6112882Sspwilson2@wisc.edu @classmethod 6212882Sspwilson2@wisc.edu def from_suite(self, suite, filepath): 6312882Sspwilson2@wisc.edu return SuiteUID(filepath, suite.name) 6412882Sspwilson2@wisc.edu 6512882Sspwilson2@wisc.edu @classmethod 6612882Sspwilson2@wisc.edu def from_test(self, test, filepath): 6712882Sspwilson2@wisc.edu return TestUID(filepath, test.name, test.parent_suite.name) 6812882Sspwilson2@wisc.edu 6912882Sspwilson2@wisc.edu @classmethod 7012882Sspwilson2@wisc.edu def from_uid(cls, uid): 7112882Sspwilson2@wisc.edu args = uid.split(cls.sep) 7212882Sspwilson2@wisc.edu del args[cls.type_idx] 7312882Sspwilson2@wisc.edu return cls.uid_to_class(uid)(*args) 7412882Sspwilson2@wisc.edu 7512882Sspwilson2@wisc.edu def __str__(self): 7612882Sspwilson2@wisc.edu common_opts = { 7712882Sspwilson2@wisc.edu self.path_idx: self.path, 7812882Sspwilson2@wisc.edu self.type_idx: self.__class__.__name__ 7912882Sspwilson2@wisc.edu } 8012882Sspwilson2@wisc.edu return self.sep.join(itertools.chain( 8112882Sspwilson2@wisc.edu [common_opts[0], common_opts[1]], 8212882Sspwilson2@wisc.edu self.attributes)) 8312882Sspwilson2@wisc.edu 8412882Sspwilson2@wisc.edu def __hash__(self): 8512882Sspwilson2@wisc.edu return hash(str(self)) 8612882Sspwilson2@wisc.edu 8712882Sspwilson2@wisc.edu def __eq__(self, other): 8812882Sspwilson2@wisc.edu return type(self) == type(other) and str(self) == str(other) 8912882Sspwilson2@wisc.edu 9012882Sspwilson2@wisc.edu 9112882Sspwilson2@wisc.educlass TestUID(UID): 9212882Sspwilson2@wisc.edu def __init__(self, filename, test_name, suite_name): 9312882Sspwilson2@wisc.edu UID.__init__(self, filename, suite_name, test_name) 9412882Sspwilson2@wisc.edu 9512882Sspwilson2@wisc.edu @property 9612882Sspwilson2@wisc.edu def test(self): 9712882Sspwilson2@wisc.edu return self.attributes[1] 9812882Sspwilson2@wisc.edu 9912882Sspwilson2@wisc.edu @property 10012882Sspwilson2@wisc.edu def suite(self): 10112882Sspwilson2@wisc.edu return self.attributes[0] 10212882Sspwilson2@wisc.edu 10312882Sspwilson2@wisc.edu 10412882Sspwilson2@wisc.educlass SuiteUID(UID): 10512882Sspwilson2@wisc.edu def __init__(self, filename, suite_name): 10612882Sspwilson2@wisc.edu UID.__init__(self, filename, suite_name) 10712882Sspwilson2@wisc.edu 10812882Sspwilson2@wisc.edu @property 10912882Sspwilson2@wisc.edu def suite(self): 11012882Sspwilson2@wisc.edu return self.attributes[0] 111