Ejemplo n.º 1
0
    def select_elements(self, json_string, expr):
        """
        Возвращает список элементов из _json_string_, соответствующих [ http://jsonselect.org/ | JSONSelect] выражению.
        
        *Args:*\n
        _json_string_ - json-строка;\n
        _expr_ - JSONSelect выражение;
        
        *Return:*\n
        Список найденных элементов. Если элементы не найдены, то ``None``
        
        *Example:*\n
        | *Settings* | *Value* |
        | Library    | JsonValidator |
        | Library    | OperatingSystem |
        | *Test Cases* | *Action* | *Argument* | *Argument* |
        | Select json elements | ${json_example}=   | OperatingSystem.Get File |   ${CURDIR}${/}json_example.json |
        |                      |  ${json_elements}= | Select elements  |  ${json_example}  |  .author:contains("Evelyn Waugh")~.price |
        =>\n
        | 12.99
        """

        load_input_json = self.string_to_json(json_string)
        # парсинг jsonselect
        jsonselect.Parser(load_input_json)
        values = jsonselect.select(expr, load_input_json)
        return values
Ejemplo n.º 2
0
    def _test(self=None):
        parser = jsonselect.Parser(input)

        try:
            if output[0][:5] == 'Error':
                self.assertRaises(jsonselect.SelectorSyntaxError, parser.parse,
                                  (selector, ))
                return
        except (IndexError, TypeError, KeyError):
            pass

        selection = parser.parse(selector)

        msg = "%s" % selector
        msg += "\n%s\n!=\n%s" % (selection, output)
        log.debug('creating %s("%s")' % (_test.__name__, selector))

        if all((hasattr(i, '__iter__') for i in (selection, output))):
            self.assertItemsEqual(selection, output, msg=msg)
        else:
            self.assertEqual(selection, output, msg=msg)
Ejemplo n.º 3
0
 def setUp(self):
     self.parser = jsonselect.Parser({})
Ejemplo n.º 4
0
 def setUp(self):
     self.obj = {'hello': 'world', 'foo': [1, 2, 3], 'bar': {'x': 'y'}}
     self.parser = jsonselect.Parser(self.obj)