File size: 2,063 Bytes
7931de6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging

import pytest

from pytriton.client.exceptions import PyTritonClientInvalidUrlError
from pytriton.client.utils import TritonUrl

logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger("test_client_utils")


def test_parse_triton_url_correctly():
    assert TritonUrl.from_url("localhost:8000") == TritonUrl("http", "localhost", 8000)
    assert TritonUrl.from_url("localhost") == TritonUrl("http", "localhost", 8000)
    assert TritonUrl.from_url("http://abc:8000") == TritonUrl("http", "abc", 8000)
    assert TritonUrl.from_url("grpc://cde:8008") == TritonUrl("grpc", "cde", 8008)
    assert TritonUrl.from_url("http://efg") == TritonUrl("http", "efg", 8000)
    assert TritonUrl.from_url("grpc://ghi") == TritonUrl("grpc", "ghi", 8001)


def test_parse_triton_url_raise_exception_when_schema_is_not_supported():
    with pytest.raises(PyTritonClientInvalidUrlError):
        TritonUrl.from_url("ftp://localhost:8000")
    with pytest.raises(PyTritonClientInvalidUrlError):
        TritonUrl.from_url("https://localhost")


def test_triton_url_with_schema():
    assert TritonUrl.from_url("localhost").with_scheme == "http://localhost:8000"
    assert TritonUrl.from_url("grpc://some:9090").with_scheme == "grpc://some:9090"


def test_triton_url_without_schema():
    assert TritonUrl.from_url("localhost").without_scheme == "localhost:8000"
    assert TritonUrl.from_url("grpc://some:9090").without_scheme == "some:9090"