From 671f3078c1471f9f45a7ce3b19bdac1dcfbfb863 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Mon, 21 Oct 2024 14:28:28 -0700 Subject: [PATCH] test: add fname_to_url tests for Unix, Windows, and edge cases --- aider/help.py | 12 ++++++------ tests/help/test_help.py | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/aider/help.py b/aider/help.py index 1bc3cef21..a08033042 100755 --- a/aider/help.py +++ b/aider/help.py @@ -57,24 +57,24 @@ def fname_to_url(filepath): return "" # 'website' not found in the path # Extract the part of the path starting from 'website' - relevant_parts = parts[website_index + 1 :] + relevant_parts = parts[website_index + 1:] # Handle _includes directory if relevant_parts and relevant_parts[0] == "_includes": return "" # Join the remaining parts - url_path = "/".join(relevant_parts) + url_path = '/'.join(relevant_parts) # Handle index.md and other .md files if url_path.endswith(index): - url_path = url_path[: -len(index)] + url_path = url_path[:-len(index)] 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 '/' - url_path = url_path.strip("/") - + url_path = url_path.strip('/') + return f"https://aider.chat/{url_path}" diff --git a/tests/help/test_help.py b/tests/help/test_help.py index 5a90d2ebf..aaac959b9 100644 --- a/tests/help/test_help.py +++ b/tests/help/test_help.py @@ -1,10 +1,12 @@ import unittest from unittest.mock import MagicMock +import os +from pathlib import Path import aider from aider.coders import Coder 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.models import Model @@ -54,6 +56,38 @@ class TestHelp(unittest.TestCase): # Assert that there are more than 5 entries self.assertGreater(result.count("