summaryrefslogtreecommitdiff
path: root/morphlib/execute_tests.py
blob: 721d0807fb8a821c19889ff56c81abe3db4212c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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'])