Debian Codegraph @

tests/cli_tests/test_config.py

raw
1 import pexpect
2 from textwrap import dedent
3 from pathlib import Path
4
5
6 def test_log_location_config():
7 config_content = dedent(
8 """
9 [main]
10 log_location = /tmp/iredis1.log
11 """
12 )
13 with open("/tmp/iredisrc", "w+") as etc_config:
14 etc_config.write(config_content)
15
16 cli = pexpect.spawn("iredis -n 15 --iredisrc /tmp/iredisrc", timeout=1)
17 cli.expect("127.0.0.1")
18 cli.close()
19
20 log = Path("/tmp/iredis1.log")
21 assert log.exists()
22 with open(log) as logfile:
23 content = logfile.read()
24
25 assert len(content) > 100
26
27
28 def test_load_prompt_from_config(iredis_client, clean_redis):
29 config_content = dedent(
30 """
31 [main]
32 prompt = {host}abc{port}xx{db}
33 """
34 )
35 with open("/tmp/iredisrc", "w+") as etc_config:
36 etc_config.write(config_content)
37
38 cli = pexpect.spawn("iredis -n 15 --iredisrc /tmp/iredisrc", timeout=1)
39 cli.expect("iredis")
40 cli.expect("127.0.0.1abc6379xx15")
41 cli.close()
42
43
44 def test_prompt_cli_overwrite_config(iredis_client, clean_redis):
45 config_content = dedent(
46 """
47 [main]
48 prompt = {host}abc{port}xx{db}
49 """
50 )
51 with open("/tmp/iredisrc", "w+") as etc_config:
52 etc_config.write(config_content)
53
54 cli = pexpect.spawn(
55 "iredis -n 15 --iredisrc /tmp/iredisrc --prompt='{db}-12345'", timeout=1
56 )
57 cli.expect("iredis")
58 cli.expect("15-12345")
59 cli.close()