Fix tests for check_for_urls

This commit is contained in:
Paul Gauthier 2024-07-28 16:48:59 -03:00
parent 3e1ad07069
commit 8a9184cef9
2 changed files with 11 additions and 7 deletions

View file

@ -664,7 +664,7 @@ class Coder:
return self.commands.run(inp) return self.commands.run(inp)
self.check_for_file_mentions(inp) self.check_for_file_mentions(inp)
inp = self.check_for_urls(inp) self.check_for_urls(inp)
return inp return inp
@ -676,7 +676,7 @@ class Coder:
inp += "\n\n" inp += "\n\n"
inp += self.commands.cmd_web(url) inp += self.commands.cmd_web(url)
return inp return urls
def keyboard_interrupt(self): def keyboard_interrupt(self):
now = time.time() now = time.time()
@ -1227,12 +1227,13 @@ class Coder:
sys.stdout.write(text) sys.stdout.write(text)
except UnicodeEncodeError: except UnicodeEncodeError:
# Safely encode and decode the text # Safely encode and decode the text
safe_text = text.encode(sys.stdout.encoding, errors='backslashreplace').decode(sys.stdout.encoding) safe_text = text.encode(sys.stdout.encoding, errors="backslashreplace").decode(
sys.stdout.encoding
)
sys.stdout.write(safe_text) sys.stdout.write(safe_text)
sys.stdout.flush() sys.stdout.flush()
yield text yield text
def live_incremental_response(self, final): def live_incremental_response(self, final):
show_resp = self.render_incremental_response(final) show_resp = self.render_incremental_response(final)
self.mdstream.update(show_resp, final=final) self.mdstream.update(show_resp, final=final)

View file

@ -668,7 +668,7 @@ two
issue_cases = [ issue_cases = [
("check http://localhost:3002, there is an error", "http://localhost:3002"), ("check http://localhost:3002, there is an error", "http://localhost:3002"),
( (
"can you check out https://example.com/setup#whatever?", "can you check out https://example.com/setup#whatever",
"https://example.com/setup#whatever", "https://example.com/setup#whatever",
), ),
] ]
@ -687,10 +687,13 @@ two
# Test case with no URL # Test case with no URL
no_url_input = "This text contains no URL" no_url_input = "This text contains no URL"
result = coder.check_for_urls(no_url_input) result = coder.check_for_urls(no_url_input)
self.assertEqual(result, no_url_input) self.assertEqual(result, [])
# Test case with the same URL appearing multiple times # Test case with the same URL appearing multiple times
repeated_url_input = "Check https://example.com, then https://example.com again, and https://example.com one more time" repeated_url_input = (
"Check https://example.com, then https://example.com again, and https://example.com one"
" more time"
)
result = coder.check_for_urls(repeated_url_input) result = coder.check_for_urls(repeated_url_input)
self.assertEqual(result.count("https://example.com"), 1) self.assertEqual(result.count("https://example.com"), 1)
self.assertIn("https://example.com", result) self.assertIn("https://example.com", result)