forked from alexcouper/bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
44 lines (34 loc) · 1.43 KB
/
tests.py
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
import unittest
from bash import bash
class TestBash(unittest.TestCase):
def test_bash_concatenation_by_method(self):
result = bash('ls .').bash('grep "tests.py$"').value()
self.assertEqual(result, 'tests.py')
def test_bash_concatenation_within_command(self):
result = bash('ls . | grep "tests.py$"').value()
self.assertEqual(result, 'tests.py')
def test_bash_repr(self):
result = bash('ls . | grep "tests.py$"')
self.assertEqual(repr(result), 'tests.py')
def test_bash_stdout(self):
result = bash('ls . | grep "tests.py$"')
self.assertEqual(result.stdout, b'tests.py\n')
self.assertEqual(result.code, 0)
def test_bash_stderr(self):
result = bash('./missing_command')
self.assertEqual(result.stdout, b'')
self.assertTrue(result.stderr in [
# Mac OSX
b'/bin/sh: ./missing_command: No such file or directory\n',
# Travis
b'/bin/sh: 1: ./missing_command: not found\n'
])
self.assertEqual(result.code, 127)
def test_passing_env(self):
result = bash('echo $NAME', env={'NAME': 'Fred'})
self.assertEqual(result.stdout, b'Fred\n')
def test_output_to_stdout(self):
b = bash('ls .', stdout=None)
self.assertEqual(str(b), '')
# Shouldn't find anything because we haven't piped it.
self.assertEqual(str(b.bash('grep setup')), '')