blob: f723e0a0bf9e03267963a7c69b5889fe7fcdda12 [file] [log] [blame]
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unittests for generate_delta_sysroot."""
from __future__ import print_function
import os
from chromite.lib import cros_build_lib
from chromite.lib import cros_test_lib
from chromite.scripts import generate_delta_sysroot as gds
# pylint: disable=W0212
def _Parse(argv):
return gds._ParseCommandLine(argv)
class InterfaceTest(cros_test_lib.OutputTestCase,
"""Test the commandline interface of the script"""
def testNoBoard(self):
"""Test no board specified."""
argv = ['--out-dir', '/path/to/nowhere']
def testNoOutDir(self):
"""Test no out dir specified."""
argv = ['--board', 'link']
def testCorrectArgv(self):
"""Test successful parsing"""
argv = ['--board', 'link', '--out-dir', self.tempdir]
options = _Parse(argv)
def testTestsSet(self):
"""Test successful parsing"""
argv = ['--board', 'link', '--out-dir', self.tempdir]
options = _Parse(argv)
def testNoTestsSet(self):
"""Test successful parsing"""
argv = ['--board', 'link', '--out-dir', self.tempdir, '--skip-tests']
options = _Parse(argv)
def assertParseError(self, argv):
"""Helper to assert parsing error, given argv."""
with self.OutputCapturer():
self.assertRaises2(SystemExit, _Parse, argv)
class TestCreateBatchFile(cros_test_lib.TempDirTestCase):
"""Test the batch file creation."""
def testSourceDirDoesNotExist(self):
"""Test error is raised if there is no source directory."""
no_source = os.path.join(self.tempdir, 'foo/bar/cow')
cros_build_lib.RunCommandError, gds.CreateBatchFile,
no_source, self.tempdir, os.path.join(self.tempdir, 'batch'))