Spaces:
Paused
Paused
import unittest | |
import arxiv | |
class TestArxivLibrary(unittest.TestCase): | |
def setUp(self): | |
self.client = arxiv.Client() | |
def test_simple_search(self): | |
search = arxiv.Search(query="quantum computing", max_results=5) | |
results = list(self.client.results(search)) | |
self.assertEqual(len(results), 5) | |
self.assertTrue(all(isinstance(r, arxiv.Result) for r in results)) | |
def test_complex_query(self): | |
query = 'au:"John Doe" AND cat:cs.AI AND year:2020' | |
search = arxiv.Search(query=query, max_results=10) | |
results = list(self.client.results(search)) | |
# Add assertions to check the results match the query | |
def test_empty_query(self): | |
search = arxiv.Search(query="", max_results=5) | |
results = list(self.client.results(search)) | |
self.assertEqual(len(results), 0, "Empty query should return no results") | |
def test_metadata_extraction(self): | |
search = arxiv.Search(query="physics", max_results=1) | |
result = next(self.client.results(search)) | |
self.assertIsNotNone(result.title) | |
self.assertIsNotNone(result.authors) | |
self.assertIsNotNone(result.published) | |
# Add more assertions for other metadata fields | |
def test_whitespace_query(self): | |
search = arxiv.Search(query=" ", max_results=5) | |
results = list(self.client.results(search)) | |
self.assertEqual(len(results), 0, "Whitespace-only query should return no results") | |
def test_network_error(self): | |
# Mock network error and ensure it's handled gracefully | |
pass | |
if __name__ == '__main__': | |
unittest.main() | |