File: test_option.py

package info (click to toggle)
python-flake8 7.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,212 kB
  • sloc: python: 6,592; sh: 21; makefile: 19
file content (57 lines) | stat: -rw-r--r-- 1,713 bytes parent folder | download
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
"""Unit tests for flake8.options.manager.Option."""
from __future__ import annotations

import functools
from unittest import mock

import pytest

from flake8.options import manager


def test_to_argparse():
    """Test conversion to an argparse arguments."""
    opt = manager.Option(
        short_option_name="-t",
        long_option_name="--test",
        action="count",
        parse_from_config=True,
        normalize_paths=True,
    )
    assert opt.normalize_paths is True
    assert opt.parse_from_config is True

    args, kwargs = opt.to_argparse()
    assert args == ["-t", "--test"]
    assert kwargs == {"action": "count", "type": mock.ANY}
    assert isinstance(kwargs["type"], functools.partial)


def test_to_argparse_creates_an_option_as_we_expect():
    """Show that we pass all keyword args to argparse."""
    opt = manager.Option("-t", "--test", action="count")
    args, kwargs = opt.to_argparse()
    assert args == ["-t", "--test"]
    assert kwargs == {"action": "count"}


def test_config_name_generation():
    """Show that we generate the config name deterministically."""
    opt = manager.Option(
        long_option_name="--some-very-long-option-name",
        parse_from_config=True,
    )

    assert opt.config_name == "some_very_long_option_name"


def test_config_name_needs_long_option_name():
    """Show that we error out if the Option should be parsed from config."""
    with pytest.raises(ValueError):
        manager.Option("-s", parse_from_config=True)


def test_dest_is_not_overridden():
    """Show that we do not override custom destinations."""
    opt = manager.Option("-s", "--short", dest="something_not_short")
    assert opt.dest == "something_not_short"