def test_add_entry_value_none(self): key = "test" value = None list_entries = [{"str": key}] vocabulary = Vocabulary() vocabulary.add_entry(key, value) self.assertEqual(list_entries, vocabulary.temp_vocabulary['entries'])
def test_add_entry(self): key = "New York" value = "Knicks" list_entries = [{"str": key, "category": value}] vocabulary = Vocabulary() vocabulary.add_entry(key, value) self.assertEqual(list_entries, vocabulary.temp_vocabulary['entries'])
def test_delete_false(self, con): some_id = 'some id' voc = Vocabulary() response = Mock() response.status_code = 200 response.ok = False con.return_value = response res = voc.delete(some_id) self.assertEqual(res, False)
def test_read(self, con): voc = Vocabulary() some_json = [{"key": "value"}] response = Mock() response.status_code = 200 response.json.return_value = some_json con.return_value = response res = voc.read() self.assertEqual(res, some_json)
def test_entries_vocabulary_len_3(self): test_vocabulary = { "str": "str", "category": "category", "some_key": "some_value" } vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.entries(test_vocabulary)
def test_fetch(self, con): some_id = 'some id' some_json = { "id": "some id", "name": "some name", "entries": "some entries" } voc = Vocabulary() response = Mock() response.json.return_value = some_json con.return_value = response res = voc.fetch(some_id) self.assertEqual(str(res), str(some_json))
def test_update_name(self): vocabulary_id = "string" entries = {"str": "str", "category": "category"} vocabulary = Vocabulary() vocabulary.entries(entries) with self.assertRaises(QtVocabularyError): vocabulary.update(vocabulary_id)
def test_update_entries(self): vocabulary_id = "string" name = "name" vocabulary = Vocabulary() vocabulary.name(name) with self.assertRaises(QtVocabularyError): vocabulary.update(vocabulary_id)
def test_create_input_stream(self, con): name = "some name" some_tsv_file = 'test.tsv' with open(some_tsv_file, "w") as f: f.write("Delete me!") some_dict = { "id": "some value", 'name': 'some name', 'entries': [{ 'str': 'some entry' }] } some_entry = "some entry" voc = Vocabulary() voc.name(name) voc.add_entry(some_entry) voc.source(some_tsv_file) response = Mock() response.json.return_value = some_dict con.return_value = response res = voc.create() self.assertEqual(str(res), str(some_dict)) os.remove("test.tsv")
def test_create_input_stream_none(self, con): name = "some name" some_dict = { "id": "some value", 'name': 'some name', 'entries': [{ 'str': 'some entry' }] } some_entry = "some entry" voc = Vocabulary() voc.name(name) voc.add_entry(some_entry) response = Mock() response.json.return_value = some_dict con.return_value = response res = voc.create() self.assertEqual(str(res), str(some_dict))
def test_update(self, con): some_id = "some id" some_name = 'some name' some_key = 'some key' some_dict = { "id": None, 'name': 'some name', 'entries': [{ 'str': 'some entry' }] } voc = Vocabulary() voc.name(some_name) voc.add_entry(some_key) response = Mock() response.json.return_value = some_dict con.return_value = response res = voc.update(some_id) self.assertEqual(str(res), str(some_dict))
def test_entries_vocabulary_len_0(self): test_vocabulary = {} vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.entries(test_vocabulary)
def test_get_entries(self): vocabulary = Vocabulary() some_entry = [] self.assertEqual(vocabulary.temp_vocabulary["entries"], some_entry)
def test_entries_type(self): test_vocabulary = "string" vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.entries(test_vocabulary)
def test_get_name(self): vocabulary = Vocabulary() some_name = None self.assertEqual(vocabulary.temp_vocabulary["name"], some_name)
def test_name_type(self): name = 123 vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.name(name)
def test_create_miss_name(self): entries = {"str": "str", "category": "category"} vocabulary = Vocabulary() vocabulary.entries(entries) with self.assertRaises(QtVocabularyError): vocabulary.create()
def test_set_id_arg_err(self): vocabulary = Vocabulary() some_id = 123 with self.assertRaises(QtArgumentError): vocabulary.set_id(some_id)
def test_name_name(self): name = "some name" vocabulary = Vocabulary() vocabulary.name(name) self.assertEqual(name, vocabulary.temp_vocabulary["name"])
def test_delete_arg(self): vocabulary_id = 123 vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.delete(vocabulary_id)
def test_update_arg_type(self): vocabulary_id = 123 vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.update(vocabulary_id)
def test_source_arg_file_type(self): file = 123 vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.source(file)
def test_create_miss_entry(self): name = "some name" voc = Vocabulary() voc.name(name) with self.assertRaises(QtVocabularyError): voc.create()
def test_set_id(self): vocabulary = Vocabulary() some_id = 'some id' vocabulary.set_id(some_id) self.assertEqual(vocabulary.id, some_id)
def test_entries_vocabulary_content_2(self): test_vocabulary = {"str": "str", "test": "category"} vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.entries(test_vocabulary)
def test_fetch_arg(self): vocabulary_id = 123 vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.fetch(vocabulary_id)
def test_entries_category(self): test_vocabulary = {"str": "str"} vocabulary = Vocabulary() vocabulary.entries(test_vocabulary) self.assertEqual([test_vocabulary], vocabulary.temp_vocabulary['entries'])
def test_source_file_exist(self): file = "path.tsv" vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.source(file)
from qtcurate.document import Document from qtcurate.result import Result API_KEY = "YOUR-API-KEY" DOCUMENT = "resources/sample.pdf" # Initialise with api key Qt.init(API_KEY) # 1- Upload the sample document for processing list_of_documents = [] document = Document() doc = document.create(DOCUMENT) list_of_documents.append(doc) # 2- Create vocabulary vocabulary = Vocabulary() vocabulary.add_entry("Industrials") vocabulary.add_entry("Quasi-Governments") vocabulary.add_entry("Governments") vocabulary.name("Allocations (%)").create() # 3- Creator Extractor - Regex must have 1 capturing group extractor = Extractor() extractor.set_vocabulary(vocabulary.get_id()) extractor.set_validator("^ +(\\d[\\d\\.\\,]+\\d)") extractor.set_type(Type.DOUBLE) # 4- Run model = Model() model.set_description("test data process") model.add_extractor(extractor)
def test_add_entry_value_type(self): key = "test" value = ["Knicks"] vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.add_entry(key, value)