File: test_config.py

package info (click to toggle)
iredis 1.15.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,244 kB
  • sloc: python: 7,196; sh: 16; makefile: 14
file content (59 lines) | stat: -rw-r--r-- 1,467 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
55
56
57
58
59
import pexpect
from textwrap import dedent
from pathlib import Path


def test_log_location_config():
    config_content = dedent(
        """
        [main]
        log_location = /tmp/iredis1.log
        """
    )
    with open("/tmp/iredisrc", "w+") as etc_config:
        etc_config.write(config_content)

    cli = pexpect.spawn("iredis -n 15 --iredisrc /tmp/iredisrc", timeout=1)
    cli.expect("127.0.0.1")
    cli.close()

    log = Path("/tmp/iredis1.log")
    assert log.exists()
    with open(log) as logfile:
        content = logfile.read()

    assert len(content) > 100


def test_load_prompt_from_config(iredis_client, clean_redis):
    config_content = dedent(
        """
        [main]
        prompt = {host}abc{port}xx{db}
        """
    )
    with open("/tmp/iredisrc", "w+") as etc_config:
        etc_config.write(config_content)

    cli = pexpect.spawn("iredis -n 15 --iredisrc /tmp/iredisrc", timeout=1)
    cli.expect("iredis")
    cli.expect("127.0.0.1abc6379xx15")
    cli.close()


def test_prompt_cli_overwrite_config(iredis_client, clean_redis):
    config_content = dedent(
        """
        [main]
        prompt = {host}abc{port}xx{db}
        """
    )
    with open("/tmp/iredisrc", "w+") as etc_config:
        etc_config.write(config_content)

    cli = pexpect.spawn(
        "iredis -n 15 --iredisrc /tmp/iredisrc --prompt='{db}-12345'", timeout=1
    )
    cli.expect("iredis")
    cli.expect("15-12345")
    cli.close()