Beispiel #1
0
from openhtf.exe import phase_executor
from openhtf.exe import triggers
from openhtf.io import http_api
from openhtf.io import test_record
from openhtf.io import user_input
from openhtf.util import functions
from openhtf.util import logs
from openhtf.util import measurements

# All tests require a station_id.  This can be via the --config-file
# automatically loaded by OpenHTF, provided explicitly to the config with
# conf.Load(station_id='My_OpenHTF_Station'), or alongside other configs loaded
# with conf.LoadFromDict({..., 'station_id': 'My_Station'}).  If none of those
# are provided then we'll fall back to the machine's hostname.
conf.Declare('station_id',
             'The name of this test station',
             default_value=socket.gethostname())

__version__ = util.get_version()
_LOG = logging.getLogger(__name__)


class InvalidTestPhaseError(Exception):
    """Raised when an invalid method is decorated."""


class Test(object):
    """An object that represents an OpenHTF test.

  Example:
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Example plug for OpenHTF."""

import logging
import time

import openhtf.conf as conf
import openhtf.plugs as plugs

conf.Declare('example_plug_increment',
             default_value=1,
             description='Increment constant for example plug.')


class ExamplePlug(plugs.BasePlug):  # pylint: disable=no-init
    """Example of a simple plug.

  This plug simply keeps a value and increments it each time Increment() is
  called.  You'll notice a few paradigms here:

    - @conf.InjectPositionalArgs
      This is generally a good way to pass in any configuration that your
      plug needs, such as an IP address or serial port to connect to.  If
      You want to use your plug outside of the OpenHTF framework, you can
      still manually instantiate it, but you must pass the arguments by
      keyword (as a side effect of the way InjectPositionalArgs is
Beispiel #3
0
 def testInvalidKey(self):
     with self.assertRaises(conf.InvalidKeyError):
         conf.Declare('_invalid')
     with self.assertRaises(conf.InvalidKeyError):
         conf.Declare('Invalid')
Beispiel #4
0
 def testMultipleDeclaration(self):
     conf.Declare('multiple')
     with self.assertRaises(conf.KeyAlreadyDeclaredError):
         conf.Declare('multiple')
Beispiel #5
0
_old_argv = list(sys.argv)
sys.argv.extend([
    '--config-value=flag_key=flag_value',
    '--config-value',
    'other_flag=other_value',
    # You can specify arbitrary keys, but they'll get ignored if they aren't
    # actually declared anywhere (included here to make sure of that).
    '--config_value=undeclared_flag=who_cares',
])

import os.path
import unittest

from openhtf import conf

conf.Declare('flag_key')
conf.Declare('other_flag')
conf.Declare('json_test_key')
conf.Declare('yaml_test_key')
conf.Declare('overridden_key')
conf.Declare('none_default', default_value=None)
conf.Declare('string_default', default_value='default')
conf.Declare('no_default')


def tearDownModule():
    sys.argv = _old_argv


class TestConf(unittest.TestCase):
Beispiel #6
0
"""
import commands
import logging
import time

import openhtf.plugs as plugs
from openhtf import conf
from openhtf.plugs.usb import adb_device
from openhtf.plugs.usb import fastboot_device
from openhtf.plugs.usb import local_usb
from openhtf.plugs.usb import usb_exceptions
from openhtf.plugs import cambrionix

_LOG = logging.getLogger(__name__)

conf.Declare('libusb_rsa_key', 'A private key file for use by libusb auth.')
conf.Declare('remote_usb', 'ethersync or other')
conf.Declare('ethersync', 'ethersync configuration')

def _open_usb_handle(**kwargs):
  """Open a UsbHandle subclass, based on configuration.

  If configuration 'remote_usb' is set, use it to connect to remote usb,
  otherwise attempt to connect locally.'remote_usb' is set to usb type,
  EtherSync or other.

  Example of Cambrionix unit in config:
  remote_usb: ethersync
  ethersync:
       mac_addr: 78:a5:04:ca:91:66
       plug_port: 5
Beispiel #7
0
To use these plugs:
  from openhtf import plugs
  from openhtf.plugs import usb

  @plugs.RequiresPlug(adb=usb.AdbPlug)
  def MyPhase(test, adb):
    adb.Shell('ls')
"""

import openhtf.plugs as plugs
from openhtf import conf
from openhtf.plugs.usb import adb_device
from openhtf.plugs.usb import fastboot_device
from openhtf.plugs.usb import local_usb

conf.Declare('usb_server', 'USB Server IP/Hostname')
conf.Declare('usb_server_port', 'USB Server Port', default_value=10000)

conf.Declare('libusb_rsa_key', 'A private key file for use by libusb auth.')


def _open_usb_handle(**kwargs):
    """Open a UsbHandle subclass, based on configuration.

  If configuration 'usb_server' is set, use it to connect to remote usb,
  otherwise attempt to connect locally.

  Args:
    **kwargs: Arguments to pass to respective handle's Open() method.

  Returns: