class CommandResultTestCase(unittest.TestCase): def setUp(self): self.c = Cisco(device) def test_return_as_is(self): self.assertEqual(self.c._process_command_result((0, None, '\ta line\r\nanother line\n '), 'show run', strip_command=False, strip_prompt=False, process_errors=False), 'a line\r\nanother line') def test_strip_prompt(self): prompt = re.compile('bar>$') self.c._buf = '\ta line\r\nanother line\n bar>' result = self.c._process_buffer([prompt]) self.assertEqual(self.c._process_command_result(result, 'show run', strip_command=False, strip_prompt=True, process_errors=False), 'a line\r\nanother line') def test_strip_command(self): prompt = re.compile('bar>$') self.c._buf = 'show run\ta line\r\nanother line\n bar>' result = self.c._process_buffer([prompt]) self.assertEqual(self.c._process_command_result(result, 'show run', strip_command=True, strip_prompt=False, process_errors=False), 'a line\r\nanother line\n bar>') def test_strip_command_and_prompt(self): prompt = re.compile('bar>$') self.c._buf = 'show run\ta line\r\nanother line\n bar>' result = self.c._process_buffer([prompt]) self.assertEqual(self.c._process_command_result(result, 'show run', strip_command=True, strip_prompt=True, process_errors=False), 'a line\r\nanother line')
class DeviceErrorsTestCase(unittest.TestCase): def setUp(self): self.c = Cisco(device) def test_no_error(self): data = """show running-config Building configuration...""" self.failUnlessIdentical(self.c._process_device_errors(data), None) def test_empty(self): self.failUnlessIdentical(self.c._process_device_errors(''), None) def test_error_with_marker(self): data = """foo bar ^ % Invalid input detected at '^' marker. switch>""" self.assertEqual(self.c._process_device_errors(data), ([' ^', "% Invalid input detected at '^' marker.", ''], ['foo bar', 'switch>'])) def test_error_with_marker_incomplete_results(self): data = r"""foo bar ^ % Something really terrible at '^' marker""" self.assertEqual(self.c._process_device_errors(data), ([' ^', "% Something really terrible at '^' marker"], ['foo bar'])) def test_error_no_marker(self): data = """$bad input % Unknown command or computer name, or unable to find computer address rest of data""" self.assertEqual(self.c._process_device_errors(data), (['% Unknown command or computer name, or unable to find computer address'], ['$bad input', 'rest of data'])) def test_error_no_marker_incomplete_results_1(self): data = """$bad input % Unknown command or computer name, or unable to find computer address""" self.assertEqual(self.c._process_device_errors(data), (['% Unknown command or computer name, or unable to find computer address'], ['$bad input'])) def test_error_no_marker_incomplete_results_2(self): data = """% Unknown command or computer name, or unable to find computer address""" self.assertEqual(self.c._process_device_errors(data), (['% Unknown command or computer name, or unable to find computer address'], [])) def test_error_no_marker_incomplete_results_3(self): data = """% Unknown command or computer name, or unable to find computer address rest of the output""" self.assertEqual(self.c._process_device_errors(data), (['% Unknown command or computer name, or unable to find computer address'], ['rest of the output']))
def setUp(self): self.c = Cisco(device)
def test_command_disconnected(self): c = Cisco(device) c.eof = True d = c.run_command('something') self.failUnlessFailure(d, NotConnected)