def test_command_timeout(self): config = { 'Command_options': { 'Timeout': 0.1 }, 'Info': { 'lhs': ['sleep', '2'] } } returned = run_commands.run(config) expected = run_commands.CommandOutput( **{'err': [('E', "Command 'lhs' not done after timeout")]}) self.assertEqual(returned, expected)
def test_command_not_found(self): config = { 'Command_options': { 'Timeout': 10 }, 'Info': { 'lhs': ['this_command_should_not_exist'] } } returned = run_commands.run(config) expected = run_commands.CommandOutput( **{'err': [('E', "Command 'lhs' not found")]}) self.assertEqual(returned, expected)
def test_command_fail(self): config = { 'Command_options': { 'Timeout': 10 }, 'Info': { 'lhs': ['false'] } } returned = run_commands.run(config) expected = run_commands.CommandOutput( **{'err': [('E', "Command 'lhs' returned a non-success code")]}) self.assertEqual(returned, expected)
def test_centered_output(self): config = { 'Command_options': { 'Timeout': 10 }, 'Info': { '_centered_output_': ['echo', 'rhs'] } } returned = run_commands.run(config) expected = run_commands.CommandOutput(**{ 'out': [('_centered_', 'rhs', 3)], 'max_rhs': 3 }) self.assertEqual(returned, expected)
def test_string_command(self): config = { 'Command_options': { 'Timeout': 10 }, 'Info': { 'lhs': 'echo rhs' } } returned = run_commands.run(config) expected = run_commands.CommandOutput(**{ 'out': [('lhs', 'rhs', 3)], 'max_lhs': 3, 'max_rhs': 3 }) self.assertEqual(returned, expected)
def test_underscore_to_space(self): config = { 'Command_options': { 'Timeout': 10 }, 'Info': { 'Replace_underscore': ['echo', 'rhs'] } } returned = run_commands.run(config) expected = run_commands.CommandOutput( **{ 'out': [('Replace underscore', 'rhs', 3)], 'max_lhs': 18, 'max_rhs': 3 }) self.assertEqual(returned, expected)
def test_multi_line_command(self): config = { 'Command_options': { 'Timeout': 10 }, 'Info': { 'lhs': ['printf', 'foo\nbar'] } } returned = run_commands.run(config) expected = run_commands.CommandOutput( **{ 'out': [('lhs', 'foo', 3), ('', 'bar', 3)], 'max_lhs': 3, 'max_rhs': 3 }) self.assertEqual(returned, expected)
def test_two_commands(self): config = { 'Command_options': { 'Timeout': 10 }, 'Info': { 'zFirst': 'echo rhs1', 'aLast': ['echo', 'rhs2'] } } returned = run_commands.run(config) expected = run_commands.CommandOutput( **{ 'out': [('zFirst', 'rhs1', 4), ('aLast', 'rhs2', 4)], 'max_lhs': 6, 'max_rhs': 4 }) self.assertEqual(returned, expected)
def test_int_command(self): config = {'Command_options': {'Timeout': 10}, 'Info': {'lhs': 2}} returned = run_commands.run(config) expected = run_commands.CommandOutput( **{'out': [('', '', 0), ('', '', 0)]}) self.assertEqual(returned, expected)