Upstream version 8.36.161.0
[platform/framework/web/crosswalk.git] / src / third_party / chromite / scripts / generate_delta_sysroot_unittest.py
1 #!/usr/bin/python
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.
5
6 """Unittests for generate_delta_sysroot."""
7
8 import os
9 import sys
10
11 sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)),
12                                 '..', '..'))
13
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
17
18
19 # pylint: disable=W0212
20 def _Parse(argv):
21   return gds._ParseCommandLine(argv)
22
23
24 class InterfaceTest(cros_test_lib.OutputTestCase,
25                     cros_test_lib.TempDirTestCase):
26   """Test the commandline interface of the script"""
27
28   def testNoBoard(self):
29     """Test no board specified."""
30     argv = ['--out-dir', '/path/to/nowhere']
31     self.assertParseError(argv)
32
33   def testNoOutDir(self):
34     """Test no out dir specified."""
35     argv = ['--board', 'link']
36     self.assertParseError(argv)
37
38   def testCorrectArgv(self):
39     """Test successful parsing"""
40     argv = ['--board', 'link', '--out-dir', self.tempdir]
41     options =  _Parse(argv)
42     gds.FinishParsing(options)
43
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)
49
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)
55
56   def assertParseError(self, argv):
57     """Helper to assert parsing error, given argv."""
58     with self.OutputCapturer():
59       self.assertRaises2(SystemExit, _Parse, argv)
60
61
62 class TestCreateBatchFile(cros_test_lib.TempDirTestCase):
63   """Test the batch file creation."""
64
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')
68
69     self.assertRaises2(cros_build_lib.RunCommandError, gds.CreateBatchFile,
70         no_source, self.tempdir, os.path.join(self.tempdir,'batch'))
71
72
73 if __name__ == '__main__':
74   cros_test_lib.main()