fixture.py (13851:a71317af0ac2) | fixture.py (14140:1e197b8006e2) |
---|---|
1# Copyright (c) 2019 ARM Limited 2# All rights reserved 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license 9# terms below provided that you ensure that this notice is replicated 10# unmodified and in its entirety in all distributions of the software, 11# modified or unmodified, in source code or in binary form. 12# |
|
1# Copyright (c) 2017 Mark D. Hill and David A. Wood 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 15 unchanged lines hidden (view full) --- 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# Authors: Sean Wilson 28 29import os 30import tempfile 31import shutil | 13# Copyright (c) 2017 Mark D. Hill and David A. Wood 14# All rights reserved. 15# 16# Redistribution and use in source and binary forms, with or without 17# modification, are permitted provided that the following conditions are 18# met: redistributions of source code must retain the above copyright 19# notice, this list of conditions and the following disclaimer; 20# redistributions in binary form must reproduce the above copyright --- 15 unchanged lines hidden (view full) --- 36# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38# 39# Authors: Sean Wilson 40 41import os 42import tempfile 43import shutil |
44import threading |
|
32 33from testlib.fixture import Fixture, globalfixture 34from testlib.config import config, constants 35from testlib.helper import log_call, cacheresult, joinpath, absdirpath 36import testlib.log as log 37 38 39class VariableFixture(Fixture): --- 14 unchanged lines hidden (view full) --- 54 def teardown(self, testitem): 55 if self.path is not None: 56 shutil.rmtree(self.path) 57 58 def skip_cleanup(self): 59 # Set path to none so it's not deleted 60 self.path = None 61 | 45 46from testlib.fixture import Fixture, globalfixture 47from testlib.config import config, constants 48from testlib.helper import log_call, cacheresult, joinpath, absdirpath 49import testlib.log as log 50 51 52class VariableFixture(Fixture): --- 14 unchanged lines hidden (view full) --- 67 def teardown(self, testitem): 68 if self.path is not None: 69 shutil.rmtree(self.path) 70 71 def skip_cleanup(self): 72 # Set path to none so it's not deleted 73 self.path = None 74 |
75class UniqueFixture(Fixture): 76 ''' 77 Base class for fixtures that generate a target in the 78 filesystem. If the same fixture is used by more than one 79 test/suite, rather than creating a copy of the fixture, it returns 80 the same object and makes sure that setup is only executed 81 once. Devired classses should override the _init and _setup 82 functions. |
|
62 | 83 |
84 :param target: The absolute path of the target in the filesystem. 85 86 ''' 87 fixtures = {} 88 89 def __new__(cls, target): 90 if target in cls.fixtures: 91 obj = cls.fixtures[target] 92 else: 93 obj = super(UniqueFixture, cls).__new__(cls) 94 obj.lock = threading.Lock() 95 obj.target = target 96 cls.fixtures[target] = obj 97 return obj 98 99 def __init__(self, *args, **kwargs): 100 with self.lock: 101 if hasattr(self, '_init_done'): 102 return 103 super(UniqueFixture, self).__init__(self, **kwargs) 104 self._init(*args, **kwargs) 105 self._init_done = True 106 107 def setup(self, testitem): 108 with self.lock: 109 if hasattr(self, '_setup_done'): 110 return 111 self._setup_done = True 112 self._setup(testitem) 113 114 |
|
63class SConsFixture(Fixture): 64 ''' 65 Fixture will wait until all SCons targets are collected and tests are 66 about to be ran, then will invocate a single instance of SCons for all 67 targets. 68 69 :param directory: The directory which scons will -C (cd) into before 70 executing. If None is provided, will choose the config base_dir. --- 225 unchanged lines hidden --- | 115class SConsFixture(Fixture): 116 ''' 117 Fixture will wait until all SCons targets are collected and tests are 118 about to be ran, then will invocate a single instance of SCons for all 119 targets. 120 121 :param directory: The directory which scons will -C (cd) into before 122 executing. If None is provided, will choose the config base_dir. --- 225 unchanged lines hidden --- |