import os import tempfile import unittest import ara import internet SAYFA = ''' ''' class AraTest(unittest.TestCase): def test_results_are_parsed_and_ads_skipped(self): self.assertEqual(ara.sonuclari_coz(SAYFA), [("Bir başlık", "https://ornek.com/bir?a=1", "Kısa & öz özet"), ("İkinci", "https://ornek.org/iki", "")]) self.assertEqual(len(ara.sonuclari_coz(SAYFA, adet=1)), 1) def test_search_output_and_empty_result(self): metin = ara.ara("x", indirici=lambda adres: (SAYFA, "text/html")) self.assertIn("1. Bir başlık\n https://ornek.com/bir?a=1", metin) self.assertIn("Sonuç bulunamadı", ara.ara("x", indirici=lambda adres: ('
no results
', "text/html"))) def test_bot_challenge_uses_one_rss_backup_not_false_no_results(self): calls = [] def indirici(adres): calls.append(adres) return (('
Bot challenge
' if len(calls) == 1 else 'OmniRoutehttps://ornek.com/'), 'text/html') self.assertIn('https://ornek.com/', ara.ara('OmniRoute', indirici=indirici)) self.assertEqual(len(calls), 2) def test_two_invalid_services_report_failure_not_no_results(self): with self.assertRaisesRegex(RuntimeError, 'Arama hizmeti'): ara.ara('x', indirici=lambda adres: ('challenge', 'text/html')) def test_page_is_turned_into_text_and_cut(self): sayfa = "

Bir & iki

üç
" self.assertEqual(ara.oku("ornek.com", indirici=lambda adres: (sayfa, "text/html")), "Bir & iki\nüç") uzun = ara.oku("https://ornek.com", en_cok=10, indirici=lambda adres: ("

" + "a" * 50 + "

", "text/html")) self.assertTrue(uzun.startswith("a" * 10 + "\n[... kesildi: 50")) def test_main_reports_errors_without_raising(self): self.assertEqual(ara.main(["oku", "http://127.0.0.1:9/yok"]), 1) class InternetTest(unittest.TestCase): def test_note_names_both_commands_and_is_added_once(self): with tempfile.TemporaryDirectory() as d: betik = os.path.join(d, "ara.py") open(betik, "w").close() metin = internet.talimat(None, betik, python="py.exe") on = '& ' if os.name == 'nt' else '' self.assertIn(f'{on}"py.exe" "{betik}" ara "sorgu"', metin) self.assertIn(f'"py.exe" "{betik}" oku ', metin) req = {"input": [{"type": "message", "role": "user", "content": [{"type": "input_text", "text": "araştır"}]}]} self.assertTrue(internet.ekle(req, metin)) self.assertFalse(internet.ekle(req, metin)) self.assertEqual(req["input"][0]["role"], "developer") self.assertEqual(len(req["input"]), 2) self.assertIsNone(internet.talimat({"enabled": False}, betik)) self.assertIsNone(internet.talimat(None, os.path.join(d, "ara.py"))) # betik yoksa not eklenmez def test_windowless_python_is_swapped_for_the_console_one(self): with tempfile.TemporaryDirectory() as d: open(os.path.join(d, "python.exe"), "w").close() self.assertEqual(internet.python_yolu(os.path.join(d, "pythonw.exe")), os.path.join(d, "python.exe")) self.assertEqual(internet.python_yolu(os.path.join("yok", "pythonw.exe")), os.path.join("yok", "pythonw.exe")) if __name__ == "__main__": unittest.main()