| #!/usr/bin/python |
| # Copyright (c) 2010 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. |
| |
| '''Unittest wrapper for chromeos_interface.py.''' |
| |
| import subprocess |
| import unittest |
| |
| import chromeos_interface |
| |
| CHROS_IF = chromeos_interface.ChromeOSInterface(True) |
| |
| class TestShellCommands(unittest.TestCase): |
| |
| TEST_CMD = 'ls /etc' |
| |
| def setUp(self): |
| '''Cache text expected to be generated by the command.''' |
| self.expected_text = subprocess.Popen( |
| self.TEST_CMD, shell=True, |
| stdout=subprocess.PIPE).stdout.read().strip() |
| |
| def test_run_shell_command(self): |
| '''Verify that the process provides correct stdout.''' |
| proc = CHROS_IF.run_shell_command(self.TEST_CMD) |
| self.assertEqual(proc.stdout.read().strip(), self.expected_text) |
| |
| def test_run_run_command_get_output(self): |
| '''Verify that the command generates correct output.''' |
| live_text = CHROS_IF.run_shell_command_get_output(self.TEST_CMD) |
| self.assertEqual(live_text, self.expected_text.split('\n')) |
| |
| def test_boot_state_vector(self): |
| '''Verify the format (not the contents) of the boot vector.''' |
| bv = CHROS_IF.boot_state_vector() |
| self.assertEqual(bv.count(':'), 4) |
| self.assertEqual(len(bv), 9) |
| |
| |
| if __name__ == '__main__': |
| unittest.main() |