|
1
|
|
|
# coding: utf8 |
|
2
|
|
|
|
|
3
|
|
|
# Copyright 2013-2015 Vincent Jacques <[email protected]> |
|
4
|
|
|
|
|
5
|
|
|
from __future__ import division, absolute_import, print_function |
|
6
|
|
|
|
|
7
|
|
|
from ActionTree import * |
|
8
|
|
|
from . import * |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class ExecutionTestCase(ActionTreeTestCase): |
|
12
|
|
|
def test_successful_nothing(self): |
|
13
|
|
|
a = self._action("a") |
|
14
|
|
|
report = execute(a) |
|
15
|
|
|
|
|
16
|
|
|
self.assertEqual(report.get_action_status(a).output, b"") |
|
17
|
|
|
|
|
18
|
|
|
def test_failed_nothing(self): |
|
19
|
|
|
a = self._action("a", exception=Exception()) |
|
20
|
|
|
report = execute(a, do_raise=False) |
|
21
|
|
|
|
|
22
|
|
|
self.assertEqual(report.get_action_status(a).output, b"") |
|
23
|
|
|
|
|
24
|
|
|
def test_canceled_nothing(self): |
|
25
|
|
|
a = self._action("a") |
|
26
|
|
|
a.add_dependency(self._action("b", exception=Exception())) |
|
27
|
|
|
report = execute(a, do_raise=False) |
|
28
|
|
|
|
|
29
|
|
|
self.assertIsNone(report.get_action_status(a).output) |
|
30
|
|
|
|
|
31
|
|
|
def test_print(self): |
|
32
|
|
|
a = self._action("a", print_on_stdout="printed on stdout") |
|
33
|
|
|
report = execute(a) |
|
34
|
|
|
|
|
35
|
|
|
self.assertEqual(report.get_action_status(a).output, b"printed on stdout\n") |
|
36
|
|
|
|
|
37
|
|
|
def test_print_stderr(self): |
|
38
|
|
|
a = self._action("a", print_on_stderr="printed on stderr") |
|
39
|
|
|
report = execute(a) |
|
40
|
|
|
|
|
41
|
|
|
self.assertEqual(report.get_action_status(a).output, b"printed on stderr\n") |
|
42
|
|
|
|
|
43
|
|
|
def test_echo(self): |
|
44
|
|
|
a = self._action("a", echo_on_stdout="echoed on stdout") |
|
45
|
|
|
report = execute(a) |
|
46
|
|
|
|
|
47
|
|
|
self.assertEqual(report.get_action_status(a).output, b"echoed on stdout\n") |
|
48
|
|
|
|
|
49
|
|
|
def test_puts(self): |
|
50
|
|
|
a = self._action("a", puts_on_stdout=b"putsed on stdout") |
|
51
|
|
|
report = execute(a) |
|
52
|
|
|
|
|
53
|
|
|
self.assertEqual(report.get_action_status(a).output, b"putsed on stdout\n") |
|
54
|
|
|
|
|
55
|
|
|
def test_many_print(self): |
|
56
|
|
|
MANY = 5 |
|
57
|
|
|
a = self._action("a") |
|
58
|
|
|
x = self._action("x", print_on_stdout=[("x", 0.1)] * MANY) |
|
59
|
|
|
y = self._action("y", print_on_stdout=[("y", 0.1)] * MANY) |
|
60
|
|
|
a.add_dependency(x) |
|
61
|
|
|
a.add_dependency(y) |
|
62
|
|
|
report = execute(a, jobs=2) |
|
63
|
|
|
|
|
64
|
|
|
self.assertEqual(report.get_action_status(x).output, b"x\n" * MANY) |
|
65
|
|
|
self.assertEqual(report.get_action_status(y).output, b"y\n" * MANY) |
|
66
|
|
|
|