import sys
import unittest
import vdebug.dbgp
import xml
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
class ResponseTest(unittest.TestCase):
"""Test the response class in the vdebug.dbgp module."""
def test_get_cmd(self):
"""Test that the get_cmd() method returns the command"""
cmd = "status"
res = vdebug.dbgp.Response("",cmd,"",Mock())
assert res.get_cmd() == cmd
def test_get_cmd_args(self):
"""Test that the get_cmd_args() method return command arguments"""
cmd_args = "-a abcd"
res = vdebug.dbgp.Response("","",cmd_args,Mock())
assert res.get_cmd_args() == cmd_args
def test_as_string(self):
"""Test that the as_string() method returns the
raw response string"""
response = "
"""
res = vdebug.dbgp.Response(response,"","",Mock())
self.assertIsInstance(res.as_xml(),xml.etree.ElementTree.Element)
def test_error_tag_raises_exception(self):
response = """
"""
re = "command is not available"
self.assertRaisesRegex(vdebug.dbgp.DBGPError,re,vdebug.dbgp.Response,response,"","",Mock())
class StatusResponseTest(unittest.TestCase):
"""Test the behaviour of the StatusResponse class."""
def test_string_is_status_text(self):
response = """
"""
res = vdebug.dbgp.StatusResponse(response,"","",Mock())
assert str(res) == "starting"
class FeatureResponseTest(unittest.TestCase):
"""Test the behaviour of the FeatureResponse class."""
def test_feature_is_supported(self):
response = """
"""
res = vdebug.dbgp.FeatureGetResponse(response,"","",Mock())
assert res.is_supported() == 1
def test_feature_is_not_supported(self):
response = """
"""
res = vdebug.dbgp.FeatureGetResponse(response,"","",Mock())
assert res.is_supported() == 0
class StackGetTest(unittest.TestCase):
"""Test the behaviour of the StackGetResponse class."""
def test_string_is_status_text(self):
response = """
"""
res = vdebug.dbgp.StackGetResponse(response,"","",Mock())
stack = res.get_stack()
assert stack[0].get('filename') == "file:///usr/local/bin/cake"
assert len(stack) == 1
class ContextGetTest(unittest.TestCase):
response = """
"""
def test_properties_are_objects(self):
res = vdebug.dbgp.ContextGetResponse(self.response,"","",Mock())
context = res.get_context()
assert len(context) == 23
self.assertIsInstance(context[0],vdebug.dbgp.ContextProperty)
def test_int_property_attributes(self):
res = vdebug.dbgp.ContextGetResponse(self.response,"","",Mock())
context = res.get_context()
prop = context[0]
assert prop.display_name == "$argc"
assert prop.type == "int"
assert prop.value == "4"
assert prop.has_children == False
def test_array_property_attributes(self):
res = vdebug.dbgp.ContextGetResponse(self.response,"","",Mock())
context = res.get_context()
prop = context[1]
assert prop.display_name == "$argv"
assert prop.type == "array"
assert prop.value == ""
assert prop.has_children == True
assert prop.child_count() == 4
def test_string_property_attributes(self):
res = vdebug.dbgp.ContextGetResponse(self.response,"","",Mock())
context = res.get_context()
prop = context[2]
assert prop.display_name == "$argv[0]"
assert prop.type == "string"
assert prop.value == "`/usr/local/bin/cake`"
assert prop.has_children == False
assert prop.size == "19"
class ContextGetAlternateTest(unittest.TestCase):
response = """
"""
def test_properties_are_objects(self):
res = vdebug.dbgp.ContextGetResponse(self.response,"","",Mock())
context = res.get_context()
assert len(context) == 3
self.assertIsInstance(context[0],vdebug.dbgp.ContextProperty)