|
7 | 7 | from tests.custom.types import GetHumanloopClientFn, SyncableFile |
8 | 8 |
|
9 | 9 |
|
| 10 | +@pytest.mark.parametrize( |
| 11 | + "path_generator,expected_error,test_case_description", |
| 12 | + [ |
| 13 | + # Extension path test cases |
| 14 | + # Using lambdas to defer path generation until we have access to the test_file fixture |
| 15 | + ( |
| 16 | + lambda test_file: f"{test_file.path}.{test_file.type}", |
| 17 | + "includes a file extension which is not supported", |
| 18 | + "Standard extension", |
| 19 | + ), |
| 20 | + ( |
| 21 | + lambda test_file: f"{test_file.path}.{test_file.type.upper()}", |
| 22 | + "includes a file extension which is not supported", |
| 23 | + "Uppercase extension", |
| 24 | + ), |
| 25 | + ( |
| 26 | + lambda test_file: f"{test_file.path}.{test_file.type.capitalize()}", |
| 27 | + "includes a file extension which is not supported", |
| 28 | + "Mixed case extension", |
| 29 | + ), |
| 30 | + ( |
| 31 | + lambda test_file: f" {test_file.path}.{test_file.type} ", |
| 32 | + "includes a file extension which is not supported", |
| 33 | + "With whitespace", |
| 34 | + ), |
| 35 | + # Slash path test cases |
| 36 | + (lambda test_file: f"{test_file.path}/", "Path .* format is invalid", "Trailing slash"), |
| 37 | + (lambda test_file: f"/{test_file.path}", "Path .* format is invalid", "Leading slash"), |
| 38 | + (lambda test_file: f"/{test_file.path}/", "Path .* format is invalid", "Both leading and trailing slashes"), |
| 39 | + ( |
| 40 | + lambda test_file: f"//{test_file.path}//", |
| 41 | + "Path .* format is invalid", |
| 42 | + "Multiple leading and trailing slashes", |
| 43 | + ), |
| 44 | + # Combined path test cases |
| 45 | + ( |
| 46 | + lambda test_file: f"{test_file.path}.{test_file.type}/", |
| 47 | + "Path .* format is invalid", |
| 48 | + "Extension and trailing slash", |
| 49 | + ), |
| 50 | + ( |
| 51 | + lambda test_file: f"/{test_file.path}.{test_file.type}", |
| 52 | + "Path .* format is invalid", |
| 53 | + "Extension and leading slash", |
| 54 | + ), |
| 55 | + ], |
| 56 | + ids=lambda x: x[2] if isinstance(x, tuple) else x, # Use test_case_description as the test ID in pytest output |
| 57 | +) |
10 | 58 | def test_path_validation( |
11 | 59 | get_humanloop_client: GetHumanloopClientFn, |
12 | 60 | syncable_files_fixture: list[SyncableFile], |
13 | 61 | tmp_path: Path, |
| 62 | + path_generator: callable, |
| 63 | + expected_error: str, |
| 64 | + test_case_description: str, |
14 | 65 | ): |
15 | 66 | """Test validation of path formats for local file operations.""" |
16 | 67 | # GIVEN a client with local files enabled and remote files pulled |
17 | 68 | humanloop_client = get_humanloop_client(use_local_files=True, local_files_directory=str(tmp_path)) |
18 | 69 | humanloop_client.pull() |
19 | 70 | test_file = syncable_files_fixture[0] |
20 | 71 |
|
21 | | - # WHEN using paths with file extensions (of any case/format) |
22 | | - extension_paths = [ |
23 | | - f"{test_file.path}.{test_file.type}", # Standard extension |
24 | | - f"{test_file.path}.{test_file.type.upper()}", # Uppercase extension |
25 | | - f"{test_file.path}.{test_file.type.capitalize()}", # Mixed case extension |
26 | | - f" {test_file.path}.{test_file.type} ", # With whitespace |
27 | | - ] |
28 | | - |
29 | | - # THEN appropriate error should be raised about file extensions |
30 | | - for path in extension_paths: |
31 | | - with pytest.raises(HumanloopRuntimeError, match="includes a file extension which is not supported"): |
32 | | - if test_file.type == "prompt": |
33 | | - humanloop_client.prompts.call(path=path, messages=[{"role": "user", "content": "Testing"}]) |
34 | | - elif test_file.type == "agent": |
35 | | - humanloop_client.agents.call(path=path, messages=[{"role": "user", "content": "Testing"}]) |
36 | | - |
37 | | - # WHEN using paths with leading/trailing slashes |
38 | | - slash_paths = [ |
39 | | - f"{test_file.path}/", # Trailing slash |
40 | | - f"/{test_file.path}", # Leading slash |
41 | | - f"/{test_file.path}/", # Both leading and trailing slashes |
42 | | - f"//{test_file.path}//", # Multiple leading and trailing slashes |
43 | | - ] |
44 | | - |
45 | | - # THEN appropriate error should be raised about slashes |
46 | | - for path in slash_paths: |
47 | | - with pytest.raises(HumanloopRuntimeError, match="Path .* format is invalid"): |
48 | | - if test_file.type == "prompt": |
49 | | - humanloop_client.prompts.call(path=path, messages=[{"role": "user", "content": "Testing"}]) |
50 | | - elif test_file.type == "agent": |
51 | | - humanloop_client.agents.call(path=path, messages=[{"role": "user", "content": "Testing"}]) |
52 | | - |
53 | | - # WHEN using paths with both extensions and slashes |
54 | | - combined_paths = [ |
55 | | - f"{test_file.path}.{test_file.type}/", # Extension and trailing slash |
56 | | - f"/{test_file.path}.{test_file.type}", # Extension and leading slash |
57 | | - ] |
58 | | - |
59 | | - # THEN the format validation error should be raised first (before extension validation) |
60 | | - for path in combined_paths: |
61 | | - with pytest.raises(HumanloopRuntimeError, match="Path .* format is invalid"): |
62 | | - if test_file.type == "prompt": |
63 | | - humanloop_client.prompts.call(path=path, messages=[{"role": "user", "content": "Testing"}]) |
64 | | - elif test_file.type == "agent": |
65 | | - humanloop_client.agents.call(path=path, messages=[{"role": "user", "content": "Testing"}]) |
| 72 | + # WHEN using the test path |
| 73 | + test_path = path_generator(test_file) |
| 74 | + |
| 75 | + # THEN appropriate error should be raised |
| 76 | + with pytest.raises(HumanloopRuntimeError, match=expected_error): |
| 77 | + if test_file.type == "prompt": |
| 78 | + humanloop_client.prompts.call(path=test_path, messages=[{"role": "user", "content": "Testing"}]) |
| 79 | + elif test_file.type == "agent": |
| 80 | + humanloop_client.agents.call(path=test_path, messages=[{"role": "user", "content": "Testing"}]) |
66 | 81 |
|
67 | 82 |
|
68 | 83 | def test_local_file_call( |
|
0 commit comments