def testAsDict(self): conf.Load(station_id='station_id') self.assertEquals( { 'station_id': 'station_id', 'string_default': 'default', 'none_default': None, 'flag_key': 'flag_value', 'other_flag': 'other_value', }, conf._asdict())
def setUpClass(cls): conf.Load(station_id='measurements_test') with open(_LocalFilename('measurements_record.pickle'), 'rb') as picklefile: cls.record = pickle.load(picklefile)
class Test(object): """An object that represents an OpenHTF test. This object encapsulates the static test state including an ordered tuple of phases to execute. Args: *phases: The ordered list of phases to execute for this test. """ def __init__(self, *phases): """Creates a new Test to be executed. Args: *phases: The ordered list of phases to execute for this test. """ self.loop = False self.phases = [TestPhaseInfo.WrapOrReturn(phase) for phase in phases] self.output_callbacks = [] # Pull some metadata from the frame in which this Test was created. frame_record = inspect.stack()[1] self.filename = os.path.basename(frame_record[1]) self.docstring = inspect.getdoc(inspect.getmodule(frame_record[0])) self.code = inspect.getsource(frame_record[0]) @property def plug_type_map(self): """Returns dict mapping name to plug type for all phases.""" plug_type_map = {} for plug, plug_type in itertools.chain.from_iterable( ((plug.name, plug.cls) for plug in phase.plugs) for phase in self.phases): if (plug in plug_type_map and plug_type is not plug_type_map[plug]): raise plugs.DuplicatePlugError( 'Duplicate plug with different type: %s' % plug) plug_type_map[plug] = plug_type return plug_type_map def AddOutputCallback(self, callback): """Add the given function as an output module to this test.""" self.output_callbacks.append(callback) def OutputTestRecord(self, test_record): """Feed the record of this test to all output modules.""" for output_cb in self.output_callbacks: output_cb(test_record) def Execute(self, loop=None, test_start=triggers.AutoStart, test_stop=triggers.AutoStop): """Start the OpenHTF framework running with the given test. Executes this test, iterating over self.phases and executing them. Example: def PhaseOne(test): # Integrate more widgets def PhaseTwo(test): # Analyze widget integration status Test(PhaseOne, PhaseTwo).Execute() Returns: None when the test framework has exited. """ try: FLAGS(sys.argv) # parse flags except gflags.FlagsError, e: # pylint: disable=invalid-name print '%s\nUsage: %s ARGS\n%s' % (e, sys.argv[0], FLAGS) sys.exit(1) logs.setup_logger() if loop is not None: self.loop = loop conf.Load() config = conf.Config() rundata.RunData(config.station_id, self.filename, socket.gethostname(), FLAGS.http_port, os.getpid()).SaveToFile(FLAGS.rundir) _LOG.info('Executing test: %s', self.filename) executor = exe.TestExecutor(config, self, test_start, test_stop) server = http_api.Server(executor) def sigint_handler(*dummy): """Handle SIGINT by stopping running executor and handler.""" print "Received SIGINT. Stopping everything." executor.Stop() server.Stop() signal.signal(signal.SIGINT, sigint_handler) server.Start() executor.Start() executor.Wait() server.Stop() return
def setUp(self): self.test_plug = UnittestPlug() conf.Load(target_name='unittest_openhtf', test_start='frontend_serial')
def testFlagValues(self): self.assertEquals('flag_value', conf.flag_key) self.assertEquals('other_value', conf.other_flag) # Make sure flag value takes precedence, even if a value is loaded. conf.Load(flag_key='loaded_value') self.assertEquals('flag_value', conf.flag_key)
def testLoadNoOverride(self): conf.Load(overridden_key='overridden_value') conf.Load(overridden_key='new_value', _override=False) self.assertEquals('overridden_value', conf.overridden_key)
def ModifiesConf(): conf.Load(string_default='modified') self.assertEquals('modified', conf.string_default)