(self)
| 865 | ) |
| 866 | |
| 867 | def test_check_for_urls(self): |
| 868 | io = InputOutput(yes=True) |
| 869 | coder = Coder.create(self.GPT35, None, io=io) |
| 870 | coder.commands.scraper = MagicMock() |
| 871 | coder.commands.scraper.scrape = MagicMock(return_value="some content") |
| 872 | |
| 873 | # Test various URL formats |
| 874 | test_cases = [ |
| 875 | ("Check http://example.com, it's cool", "http://example.com"), |
| 876 | ("Visit https://www.example.com/page and see stuff", "https://www.example.com/page"), |
| 877 | ( |
| 878 | "Go to http://subdomain.example.com:8080/path?query=value, or not", |
| 879 | "http://subdomain.example.com:8080/path?query=value", |
| 880 | ), |
| 881 | ( |
| 882 | "See https://example.com/path#fragment for example", |
| 883 | "https://example.com/path#fragment", |
| 884 | ), |
| 885 | ("Look at http://localhost:3000", "http://localhost:3000"), |
| 886 | ("View https://example.com/setup#whatever", "https://example.com/setup#whatever"), |
| 887 | ("Open http://127.0.0.1:8000/api/v1/", "http://127.0.0.1:8000/api/v1/"), |
| 888 | ( |
| 889 | "Try https://example.com/path/to/page.html?param1=value1¶m2=value2", |
| 890 | "https://example.com/path/to/page.html?param1=value1¶m2=value2", |
| 891 | ), |
| 892 | ("Access http://user:password@example.com", "http://user:password@example.com"), |
| 893 | ( |
| 894 | "Use https://example.com/path_(with_parentheses)", |
| 895 | "https://example.com/path_(with_parentheses)", |
| 896 | ), |
| 897 | ] |
| 898 | |
| 899 | for input_text, expected_url in test_cases: |
| 900 | with self.subTest(input_text=input_text): |
| 901 | result = coder.check_for_urls(input_text) |
| 902 | self.assertIn(expected_url, result) |
| 903 | |
| 904 | # Test cases from the GitHub issue |
| 905 | issue_cases = [ |
| 906 | ("check http://localhost:3002, there is an error", "http://localhost:3002"), |
| 907 | ( |
| 908 | "can you check out https://example.com/setup#whatever", |
| 909 | "https://example.com/setup#whatever", |
| 910 | ), |
| 911 | ] |
| 912 | |
| 913 | for input_text, expected_url in issue_cases: |
| 914 | with self.subTest(input_text=input_text): |
| 915 | result = coder.check_for_urls(input_text) |
| 916 | self.assertIn(expected_url, result) |
| 917 | |
| 918 | # Test case with multiple URLs |
| 919 | multi_url_input = "Check http://example1.com and https://example2.com/page" |
| 920 | result = coder.check_for_urls(multi_url_input) |
| 921 | self.assertIn("http://example1.com", result) |
| 922 | self.assertIn("https://example2.com/page", result) |
| 923 | |
| 924 | # Test case with no URL |
nothing calls this directly
no test coverage detected