2 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Unittests for generate_delta_sysroot."""
11 sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)),
14 from chromite.lib import cros_build_lib
15 from chromite.lib import cros_test_lib
16 from chromite.scripts import generate_delta_sysroot as gds
19 # pylint: disable=W0212
21 return gds._ParseCommandLine(argv)
24 class InterfaceTest(cros_test_lib.OutputTestCase,
25 cros_test_lib.TempDirTestCase):
26 """Test the commandline interface of the script"""
28 def testNoBoard(self):
29 """Test no board specified."""
30 argv = ['--out-dir', '/path/to/nowhere']
31 self.assertParseError(argv)
33 def testNoOutDir(self):
34 """Test no out dir specified."""
35 argv = ['--board', 'link']
36 self.assertParseError(argv)
38 def testCorrectArgv(self):
39 """Test successful parsing"""
40 argv = ['--board', 'link', '--out-dir', self.tempdir]
41 options = _Parse(argv)
42 gds.FinishParsing(options)
44 def testTestsSet(self):
45 """Test successful parsing"""
46 argv = ['--board', 'link', '--out-dir', self.tempdir]
47 options = _Parse(argv)
48 self.assertTrue(options.build_tests)
50 def testNoTestsSet(self):
51 """Test successful parsing"""
52 argv = ['--board', 'link', '--out-dir', self.tempdir, '--skip-tests']
53 options = _Parse(argv)
54 self.assertFalse(options.build_tests)
56 def assertParseError(self, argv):
57 """Helper to assert parsing error, given argv."""
58 with self.OutputCapturer():
59 self.assertRaises2(SystemExit, _Parse, argv)
62 class TestCreateBatchFile(cros_test_lib.TempDirTestCase):
63 """Test the batch file creation."""
65 def testSourceDirDoesNotExist(self):
66 """Test error is raised if there is no source directory."""
67 no_source = os.path.join(self.tempdir, 'foo/bar/cow')
69 self.assertRaises2(cros_build_lib.RunCommandError, gds.CreateBatchFile,
70 no_source, self.tempdir, os.path.join(self.tempdir,'batch'))
73 if __name__ == '__main__':