Adding first rules for entities.
This commit is contained in:
parent
63a5340b30
commit
ad23aefa77
|
|
@ -0,0 +1,159 @@
|
|||
|
||||
import rule
|
||||
import re
|
||||
|
||||
|
||||
class entity_rule(rule.rule):
|
||||
|
||||
def __init__(self):
|
||||
rule.rule.__init__(self)
|
||||
self.name = 'entity'
|
||||
|
||||
|
||||
class rule_001(entity_rule):
|
||||
'''Entity rule 001 checks for spaces before the entity keyword.'''
|
||||
|
||||
def __init__(self):
|
||||
entity_rule.__init__(self)
|
||||
self.identifier = '001'
|
||||
self.description = 'Remove spaces before entity keyword.'
|
||||
|
||||
def analyze(self, lines):
|
||||
lFailureLines = []
|
||||
for iLineNumber, sLine in enumerate(lines):
|
||||
if re.match('^\s\s*entity', sLine.lower()):
|
||||
lFailureLines.append(iLineNumber + 1)
|
||||
self.violations = lFailureLines
|
||||
|
||||
|
||||
class rule_002(entity_rule):
|
||||
'''Entity rule 002 checks for a single space after the entity keyword.'''
|
||||
|
||||
def __init__(self):
|
||||
entity_rule.__init__(self)
|
||||
self.identifier = '002'
|
||||
self.description = 'Remove extra spaces after entity keyword.'
|
||||
|
||||
def analyze(self, lines):
|
||||
lFailureLines = []
|
||||
for iLineNumber, sLine in enumerate(lines):
|
||||
if re.match('^\s*entity\s\s+', sLine.lower()):
|
||||
lFailureLines.append(iLineNumber + 1)
|
||||
self.violations = lFailureLines
|
||||
|
||||
|
||||
class rule_003(entity_rule):
|
||||
'''Entity rule 003 checks for a blank line above the entity keyword.'''
|
||||
|
||||
def __init__(self):
|
||||
entity_rule.__init__(self)
|
||||
self.identifier = '003'
|
||||
self.description = 'Add blank line above entity keyword.'
|
||||
|
||||
def analyze(self, lines):
|
||||
lFailureLines = []
|
||||
for iLineNumber, sLine in enumerate(lines):
|
||||
if re.match('^\s*entity', sLine.lower()):
|
||||
if not re.match('^\s*$', lines[iLineNumber - 1]):
|
||||
lFailureLines.append(iLineNumber + 1)
|
||||
self.violations = lFailureLines
|
||||
|
||||
|
||||
class rule_004(entity_rule):
|
||||
'''Entity rule 004 checks the entity keyword is lower case.'''
|
||||
|
||||
def __init__(self):
|
||||
entity_rule.__init__(self)
|
||||
self.identifier = '004'
|
||||
self.description = 'Change entity keyword to lowercase.'
|
||||
|
||||
def analyze(self, lines):
|
||||
lFailureLines = []
|
||||
for iLineNumber, sLine in enumerate(lines):
|
||||
if re.match('^\s*entity', sLine.lower()):
|
||||
if not re.match('^\s*entity', sLine):
|
||||
lFailureLines.append(iLineNumber + 1)
|
||||
self.violations = lFailureLines
|
||||
|
||||
|
||||
class rule_005(entity_rule):
|
||||
'''Entity rule 005 checks the is keyword is on the same line as the entity keyword.'''
|
||||
|
||||
def __init__(self):
|
||||
entity_rule.__init__(self)
|
||||
self.identifier = '005'
|
||||
self.description = 'Add "is" keyword to same line as "entity" keyword.'
|
||||
|
||||
def analyze(self, lines):
|
||||
lFailureLines = []
|
||||
for iLineNumber, sLine in enumerate(lines):
|
||||
if re.match('^\s*entity', sLine.lower()):
|
||||
if not re.match('^.*\s\s*is', sLine.lower()):
|
||||
lFailureLines.append(iLineNumber + 1)
|
||||
self.violations = lFailureLines
|
||||
|
||||
class rule_006(entity_rule):
|
||||
'''Entity rule 006 checks the "is" keyword is lower case.'''
|
||||
|
||||
def __init__(self):
|
||||
entity_rule.__init__(self)
|
||||
self.identifier = '006'
|
||||
self.description = 'Change entity keyword to lowercase.'
|
||||
|
||||
def analyze(self, lines):
|
||||
lFailureLines = []
|
||||
for iLineNumber, sLine in enumerate(lines):
|
||||
if re.match('^\s*entity', sLine.lower()):
|
||||
if not re.match('^.*\s\s*is', sLine):
|
||||
lFailureLines.append(iLineNumber + 1)
|
||||
self.violations = lFailureLines
|
||||
|
||||
class rule_007(entity_rule):
|
||||
'''Entity rule 007 checks for a single space before the "is" keyword.'''
|
||||
|
||||
def __init__(self):
|
||||
entity_rule.__init__(self)
|
||||
self.identifier = '007'
|
||||
self.description = 'Remove extra spaces before "is" keyword.'
|
||||
|
||||
def analyze(self, lines):
|
||||
lFailureLines = []
|
||||
for iLineNumber, sLine in enumerate(lines):
|
||||
if re.match('^\s*entity', sLine.lower()):
|
||||
if re.match('^.*\s\s+is', sLine.lower()):
|
||||
lFailureLines.append(iLineNumber + 1)
|
||||
self.violations = lFailureLines
|
||||
|
||||
|
||||
#class rule_007(entity_rule):
|
||||
# '''Entity rule 007 checks for a blank line above the entity keyword.'''
|
||||
#
|
||||
# def __init__(self):
|
||||
# entity_rule.__init__(self)
|
||||
# self.identifier = '007'
|
||||
# self.description = 'Remove blank line above use keyword.'
|
||||
#
|
||||
# def analyze(self, lines):
|
||||
# lFailureLines = []
|
||||
# for iLineNumber, sLine in enumerate(lines):
|
||||
# if re.match('^\s*use', sLine.lower()):
|
||||
# if re.match('^\s*$', lines[iLineNumber - 1]):
|
||||
# lFailureLines.append(iLineNumber + 1)
|
||||
# self.violations = lFailureLines
|
||||
#
|
||||
#
|
||||
#class rule_008(entity_rule):
|
||||
# '''Entity rule 008 checks indentation of the use keyword.'''
|
||||
#
|
||||
# def __init__(self):
|
||||
# entity_rule.__init__(self)
|
||||
# self.identifier = '008'
|
||||
# self.description = 'Change indent of use keyword to 2 spaces.'
|
||||
#
|
||||
# def analyze(self, lines):
|
||||
# lFailureLines = []
|
||||
# for iLineNumber, sLine in enumerate(lines):
|
||||
# if re.match('^\s*use', sLine.lower()):
|
||||
# if not re.match('^\s\suse', sLine.lower()):
|
||||
# lFailureLines.append(iLineNumber + 1)
|
||||
# self.violations = lFailureLines
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
|
||||
import sys
|
||||
sys.path.append('..\..')
|
||||
import unittest
|
||||
import rule_entity
|
||||
import os
|
||||
|
||||
|
||||
class testRuleEntityMethods(unittest.TestCase):
|
||||
|
||||
def test_rule_001_exists(self):
|
||||
oRule = rule_entity.rule_001()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'entity')
|
||||
self.assertEqual(oRule.identifier, '001')
|
||||
|
||||
def test_rule_001(self):
|
||||
oRule = rule_entity.rule_001()
|
||||
|
||||
dExpected = [2,4]
|
||||
lLines = []
|
||||
lLines.append(' This is a test of ending entity')
|
||||
lLines.append(' entity ')
|
||||
lLines.append('entity')
|
||||
lLines.append(' Entity ')
|
||||
lLines.append('Entity')
|
||||
oRule.analyze(lLines)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
def test_rule_002_exists(self):
|
||||
oRule = rule_entity.rule_002()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'entity')
|
||||
self.assertEqual(oRule.identifier, '002')
|
||||
|
||||
def test_rule_002(self):
|
||||
oRule = rule_entity.rule_002()
|
||||
|
||||
dExpected = [3,5]
|
||||
lLines = []
|
||||
lLines.append(' This is a test of ending entity')
|
||||
lLines.append(' entity blah is')
|
||||
lLines.append('entity blah is')
|
||||
lLines.append(' Entity blah is ')
|
||||
lLines.append('Entity blah is')
|
||||
oRule.analyze(lLines)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
def test_rule_003_exists(self):
|
||||
oRule = rule_entity.rule_003()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'entity')
|
||||
self.assertEqual(oRule.identifier, '003')
|
||||
|
||||
def test_rule_003(self):
|
||||
oRule = rule_entity.rule_003()
|
||||
|
||||
dExpected = [4,8]
|
||||
lLines = []
|
||||
lLines.append(' This is a test of ending entity')
|
||||
lLines.append(' ')
|
||||
lLines.append(' entity blah is')
|
||||
lLines.append('entity blah is')
|
||||
lLines.append(' ')
|
||||
lLines.append(' ')
|
||||
lLines.append(' Entity blah is ')
|
||||
lLines.append('Entity blah is')
|
||||
oRule.analyze(lLines)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
def test_rule_004_exists(self):
|
||||
oRule = rule_entity.rule_004()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'entity')
|
||||
self.assertEqual(oRule.identifier, '004')
|
||||
|
||||
def test_rule_004(self):
|
||||
oRule = rule_entity.rule_004()
|
||||
|
||||
dExpected = [7,8]
|
||||
lLines = []
|
||||
lLines.append(' This is a test of ending entity')
|
||||
lLines.append(' ')
|
||||
lLines.append(' entity blah iS')
|
||||
lLines.append('entity blah is')
|
||||
lLines.append(' ')
|
||||
lLines.append(' ')
|
||||
lLines.append(' Entity blah is ')
|
||||
lLines.append('Entity blah IS')
|
||||
oRule.analyze(lLines)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
def test_rule_005_exists(self):
|
||||
oRule = rule_entity.rule_005()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'entity')
|
||||
self.assertEqual(oRule.identifier, '005')
|
||||
|
||||
def test_rule_005(self):
|
||||
oRule = rule_entity.rule_005()
|
||||
|
||||
dExpected = [4,7]
|
||||
lLines = []
|
||||
lLines.append(' This is a test of ending entity')
|
||||
lLines.append(' ')
|
||||
lLines.append(' entity blah iS')
|
||||
lLines.append('entity blah ')
|
||||
lLines.append(' ')
|
||||
lLines.append(' ')
|
||||
lLines.append(' Entity blah ')
|
||||
lLines.append('Entity blah IS')
|
||||
oRule.analyze(lLines)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
def test_rule_006_exists(self):
|
||||
oRule = rule_entity.rule_006()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'entity')
|
||||
self.assertEqual(oRule.identifier, '006')
|
||||
|
||||
def test_rule_006(self):
|
||||
oRule = rule_entity.rule_006()
|
||||
|
||||
dExpected = [3,8]
|
||||
lLines = []
|
||||
lLines.append(' This is a test of ending entity')
|
||||
lLines.append(' ')
|
||||
lLines.append(' entity blah iS')
|
||||
lLines.append('entity blah is ')
|
||||
lLines.append(' ')
|
||||
lLines.append(' ')
|
||||
lLines.append(' Entity blah is ')
|
||||
lLines.append('Entity blah IS')
|
||||
oRule.analyze(lLines)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
def test_rule_007_exists(self):
|
||||
oRule = rule_entity.rule_007()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'entity')
|
||||
self.assertEqual(oRule.identifier, '007')
|
||||
|
||||
def test_rule_007(self):
|
||||
oRule = rule_entity.rule_007()
|
||||
|
||||
dExpected = [4,8]
|
||||
lLines = []
|
||||
lLines.append(' This is a test of ending entity')
|
||||
lLines.append(' ')
|
||||
lLines.append(' entity blah iS')
|
||||
lLines.append('entity blah is ')
|
||||
lLines.append(' ')
|
||||
lLines.append(' ')
|
||||
lLines.append(' Entity blah is ')
|
||||
lLines.append('Entity blah IS')
|
||||
oRule.analyze(lLines)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue