Exemplo n.º 1
0
    def pushButton_clicked(self):
        text = str(self.textEdit.toPlainText())
        text = text.replace('true', 'True')
        text = text.replace('false', 'False')
        text = text.replace('null', 'None')

        data_structure = string_to_dict(text)
        if not data_structure:
            self.resultLineEdit.setText('Incorrect data structure')
            return

        key = str(self.finder.text())
        if not key:
            self.resultLineEdit.setText('Incorrect key structure')
            return

        key_path = find_key(data_structure, key)
        if not key_path:
            self.resultLineEdit.setText('Key not found')
            return

        self.resultLineEdit.setText(key_path)
Exemplo n.º 2
0
 def test_stringToDict_valid(self):
     the_dict = {'K': [{'k1': 'v'}, {'k': 'v1'}, {'k2': 'v1'}]}
     # pprint(the_dict) {'K': [{'k1': 'v'}, {'k': 'v1'}, {'k2': 'v1'}]}
     self.assertEqual(the_dict, string_to_dict("""{'K': [{'k1': 'v'},
                                                     {'k': 'v1'},
                                                     {'k2': 'v1'}]}"""))