def testParserSetsBuildDir(self):
   """Verify that the build directory is set when not specified."""
   test_dir = self.TempFilePath('out_amd64-generic/Release/crypto_unittests')
   # Retrieves the build directory from the parsed options.
   build_dir = cros_test.ParseCommandLine(
       ['--chrome-test', '--', test_dir]).build_dir
   self.assertEqual(build_dir, os.path.dirname(test_dir))
 def setUp(self):
   """Common set up method for all tests."""
   opts = cros_test.ParseCommandLine([])
   self._tester = cros_test.CrOSTest(opts)
   self._tester._device.board = 'amd64-generic'
   self._tester._device.image_path = self.TempFilePath(
       'chromiumos_qemu_image.bin')
   osutils.Touch(self._tester._device.image_path)
   version_str = ('QEMU emulator version 2.6.0, Copyright (c) '
                  '2003-2008 Fabrice Bellard')
   self.rc.AddCmdResult(partial_mock.In('--version'), output=version_str)
   self.ssh_port = self._tester._device.ssh_port
  def CheckParserError(self, args, error_msg):
    """Checks that parser error is raised.

    Args:
      args: List of commandline arguments.
      error_msg: Error message to check for.
    """
    # Recreate args as a list if it is given as a string.
    if isinstance(args, str):
      args = [args]
    # Putting outcap.OutputCapturer() before assertRaises(SystemExit)
    # swallows SystemExit exception check.
    with self.assertRaises(SystemExit):
      with outcap.OutputCapturer() as output:
        cros_test.ParseCommandLine(args)
    self.assertIn(error_msg, output.GetStderr())
Esempio n. 4
0
  def createTester(self, opts=None):
    """Builds a CrOSTest suitable for testing.

    Args:
      opts: Cmd-line args to cros_test used to build a CrOSTest.

    Returns:
      An instance of cros_test.CrOSTest.
    """
    opts = cros_test.ParseCommandLine(opts if opts else [])
    opts.enable_kvm = True
    # We check if /dev/kvm is writeable to use sudo.
    with mock.patch.object(os, 'access', return_value=True):
      tester = cros_test.CrOSTest(opts)
    tester._device.use_sudo = False
    tester._device.board = 'amd64-generic'
    tester._device.image_path = self.TempFilePath(
        'chromiumos_qemu_image.bin')
    osutils.Touch(tester._device.image_path)
    version_str = ('QEMU emulator version 2.6.0, Copyright (c) '
                   '2003-2008 Fabrice Bellard')
    self.rc.AddCmdResult(partial_mock.In('--version'), output=version_str)
    return tester
def main(argv):
  opts = cros_test.ParseCommandLine(argv)
  opts.Freeze()
  return cros_test.CrOSTest(opts).Run()