From 1e9878611a93b3af583e222a15c0b4575fc4f027 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Sat, 9 Jan 2016 12:55:31 -0600 Subject: [PATCH] Move unit tests into tests/unit --- tests/unit/__init__.py | 0 tests/{ => unit}/test_notifier.py | 0 tests/unit/test_option.py | 52 +++++++++++++++++++++++++++++++ tests/{ => unit}/test_trie.py | 0 4 files changed, 52 insertions(+) create mode 100644 tests/unit/__init__.py rename tests/{ => unit}/test_notifier.py (100%) create mode 100644 tests/unit/test_option.py rename tests/{ => unit}/test_trie.py (100%) diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_notifier.py b/tests/unit/test_notifier.py similarity index 100% rename from tests/test_notifier.py rename to tests/unit/test_notifier.py diff --git a/tests/unit/test_option.py b/tests/unit/test_option.py new file mode 100644 index 0000000..d1491eb --- /dev/null +++ b/tests/unit/test_option.py @@ -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' diff --git a/tests/test_trie.py b/tests/unit/test_trie.py similarity index 100% rename from tests/test_trie.py rename to tests/unit/test_trie.py