File: test_helper.py

package info (click to toggle)
pymodbus 3.8.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,720 kB
  • sloc: python: 14,867; makefile: 27; sh: 17
file content (54 lines) | stat: -rw-r--r-- 1,639 bytes parent folder | download | duplicates (2)
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
50
51
52
53
54
"""Test example helper function."""
from unittest import mock

import pytest

from examples import helper


class TestHelperExamples:
    """Test helper functions in examples."""

    def test_commandline_server_defaults(self):
        """Test defaults."""
        args = helper.get_commandline(server=True, cmdline=[])
        assert args.comm == "tcp"
        assert args.log == "info"
        assert args.baudrate == 9600
        assert args.framer
        assert args.port
        assert args.store
        assert not args.slaves
        assert not args.context

    def test_commandline_client_defaults(self):
        """Test defaults."""
        args = helper.get_commandline(server=False, cmdline=[])
        assert args.comm == "tcp"
        assert args.log == "info"
        assert args.baudrate == 9600
        assert args.host == "127.0.0.1"
        assert args.framer
        assert args.port

    def test_commandline(self):
        """Test defaults."""
        args = helper.get_commandline(
            server=False, cmdline=["--log", "debug", "--comm", "udp"]
        )
        assert args.comm == "udp"
        assert args.log == "debug"

    @pytest.mark.parametrize("suffix", ["crt", "key"])
    def test_certificate(self, suffix):
        """Test certificate."""
        path = helper.get_certificate(suffix)
        with open(path, encoding="utf-8"):
            pass

    def test_certificate_illegal(self):
        """Test illegal path."""
        with mock.patch(
            "examples.helper.os.getcwd", return_value="no/good/path"
        ), pytest.raises(RuntimeError):
            helper.get_certificate("crt")