File: test_client.py

package info (click to toggle)
python-wyoming 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 376 kB
  • sloc: python: 3,025; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 1,031 bytes parent folder | download
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
"""Client tests."""

from pathlib import Path

import pytest

from wyoming.client import (
    AsyncClient,
    AsyncStdioClient,
    AsyncTcpClient,
    AsyncUnixClient,
)


def test_from_uri() -> None:
    """Test AsyncClient.from_uri"""
    # Bad scheme
    with pytest.raises(ValueError):
        AsyncClient.from_uri("ftp://127.0.0.1:5000")

    # Missing hostname
    with pytest.raises(ValueError):
        AsyncClient.from_uri("tcp://:5000")

    # Missing port
    with pytest.raises(ValueError):
        AsyncClient.from_uri("tcp://127.0.0.1")

    stdio_client = AsyncClient.from_uri("stdio://")
    assert isinstance(stdio_client, AsyncStdioClient)

    tcp_client = AsyncClient.from_uri("tcp://127.0.0.1:5000")
    assert isinstance(tcp_client, AsyncTcpClient)
    assert tcp_client.host == "127.0.0.1"
    assert tcp_client.port == 5000

    unix_client = AsyncClient.from_uri("unix:///path/to/socket")
    assert isinstance(unix_client, AsyncUnixClient)
    assert unix_client.socket_path == Path("/path/to/socket")