mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-03 19:56:54 +00:00
Move unit tests into tests/unit
This commit is contained in:
parent
93369e112f
commit
1e9878611a
4 changed files with 52 additions and 0 deletions
0
tests/unit/__init__.py
Normal file
0
tests/unit/__init__.py
Normal file
52
tests/unit/test_option.py
Normal file
52
tests/unit/test_option.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
"""Unit tests for flake8.options.manager.Option."""
|
||||
import mock
|
||||
|
||||
from flake8.options import manager
|
||||
|
||||
|
||||
def test_to_optparse():
|
||||
"""Test conversion to an optparse.Option class."""
|
||||
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
|
||||
|
||||
optparse_opt = opt.to_optparse()
|
||||
assert not hasattr(optparse_opt, 'parse_from_config')
|
||||
assert not hasattr(optparse_opt, 'normalize_paths')
|
||||
assert optparse_opt.action == 'count'
|
||||
|
||||
|
||||
@mock.patch('optparse.Option')
|
||||
def test_to_optparse_creates_an_option_as_we_expect(Option):
|
||||
"""Show that we pass all keyword args to optparse.Option."""
|
||||
opt = manager.Option('-t', '--test', action='count')
|
||||
opt.to_optparse()
|
||||
option_kwargs = {
|
||||
'action': 'count',
|
||||
'default': None,
|
||||
'type': None,
|
||||
'dest': None,
|
||||
'callback': None,
|
||||
'callback_args': None,
|
||||
'callback_kwargs': None,
|
||||
'help': None,
|
||||
'metavar': None,
|
||||
}
|
||||
|
||||
Option.assert_called_once_with(
|
||||
'-t', '--test', **option_kwargs
|
||||
)
|
||||
|
||||
|
||||
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'
|
||||
Loading…
Add table
Add a link
Reference in a new issue