| 1 | # -*- Python -*- -*- coding: iso-8859-1 -*- |
|---|
| 2 | # :Progetto: vcpx -- Test shell wrappers |
|---|
| 3 | # :Creato: mar 20 apr 2004 16:49:23 CEST |
|---|
| 4 | # :Autore: Lele Gaifax <lele@nautilus.homeip.net> |
|---|
| 5 | # |
|---|
| 6 | |
|---|
| 7 | from unittest import TestCase, TestSuite |
|---|
| 8 | from vcpx.shwrap import SystemCommand |
|---|
| 9 | |
|---|
| 10 | class SystemCommandTest(TestCase): |
|---|
| 11 | """Perform some basic tests of the wrapper. |
|---|
| 12 | """ |
|---|
| 13 | |
|---|
| 14 | def testExitStatusForTrue(self): |
|---|
| 15 | """Verify SystemCommand exit_status of ``true``. |
|---|
| 16 | """ |
|---|
| 17 | |
|---|
| 18 | c = SystemCommand('true') |
|---|
| 19 | c() |
|---|
| 20 | self.assertEqual(c.exit_status, 0) |
|---|
| 21 | |
|---|
| 22 | def testExitStatusForTrueWithOutput(self): |
|---|
| 23 | """Verify SystemCommand exit_status of ``true`` asking output. |
|---|
| 24 | """ |
|---|
| 25 | |
|---|
| 26 | c = SystemCommand('true') |
|---|
| 27 | c(output=True) |
|---|
| 28 | self.assertEqual(c.exit_status, 0) |
|---|
| 29 | |
|---|
| 30 | def testExitStatusForTrueWithInput(self): |
|---|
| 31 | """Verify SystemCommand exit_status of ``true`` feeding input. |
|---|
| 32 | """ |
|---|
| 33 | |
|---|
| 34 | c = SystemCommand('true') |
|---|
| 35 | c(input="Ciao") |
|---|
| 36 | self.assertEqual(c.exit_status, 0) |
|---|
| 37 | |
|---|
| 38 | def testExitStatusForTrueWithInputAndOutput(self): |
|---|
| 39 | """Verify SystemCommand exit_status of ``true`` input/output. |
|---|
| 40 | """ |
|---|
| 41 | |
|---|
| 42 | c = SystemCommand('true') |
|---|
| 43 | c(output=True, input="Ciao") |
|---|
| 44 | self.assertEqual(c.exit_status, 0) |
|---|
| 45 | |
|---|
| 46 | def testExitStatusForFalse(self): |
|---|
| 47 | """Verify SystemCommand exit_status of ``false``. |
|---|
| 48 | """ |
|---|
| 49 | |
|---|
| 50 | c = SystemCommand('false') |
|---|
| 51 | c() |
|---|
| 52 | self.assertNotEqual(c.exit_status, 0) |
|---|
| 53 | |
|---|
| 54 | def testExitStatusForFalseWithOutput(self): |
|---|
| 55 | """Verify SystemCommand exit_status of ``false`` asking output. |
|---|
| 56 | """ |
|---|
| 57 | |
|---|
| 58 | c = SystemCommand('false') |
|---|
| 59 | c(output=True) |
|---|
| 60 | self.assertNotEqual(c.exit_status, 0) |
|---|
| 61 | |
|---|
| 62 | def testExitStatusForFalseWithInput(self): |
|---|
| 63 | """Verify SystemCommand exit_status of ``false`` feeding input. |
|---|
| 64 | """ |
|---|
| 65 | |
|---|
| 66 | c = SystemCommand('false') |
|---|
| 67 | c(input="Ciao") |
|---|
| 68 | self.assertNotEqual(c.exit_status, 0) |
|---|
| 69 | |
|---|
| 70 | def testExitStatusForFalseWithInputAndOutput(self): |
|---|
| 71 | """Verify SystemCommand exit_status of ``false`` input/output. |
|---|
| 72 | """ |
|---|
| 73 | |
|---|
| 74 | c = SystemCommand('false') |
|---|
| 75 | c(output=True, input="Ciao") |
|---|
| 76 | self.assertNotEqual(c.exit_status, 0) |
|---|
| 77 | |
|---|
| 78 | def testExitStatusUnknownCommand(self): |
|---|
| 79 | """Verify SystemCommand exit_status for non existing command. |
|---|
| 80 | """ |
|---|
| 81 | |
|---|
| 82 | c = SystemCommand('/does/not/exist 2>/dev/null') |
|---|
| 83 | c() |
|---|
| 84 | self.assertNotEqual(c.exit_status, 0) |
|---|
| 85 | |
|---|
| 86 | def testStandardOutput(self): |
|---|
| 87 | """Verify that SystemCommand redirects stdout.""" |
|---|
| 88 | |
|---|
| 89 | c = SystemCommand('echo "ciao"') |
|---|
| 90 | out = c(output=True) |
|---|
| 91 | self.assertEqual(out.read(), "ciao\n") |
|---|
| 92 | |
|---|
| 93 | def testWorkingDir(self): |
|---|
| 94 | """Verify that the given command is executed in the specified |
|---|
| 95 | working directory. |
|---|
| 96 | """ |
|---|
| 97 | |
|---|
| 98 | c = SystemCommand('pwd', '/tmp') |
|---|
| 99 | out = c(output=True) |
|---|
| 100 | self.assertEqual(out.read(), "/tmp\n") |
|---|
| 101 | |
|---|