[GEMINI] Add test cases for ctf flag -l/--list and -s/--set options
This commit is contained in:
@@ -70,3 +70,58 @@ def test_flag_cmd_exemption(capsys):
|
|||||||
finally:
|
finally:
|
||||||
write_config(original_config, str(config_file))
|
write_config(original_config, str(config_file))
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
# {{{ test_flag_cmd_list_format
|
||||||
|
def test_flag_cmd_list_format():
|
||||||
|
"""
|
||||||
|
Verifies that ctf flag --list / -l prints the current flag format.
|
||||||
|
"""
|
||||||
|
from ctf.main import cli
|
||||||
|
|
||||||
|
config_file = Path("/home/venus/code/ctf/config.toml")
|
||||||
|
original_config = load_config(str(config_file))
|
||||||
|
|
||||||
|
try:
|
||||||
|
temp_config = load_config(str(config_file))
|
||||||
|
if "Competition" not in temp_config:
|
||||||
|
temp_config["Competition"] = {}
|
||||||
|
temp_config["Competition"]["flag_format"] = "TEST_FORMAT{[a-z]+}"
|
||||||
|
write_config(temp_config, str(config_file))
|
||||||
|
|
||||||
|
runner = CliRunner()
|
||||||
|
|
||||||
|
# Test standard output
|
||||||
|
result = runner.invoke(cli, ["flag", "-l"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "Current flag format: TEST_FORMAT{[a-z]+}" in result.output
|
||||||
|
|
||||||
|
# Test plain output
|
||||||
|
result_plain = runner.invoke(cli, ["flag", "-l", "-p"])
|
||||||
|
assert result_plain.exit_code == 0
|
||||||
|
assert result_plain.output.strip() == "TEST_FORMAT{[a-z]+}"
|
||||||
|
finally:
|
||||||
|
write_config(original_config, str(config_file))
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
# {{{ test_flag_cmd_set_format
|
||||||
|
def test_flag_cmd_set_format():
|
||||||
|
"""
|
||||||
|
Verifies that ctf flag --set / -s updates the flag format in config.toml.
|
||||||
|
"""
|
||||||
|
from ctf.main import cli
|
||||||
|
|
||||||
|
config_file = Path("/home/venus/code/ctf/config.toml")
|
||||||
|
original_config = load_config(str(config_file))
|
||||||
|
|
||||||
|
try:
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(cli, ["flag", "-s", "NEW_FLAG_FORMAT{[0-9]+}"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "Flag format set to: NEW_FLAG_FORMAT{[0-9]+}" in result.output
|
||||||
|
|
||||||
|
updated_config = load_config(str(config_file))
|
||||||
|
assert updated_config["Competition"]["flag_format"] == "NEW_FLAG_FORMAT{[0-9]+}"
|
||||||
|
finally:
|
||||||
|
write_config(original_config, str(config_file))
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user