class QueryInspectionTest(unittest.TestCase):
    def setUp(self):
        class Root(Node):
            attr = 'value'
            query = Q.attr + Q.attr
            def my_action(self): pass
        self.env = Env(Root())
        self.env_insp = Inspector(self.env)
        self.node_insp = Inspector(Root())

    def test_has_query(self):
        self.assertEqual(self.env_insp.has_query('query'), True)
        self.assertEqual(self.env_insp.has_query('not_a_query'), False)

        self.assertEqual(self.node_insp.has_query('query'), True)
        self.assertEqual(self.node_insp.has_query('not_a_query'), False)

    def test_get_query(self):
        self.assertIsInstance(self.node_insp.get_query('query'), Action)
        self.assertRaises(AttributeError, self.node_insp.get_query, 'not_a_query')

    def test_trace_query(self):
        # trace_query is private because it's for internal use. (In the
        # shell.)
        result = self.env_insp.trace_query('query')
        self.assertIsInstance(result, QueryResult)
        self.assertEqual(result.result, 'valuevalue')
Ejemplo n.º 2
0
    def get_type(self):
        """
        Return the ``AUTOCOMPLETE_TYPE`` for this node.
        """
        insp = Inspector(self.node)
        atypes = self.autocomplete_types

        if AUTOCOMPLETE_TYPE.NODE in atypes and not self.attr_name:
            return AUTOCOMPLETE_TYPE.NODE

        if AUTOCOMPLETE_TYPE.ACTION in atypes and not self.attr_name and insp.is_callable(
        ):
            return AUTOCOMPLETE_TYPE.ACTION

        if AUTOCOMPLETE_TYPE.ACTION in atypes and insp.has_action(
                self.attr_name):
            return AUTOCOMPLETE_TYPE.ACTION

        if AUTOCOMPLETE_TYPE.QUERY_ATTRIBUTE in atypes and insp.has_query(
                self.attr_name):
            return AUTOCOMPLETE_TYPE.QUERY_ATTRIBUTE

        if AUTOCOMPLETE_TYPE.PROPERTY_ATTRIBUTE in atypes and insp.has_property(
                self.attr_name):
            return AUTOCOMPLETE_TYPE.PROPERTY_ATTRIBUTE
Ejemplo n.º 3
0
    def get_type(self):
        """
        Return the ``AUTOCOMPLETE_TYPE`` for this node.
        """
        insp = Inspector(self.node)
        atypes = self.autocomplete_types

        if AUTOCOMPLETE_TYPE.NODE in atypes and not self.attr_name:
            return AUTOCOMPLETE_TYPE.NODE

        if AUTOCOMPLETE_TYPE.ACTION in atypes and not self.attr_name and insp.is_callable():
            return AUTOCOMPLETE_TYPE.ACTION

        if AUTOCOMPLETE_TYPE.ACTION in atypes and insp.has_action(self.attr_name):
            return AUTOCOMPLETE_TYPE.ACTION

        if AUTOCOMPLETE_TYPE.QUERY_ATTRIBUTE in atypes and insp.has_query(self.attr_name):
            return AUTOCOMPLETE_TYPE.QUERY_ATTRIBUTE

        if AUTOCOMPLETE_TYPE.PROPERTY_ATTRIBUTE in atypes and insp.has_property(self.attr_name):
            return AUTOCOMPLETE_TYPE.PROPERTY_ATTRIBUTE