~ubuntu-branches/ubuntu/precise/landscape-client/precise-proposed

« back to all changes in this revision

Viewing changes to landscape/lib/tests/test_twisted_util.py

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Hasenack
  • Date: 2011-07-21 15:40:46 UTC
  • Revision ID: james.westby@ubuntu.com-20110721154046-l9vwkd062b4war77
Tags: 11.07.1.1-0ubuntu1.11.10.0
Included missing files (LP: #814223).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
 
3
from landscape.tests.helpers import LandscapeTest
 
4
from landscape.lib.twisted_util import spawn_process
 
5
from landscape.lib.fs import create_file
 
6
 
 
7
 
 
8
class SpawnProcessTest(LandscapeTest):
 
9
 
 
10
    def setUp(self):
 
11
        super(SpawnProcessTest, self).setUp()
 
12
        self.command = self.makeFile("#!/bin/sh\necho -n $@")
 
13
        os.chmod(self.command, 0755)
 
14
 
 
15
    def test_spawn_process_return_value(self):
 
16
        """
 
17
        The process is executed and returns the expected exit code.
 
18
        """
 
19
        create_file(self.command, "#!/bin/sh\nexit 2")
 
20
 
 
21
        def callback((out, err, code)):
 
22
            self.assertEqual(out, "")
 
23
            self.assertEqual(err, "")
 
24
            self.assertEqual(code, 2)
 
25
 
 
26
        result = spawn_process(self.command)
 
27
        result.addCallback(callback)
 
28
        return result
 
29
 
 
30
    def test_spawn_process_output(self):
 
31
        """
 
32
        The process returns the expected standard output.
 
33
        """
 
34
        def callback((out, err, code)):
 
35
            self.assertEqual(out, "a b")
 
36
            self.assertEqual(err, "")
 
37
            self.assertEqual(code, 0)
 
38
 
 
39
        result = spawn_process(self.command, args=("a", "b"))
 
40
        result.addCallback(callback)
 
41
        return result
 
42
 
 
43
    def test_spawn_process_error(self):
 
44
        """
 
45
        The process returns the expected standard error.
 
46
        """
 
47
        create_file(self.command, "#!/bin/sh\necho -n $@ >&2")
 
48
 
 
49
        def callback((out, err, code)):
 
50
            self.assertEqual(out, "")
 
51
            self.assertEqual(err, "a b")
 
52
            self.assertEqual(code, 0)
 
53
 
 
54
        result = spawn_process(self.command, args=("a", "b"))
 
55
        result.addCallback(callback)
 
56
        return result