Skip to content

Commit 6e65f39

Browse files
committed
Add tests for untested helpers in weaviate.util
Covers _capitalize_first_letter (empty, single-character, and the "only the first character is changed" behaviour), is_weaviate_domain (the weaviate.io / weaviate.cloud / semi.technology matches, case insensitivity, and non-Weaviate URLs), and strip_newlines.
1 parent 17a9887 commit 6e65f39

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

test/test_util.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from weaviate.exceptions import SchemaValidationException
1111
from weaviate.util import (
1212
MINIMUM_NO_WARNING_VERSION,
13+
_capitalize_first_letter,
1314
_datetime_from_weaviate_str,
1415
_is_sub_schema,
1516
_sanitize_str,
@@ -21,9 +22,11 @@
2122
image_encoder_b64,
2223
is_object_url,
2324
is_weaviate_client_too_old,
25+
is_weaviate_domain,
2426
is_weaviate_object_url,
2527
is_weaviate_too_old,
2628
parse_version_string,
29+
strip_newlines,
2730
)
2831

2932
schema_set = {
@@ -495,3 +498,52 @@ def test_is_weaviate_client_too_old(current_version: str, latest_version: str, t
495498
)
496499
def test_sanitize_str(in_str: str, out_str: str) -> None:
497500
assert _sanitize_str(in_str) == f'"{out_str}"'
501+
502+
503+
@pytest.mark.parametrize(
504+
"value,expected",
505+
[
506+
("", ""),
507+
("a", "A"),
508+
("z", "Z"),
509+
("hi", "Hi"),
510+
# Only the first character is touched; the remainder is left as-is.
511+
("hELLO", "HELLO"),
512+
("Hello", "Hello"),
513+
("1abc", "1abc"),
514+
],
515+
)
516+
def test_capitalize_first_letter(value: str, expected: str) -> None:
517+
assert _capitalize_first_letter(value) == expected
518+
519+
520+
@pytest.mark.parametrize(
521+
"url,expected",
522+
[
523+
("https://my-cluster.weaviate.io", True),
524+
("https://my-cluster.weaviate.cloud", True),
525+
("https://foo.semi.technology", True),
526+
# Matching is case-insensitive.
527+
("https://MY-CLUSTER.WEAVIATE.CLOUD", True),
528+
("http://localhost:8080", False),
529+
("https://example.com", False),
530+
("", False),
531+
],
532+
)
533+
def test_is_weaviate_domain(url: str, expected: bool) -> None:
534+
assert is_weaviate_domain(url) is expected
535+
536+
537+
@pytest.mark.parametrize(
538+
"value,expected",
539+
[
540+
("no newlines", "no newlines"),
541+
("one\nnewline", "one newline"),
542+
("a\nb\nc", "a b c"),
543+
("\nleading", " leading"),
544+
("trailing\n", "trailing "),
545+
("", ""),
546+
],
547+
)
548+
def test_strip_newlines(value: str, expected: str) -> None:
549+
assert strip_newlines(value) == expected

0 commit comments

Comments
 (0)