def test_config_file_and_override(tmpdir):
    """Test command line args override config file args."""
    cfg_file = str(tmpdir.mkdir("config_file").join("config.cfg"))
    with open(cfg_file, "w") as f:
        f.write("""[Defaults]
        input=in
        output=out
        log-level=CRITICAL""")
    args = _parse_args(["-c={}".format(cfg_file), "--input=override"])

    assert "override" == args.input
def test_defaults():
    """Test default parameters."""
    args = _parse_args(["--input=in", "--output=out"])
    assert "in" == args.input
    assert "out" == args.output
    assert not args.anonymize_passwords
    assert not args.anonymize_ips
    assert args.dump_ip_map is None
    assert "INFO" == args.log_level
    assert args.salt is None
    assert not args.undo
    assert args.sensitive_words is None
def test_config_file(tmpdir):
    """Test config file args are parsed."""
    cfg_file = str(tmpdir.mkdir("config_file").join("config.cfg"))
    with open(cfg_file, "w") as f:
        f.write("""[Defaults]
        input=in
        output=out
        log-level=CRITICAL""")
    args = _parse_args(["-c={}".format(cfg_file)])

    assert "in" == args.input
    assert "out" == args.output
    assert not args.anonymize_passwords
    assert not args.anonymize_ips
    assert args.dump_ip_map is None
    assert "CRITICAL" == args.log_level
    assert args.salt is None
    assert not args.undo
    assert args.sensitive_words is None
def test_no_config_file():
    """Test command line args are parsed."""
    args = _parse_args([
        "--input=in",
        "--output=out",
        "--anonymize-passwords",
        "--anonymize-ips",
        "--dump-ip-map=dump",
        "--log-level=CRITICAL",
        "--salt=salty",
        "--undo",
        "--sensitive-words=secret,password",
    ])

    assert "in" == args.input
    assert "out" == args.output
    assert args.anonymize_passwords
    assert args.anonymize_ips
    assert "dump" == args.dump_ip_map
    assert "CRITICAL" == args.log_level
    assert "salty" == args.salt
    assert args.undo
    assert "secret,password" == args.sensitive_words