示例#1
0
 def test_10_query(self):
     try:
         if TT.jmespath:
             self.assertEquals(TT.query({"a": 1}, ac_query="a"), 1)
             self.assertEquals(TT.query({"a": {"b": 2}}, ac_query="a.b"), 2)
     except (NameError, AttributeError):
         pass
示例#2
0
 def test_14_empty_query(self):
     data = {"a": 1}
     try:
         if TT.jmespath:
             self._assert_dicts_equal(TT.query(data, ac_query=None), data)
             self._assert_dicts_equal(TT.query(data, ac_query=''), data)
     except (NameError, AttributeError):
         pass
示例#3
0
 def test_12_invalid_query(self):
     data = {"a": 1}
     try:
         if TT.jmespath:
             self._assert_dicts_equal(TT.query(data, ac_query="b."), data)
     except (NameError, AttributeError):
         pass
示例#4
0
 def _assert_query(self, data_exp_ref_list, dicts=False):
     _assert = self._assert_dicts_equal if dicts else self.assertEqual
     for data, exp, ref in data_exp_ref_list:
         try:
             _assert(TT.query(data, exp)[0], ref)
         except ValueError:
             pass
示例#5
0
文件: api.py 项目: angustaylor/venv
def _try_query(cnf, jexp, **options):
    """
    :param cnf: Mapping object represents configuration data
    :param jexp: JMESPath expression to query or None/False
    :param options: Keyword options currently not used

    :return: Maybe the result by querying with the JMESPath exp.
    :raises: jmespath.exceptions.*Error (ValueError)
    """
    if jexp:
        (cnf, exc) = query(cnf, jexp, **options)
        if exc:
            raise exc

    return cnf