1# Copyright 2014 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5 6# TODO(1262303): After Telemetry is supported by python3 we can remove 7# object inheritance from this script. 8# pylint: disable=useless-object-inheritance 9class Environment(object): 10 """An environment in which tests can be run. 11 12 This is expected to handle all logic that is applicable to an entire specific 13 environment but is independent of the test type. 14 15 Examples include: 16 - The local device environment, for running tests on devices attached to 17 the local machine. 18 - The local machine environment, for running tests directly on the local 19 machine. 20 """ 21 22 def __init__(self, output_manager): 23 """Environment constructor. 24 25 Args: 26 output_manager: Instance of |output_manager.OutputManager| used to 27 save test output. 28 """ 29 self._output_manager = output_manager 30 31 # Some subclasses have different teardown behavior on receiving SIGTERM. 32 self._received_sigterm = False 33 34 def SetUp(self): 35 raise NotImplementedError 36 37 def TearDown(self): 38 raise NotImplementedError 39 40 def __enter__(self): 41 self.SetUp() 42 return self 43 44 def __exit__(self, _exc_type, _exc_val, _exc_tb): 45 self.TearDown() 46 47 @property 48 def output_manager(self): 49 return self._output_manager 50 51 def ReceivedSigterm(self): 52 self._received_sigterm = True 53