Example #1
0
def test_styleguide_input_file():
    """Verify we call StyleGuide.check_files with the filename."""
    app = mock.Mock()
    style_guide = api.StyleGuide(app)
    with mock.patch.object(style_guide, 'check_files') as check_files:
        style_guide.input_file('file.py')
    check_files.assert_called_once_with(['file.py'])
Example #2
0
def test_styleguide_init_report_does_nothing():
    """Verify if we use None that we don't call anything."""
    app = mock.Mock()
    style_guide = api.StyleGuide(app)
    style_guide.init_report()
    assert app.make_formatter.called is False
    assert app.make_guide.called is False
Example #3
0
def test_styleguide_init_report_with_non_subclass():
    """Verify we raise a ValueError with non BaseFormatter subclasses."""
    app = mock.Mock()
    style_guide = api.StyleGuide(app)
    with pytest.raises(ValueError):
        style_guide.init_report(object)
    assert app.make_formatter.called is False
    assert app.make_guide.called is False
Example #4
0
def test_styleguide_check_files():
    """Verify we call the right application methods."""
    paths = ['foo', 'bar']
    app = mock.Mock()
    style_guide = api.StyleGuide(app)
    report = style_guide.check_files(paths)

    app.run_checks.assert_called_once_with(paths)
    app.report_errors.assert_called_once_with()
    assert isinstance(report, api.Report)
Example #5
0
def test_styleguide_excluded():
    """Verify we delegate to our file checker manager.

    We also want to ensure that if we don't specify a parent, is_path_excluded
    is called exactly once.
    """
    app = mock.Mock()
    file_checker_manager = app.file_checker_manager = mock.Mock()
    style_guide = api.StyleGuide(app)

    style_guide.excluded('file.py')
    file_checker_manager.is_path_excluded.assert_called_once_with('file.py')
Example #6
0
def test_styleguide_init_report():
    """Verify we do the right incantation for the Application."""
    app = mock.Mock(guide='fake')
    style_guide = api.StyleGuide(app)

    class FakeFormatter(formatter.BaseFormatter):
        def format(self, *args):
            pass

    style_guide.init_report(FakeFormatter)
    app.make_formatter.assert_called_once_with(FakeFormatter)
    assert app.guide is None
    app.make_guide.assert_called_once_with()
Example #7
0
def test_styleguide_excluded_with_parent():
    """Verify we delegate to our file checker manager.

    When we add the parent argument, we don't check that is_path_excluded was
    called only once.
    """
    app = mock.Mock()
    file_checker_manager = app.file_checker_manager = mock.Mock()
    style_guide = api.StyleGuide(app)

    style_guide.excluded('file.py', 'parent')
    file_checker_manager.is_path_excluded.call_args == [
        ('file.py',),
        ('parent/file.py',),
    ]
Example #8
0
def test_styleguide_excluded_with_parent():
    """Verify we delegate to our file checker manager.

    When we add the parent argument, we don't check that is_path_excluded was
    called only once.
    """
    app = mock.Mock()
    file_checker_manager = app.file_checker_manager = mock.Mock()
    file_checker_manager.is_path_excluded.return_value = False
    style_guide = api.StyleGuide(app)

    style_guide.excluded("file.py", "parent")
    assert file_checker_manager.is_path_excluded.call_args_list == [
        mock.call("file.py"),
        mock.call(os.path.join("parent", "file.py")),
    ]
Example #9
0
def test_styleguide_paths():
    """Show tha we proxy the StyleGuide.paths attribute."""
    app = mock.Mock()
    app.paths = 'paths'
    style_guide = api.StyleGuide(app)
    assert style_guide.paths == 'paths'
Example #10
0
def test_styleguide_options():
    """Show tha we proxy the StyleGuide.options attribute."""
    app = mock.Mock()
    app.options = 'options'
    style_guide = api.StyleGuide(app)
    assert style_guide.options == 'options'