mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
test: add fname_to_url tests for Unix, Windows, and edge cases
This commit is contained in:
parent
67d538a499
commit
671f3078c1
2 changed files with 41 additions and 7 deletions
|
@ -57,24 +57,24 @@ def fname_to_url(filepath):
|
||||||
return "" # 'website' not found in the path
|
return "" # 'website' not found in the path
|
||||||
|
|
||||||
# Extract the part of the path starting from 'website'
|
# Extract the part of the path starting from 'website'
|
||||||
relevant_parts = parts[website_index + 1 :]
|
relevant_parts = parts[website_index + 1:]
|
||||||
|
|
||||||
# Handle _includes directory
|
# Handle _includes directory
|
||||||
if relevant_parts and relevant_parts[0] == "_includes":
|
if relevant_parts and relevant_parts[0] == "_includes":
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
# Join the remaining parts
|
# Join the remaining parts
|
||||||
url_path = "/".join(relevant_parts)
|
url_path = '/'.join(relevant_parts)
|
||||||
|
|
||||||
# Handle index.md and other .md files
|
# Handle index.md and other .md files
|
||||||
if url_path.endswith(index):
|
if url_path.endswith(index):
|
||||||
url_path = url_path[: -len(index)]
|
url_path = url_path[:-len(index)]
|
||||||
elif url_path.endswith(md):
|
elif url_path.endswith(md):
|
||||||
url_path = url_path[: -len(md)] + ".html"
|
url_path = url_path[:-len(md)] + ".html"
|
||||||
|
|
||||||
# Ensure the URL starts and ends with '/'
|
# Ensure the URL starts and ends with '/'
|
||||||
url_path = url_path.strip("/")
|
url_path = url_path.strip('/')
|
||||||
|
|
||||||
return f"https://aider.chat/{url_path}"
|
return f"https://aider.chat/{url_path}"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import aider
|
import aider
|
||||||
from aider.coders import Coder
|
from aider.coders import Coder
|
||||||
from aider.commands import Commands
|
from aider.commands import Commands
|
||||||
from aider.help import Help
|
from aider.help import Help, fname_to_url
|
||||||
from aider.io import InputOutput
|
from aider.io import InputOutput
|
||||||
from aider.models import Model
|
from aider.models import Model
|
||||||
|
|
||||||
|
@ -54,6 +56,38 @@ class TestHelp(unittest.TestCase):
|
||||||
# Assert that there are more than 5 <doc> entries
|
# Assert that there are more than 5 <doc> entries
|
||||||
self.assertGreater(result.count("<doc"), 5)
|
self.assertGreater(result.count("<doc"), 5)
|
||||||
|
|
||||||
|
def test_fname_to_url_unix(self):
|
||||||
|
# Test relative Unix-style paths
|
||||||
|
self.assertEqual(fname_to_url('website/docs/index.md'), 'https://aider.chat/docs/')
|
||||||
|
self.assertEqual(fname_to_url('website/docs/usage.md'), 'https://aider.chat/docs/usage.html')
|
||||||
|
self.assertEqual(fname_to_url('website/_includes/header.md'), '')
|
||||||
|
|
||||||
|
# Test absolute Unix-style paths
|
||||||
|
self.assertEqual(fname_to_url('/home/user/project/website/docs/index.md'), 'https://aider.chat/docs/')
|
||||||
|
self.assertEqual(fname_to_url('/home/user/project/website/docs/usage.md'), 'https://aider.chat/docs/usage.html')
|
||||||
|
self.assertEqual(fname_to_url('/home/user/project/website/_includes/header.md'), '')
|
||||||
|
|
||||||
|
def test_fname_to_url_windows(self):
|
||||||
|
# Test relative Windows-style paths
|
||||||
|
self.assertEqual(fname_to_url(r'website\docs\index.md'), 'https://aider.chat/docs/')
|
||||||
|
self.assertEqual(fname_to_url(r'website\docs\usage.md'), 'https://aider.chat/docs/usage.html')
|
||||||
|
self.assertEqual(fname_to_url(r'website\_includes\header.md'), '')
|
||||||
|
|
||||||
|
# Test absolute Windows-style paths
|
||||||
|
self.assertEqual(fname_to_url(r'C:\Users\user\project\website\docs\index.md'), 'https://aider.chat/docs/')
|
||||||
|
self.assertEqual(fname_to_url(r'C:\Users\user\project\website\docs\usage.md'), 'https://aider.chat/docs/usage.html')
|
||||||
|
self.assertEqual(fname_to_url(r'C:\Users\user\project\website\_includes\header.md'), '')
|
||||||
|
|
||||||
|
def test_fname_to_url_edge_cases(self):
|
||||||
|
# Test paths that don't contain 'website'
|
||||||
|
self.assertEqual(fname_to_url('/home/user/project/docs/index.md'), '')
|
||||||
|
self.assertEqual(fname_to_url(r'C:\Users\user\project\docs\index.md'), '')
|
||||||
|
|
||||||
|
# Test empty path
|
||||||
|
self.assertEqual(fname_to_url(''), '')
|
||||||
|
|
||||||
|
# Test path with 'website' in the wrong place
|
||||||
|
self.assertEqual(fname_to_url('/home/user/website_project/docs/index.md'), '')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue