Skip to content

Commit

Permalink
add error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Sep 26, 2024
1 parent 401d58d commit 875efa5
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,39 @@ def setUp(self):
self.api_key = os.environ.get("API_KEY")
if not self.api_key:
raise ValueError("API_KEY environment variable is not set")
print("we got api key: ", self.api_key)
self.file_path = "../examples/sample_data/stoxx_index_guide_0003.pdf"
self.file_path = "./examples/sample_data/stoxx_index_guide_0003.pdf"
# create instance of AnyParser
self.ap = AnyParser(self.api_key)

def test_sync_extract(self):
"""Synchronous Extraction"""
md_output, total_time = self.ap.extract(self.file_path)
self.assertIsNotNone(md_output)
self.assertIsInstance(total_time, str)

# check for specific content in the markdown
self.assertFalse(md_output.startswith("Error:"), md_output)
self.assertTrue(
md_output.startswith("STOXX INDEX METHODOLOGY GUIDE"),
"Extraction failed",
)

# returning time elapsed indicates success
self.assertTrue(total_time.startswith("Time Elapsed:"))

def test_async_extract_and_fetch(self):
"""Asynchronous Extraction and Fetch"""

# check for error in sending extraction request
file_id = self.ap.async_extract(self.file_path)
self.assertIsNotNone(file_id)
self.assertFalse(file_id.startswith("Error:"), file_id)
self.assertFalse(file_id.startswith("Request error:"), file_id)
self.assertFalse(file_id.startswith("Upload error:"), file_id)

# check for specific content in extraction result
md = self.ap.async_fetch(file_id=file_id)
self.assertIsNotNone(md)
self.assertTrue(
md.startswith("STOXX INDEX METHODOLOGY GUIDE"),
"Expected content not found at the start of the fetched result",
)


if __name__ == "__main__":
Expand Down

0 comments on commit 875efa5

Please sign in to comment.