Skip to content

Commit

Permalink
Added violation tests and violation code tests. FIxes wemake-services#12
Browse files Browse the repository at this point in the history
  • Loading branch information
CCS-Tech committed Jun 15, 2019
2 parents 53b26f6 + 4e8911d commit e84bbbf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ We follow Semantic Versions.


## Version 0.1.2

### Bugfixes

- Fixes issue with empty comments

### Misc
Expand Down
26 changes: 26 additions & 0 deletions tests/test_violations/test_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-


def test_all_violations_are_documented(all_module_violations):
"""Ensures that all violations are documented"""
for module, classes in all_module_violations.items():
for violantion_class in classes:
# Once per `summary` and once for `autoclass`
assert module.__doc__.count(violantion_class.__qualname__) == 2

def test_all_violations_have_versionadded(all_violations):
"""Ensures that all violations have `versionadded` tag"""
for violation in all_violations:
assert '..versionadded' in violation.__doc__

def test_violation_name(all_violations):
"""Ensures all violations have `Violation` suffix"""
for violation in all_violations:
class_name = violation.__qualname__
assert class_name.endswith('Violation'), class_name

def test_configuration(all_violations):
"""Ensures all configuration options are listed in the docs."""
#TODO. This function relies on a configuration file that has yet to be
#completed and implemented.
return None
20 changes: 20 additions & 0 deletions tests/test_violations/test_implementation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

import ast

from dotenv_linter.violations.base import (
BaseViolation,
BaseFSTViolation,
BaseFileViolation,
)

def test_visitor_returns_location():
"""Ensures that `BaseNodeVisitor` return correct violation message."""
visitor = BaseFSTViolation(node=ast.parse(''), text='violation')
visitor.error_template = '{0}'
visitor.code = 1
assert visitor._node() == (0, 0, 'Z001 violation')

def test_checker_default_locations():
"""Ensures that `BaseViolation` returns correct location. """
assert BaseViolation(None, None).location() == (0, 0) #noqa: Z441

0 comments on commit e84bbbf

Please sign in to comment.