diff options
Diffstat (limited to 'morphlib/execute_tests.py')
-rw-r--r-- | morphlib/execute_tests.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/morphlib/execute_tests.py b/morphlib/execute_tests.py new file mode 100644 index 00000000..721d0807 --- /dev/null +++ b/morphlib/execute_tests.py @@ -0,0 +1,51 @@ +# Copyright (C) 2011 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +import os +import unittest + +import morphlib + + +class ExecuteTests(unittest.TestCase): + + def setUp(self): + self.e = morphlib.execute.Execute('/') + + def test_has_same_path_as_environment(self): + self.assertEqual(self.e.env['PATH'], os.environ['PATH']) + + def test_executes_true_ok(self): + self.assertEqual(self.e.run(['true']), ['']) + + def test_raises_commandfailure_for_false(self): + self.assertRaises(morphlib.execute.CommandFailure, + self.e.run, ['false']) + + def test_returns_stdout_from_all_commands(self): + self.assertEqual(self.e.run(['echo foo', 'echo bar']), + ['foo\n', 'bar\n']) + + def test_sets_working_directory(self): + self.assertEqual(self.e.run(['pwd']), ['/\n']) + + def test_executes_argv(self): + self.assertEqual(self.e.runv(['echo', 'foo']), 'foo\n') + + def test_raises_error_when_argv_fails(self): + self.assertRaises(morphlib.execute.CommandFailure, + self.e.runv, ['false']) + |