77
88
99def test_parse_url_valid_https () -> None :
10+ """
11+ Test `_parse_url` with valid HTTPS URLs from supported platforms (GitHub, GitLab, Bitbucket).
12+ Verifies that user and repository names are correctly extracted.
13+ """
1014 test_cases = [
1115 "https://github.com/user/repo" ,
1216 "https://gitlab.com/user/repo" ,
@@ -20,6 +24,10 @@ def test_parse_url_valid_https() -> None:
2024
2125
2226def test_parse_url_valid_http () -> None :
27+ """
28+ Test `_parse_url` with valid HTTP URLs from supported platforms.
29+ Verifies that user and repository names, as well as the slug, are correctly extracted.
30+ """
2331 test_cases = [
2432 "http://github.com/user/repo" ,
2533 "http://gitlab.com/user/repo" ,
@@ -33,12 +41,20 @@ def test_parse_url_valid_http() -> None:
3341
3442
3543def test_parse_url_invalid () -> None :
44+ """
45+ Test `_parse_url` with an invalid URL that does not include a repository structure.
46+ Verifies that a ValueError is raised with an appropriate error message.
47+ """
3648 url = "https://only-domain.com"
3749 with pytest .raises (ValueError , match = "Invalid repository URL" ):
3850 _parse_url (url )
3951
4052
4153def test_parse_query_basic () -> None :
54+ """
55+ Test `parse_query` with basic inputs including valid repository URLs.
56+ Verifies that user and repository names, URL, and ignore patterns are correctly parsed.
57+ """
4258 test_cases = ["https://github.com/user/repo" , "https://gitlab.com/user/repo" ]
4359 for url in test_cases :
4460 result = parse_query (url , max_file_size = 50 , from_web = True , ignore_patterns = "*.txt" )
@@ -49,19 +65,31 @@ def test_parse_query_basic() -> None:
4965
5066
5167def test_parse_query_include_pattern () -> None :
68+ """
69+ Test `parse_query` with an include pattern.
70+ Verifies that the include pattern is set correctly and default ignore patterns are applied.
71+ """
5272 url = "https://github.com/user/repo"
5373 result = parse_query (url , max_file_size = 50 , from_web = True , include_patterns = "*.py" )
5474 assert result ["include_patterns" ] == ["*.py" ]
5575 assert set (result ["ignore_patterns" ]) == set (DEFAULT_IGNORE_PATTERNS )
5676
5777
5878def test_parse_query_invalid_pattern () -> None :
79+ """
80+ Test `parse_query` with an invalid pattern containing special characters.
81+ Verifies that a ValueError is raised with an appropriate error message.
82+ """
5983 url = "https://github.com/user/repo"
6084 with pytest .raises (ValueError , match = "Pattern.*contains invalid characters" ):
6185 parse_query (url , max_file_size = 50 , from_web = True , include_patterns = "*.py;rm -rf" )
6286
6387
6488def test_parse_url_with_subpaths () -> None :
89+ """
90+ Test `_parse_url` with a URL containing a branch and subpath.
91+ Verifies that user name, repository name, branch, and subpath are correctly extracted.
92+ """
6593 url = "https://github.com/user/repo/tree/main/subdir/file"
6694 result = _parse_url (url )
6795 assert result ["user_name" ] == "user"
@@ -71,38 +99,62 @@ def test_parse_url_with_subpaths() -> None:
7199
72100
73101def test_parse_url_invalid_repo_structure () -> None :
102+ """
103+ Test `_parse_url` with an invalid repository structure in the URL.
104+ Verifies that a ValueError is raised with an appropriate error message.
105+ """
74106 url = "https://github.com/user"
75107 with pytest .raises (ValueError , match = "Invalid repository URL" ):
76108 _parse_url (url )
77109
78110
79111def test_parse_patterns_valid () -> None :
112+ """
113+ Test `_parse_patterns` with valid patterns separated by commas.
114+ Verifies that the patterns are correctly parsed into a list.
115+ """
80116 patterns = "*.py, *.md, docs/*"
81117 result = _parse_patterns (patterns )
82118 assert result == ["*.py" , "*.md" , "docs/*" ]
83119
84120
85121def test_parse_patterns_invalid_characters () -> None :
122+ """
123+ Test `_parse_patterns` with invalid patterns containing special characters.
124+ Verifies that a ValueError is raised with an appropriate error message.
125+ """
86126 patterns = "*.py;rm -rf"
87127 with pytest .raises (ValueError , match = "Pattern.*contains invalid characters" ):
88128 _parse_patterns (patterns )
89129
90130
91131def test_parse_query_with_large_file_size () -> None :
132+ """
133+ Test `parse_query` with a very large file size limit.
134+ Verifies that the file size limit and default ignore patterns are set correctly.
135+ """
92136 url = "https://github.com/user/repo"
93137 result = parse_query (url , max_file_size = 10 ** 9 , from_web = True )
94138 assert result ["max_file_size" ] == 10 ** 9
95139 assert result ["ignore_patterns" ] == DEFAULT_IGNORE_PATTERNS
96140
97141
98142def test_parse_query_empty_patterns () -> None :
143+ """
144+ Test `parse_query` with empty include and ignore patterns.
145+ Verifies that the include patterns are set to None and default ignore patterns are applied.
146+ """
99147 url = "https://github.com/user/repo"
100148 result = parse_query (url , max_file_size = 50 , from_web = True , include_patterns = "" , ignore_patterns = "" )
101149 assert result ["include_patterns" ] is None
102150 assert result ["ignore_patterns" ] == DEFAULT_IGNORE_PATTERNS
103151
104152
105153def test_parse_query_include_and_ignore_overlap () -> None :
154+ """
155+ Test `parse_query` with overlapping include and ignore patterns.
156+ Verifies that overlapping patterns are removed from the ignore patterns.
157+ """
106158 url = "https://github.com/user/repo"
107159 result = parse_query (
108160 url ,
@@ -117,6 +169,10 @@ def test_parse_query_include_and_ignore_overlap() -> None:
117169
118170
119171def test_parse_query_local_path () -> None :
172+ """
173+ Test `parse_query` with a local file path.
174+ Verifies that the local path is set, a unique ID is generated, and the slug is correctly created.
175+ """
120176 path = "/home/user/project"
121177 result = parse_query (path , max_file_size = 100 , from_web = False )
122178 assert result ["local_path" ] == "/home/user/project"
@@ -125,18 +181,30 @@ def test_parse_query_local_path() -> None:
125181
126182
127183def test_parse_query_relative_path () -> None :
184+ """
185+ Test `parse_query` with a relative file path.
186+ Verifies that the local path and slug are correctly resolved.
187+ """
128188 path = "./project"
129189 result = parse_query (path , max_file_size = 100 , from_web = False )
130190 assert result ["local_path" ].endswith ("project" )
131191 assert result ["slug" ].endswith ("project" )
132192
133193
134194def test_parse_query_empty_source () -> None :
195+ """
196+ Test `parse_query` with an empty source input.
197+ Verifies that a ValueError is raised with an appropriate error message.
198+ """
135199 with pytest .raises (ValueError , match = "Invalid repository URL" ):
136200 parse_query ("" , max_file_size = 100 , from_web = True )
137201
138202
139203def test_parse_url_branch_and_commit_distinction () -> None :
204+ """
205+ Test `_parse_url` with URLs containing either a branch name or a commit hash.
206+ Verifies that the branch and commit are correctly distinguished.
207+ """
140208 url_branch = "https://github.com/user/repo/tree/main"
141209 url_commit = "https://github.com/user/repo/tree/abcd1234abcd1234abcd1234abcd1234abcd1234"
142210
@@ -151,13 +219,20 @@ def test_parse_url_branch_and_commit_distinction() -> None:
151219
152220
153221def test_parse_query_uuid_uniqueness () -> None :
222+ """
223+ Test `parse_query` to ensure that each call generates a unique UUID for the query result.
224+ """
154225 path = "/home/user/project"
155226 result1 = parse_query (path , max_file_size = 100 , from_web = False )
156227 result2 = parse_query (path , max_file_size = 100 , from_web = False )
157228 assert result1 ["id" ] != result2 ["id" ]
158229
159230
160231def test_parse_url_with_query_and_fragment () -> None :
232+ """
233+ Test `_parse_url` with a URL containing query parameters and a fragment.
234+ Verifies that the URL is cleaned and other fields are correctly extracted.
235+ """
161236 url = "https://github.com/user/repo?arg=value#fragment"
162237 result = _parse_url (url )
163238 assert result ["user_name" ] == "user"
0 commit comments