Fix failed tests issue.
This commit is contained in:
parent
43250de2e9
commit
9a2a84ba0c
|
|
@ -13,3 +13,6 @@ def is_lowercase(self, sString, iLineNumber):
|
|||
'''
|
||||
if not sString == sString.lower():
|
||||
self.add_violation(iLineNumber)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -13,3 +13,6 @@ def is_uppercase(self, sString, iLineNumber):
|
|||
'''
|
||||
if not sString == sString.upper():
|
||||
self.add_violation(iLineNumber)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -41,27 +41,24 @@ class case_rule(rule.rule):
|
|||
self.sTrigger = sTrigger
|
||||
self.extractFunction = extractFunction
|
||||
self.case = 'lower'
|
||||
self.words = []
|
||||
self.words_to_fix = set()
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.__dict__[self.sTrigger]:
|
||||
self.words = self.words + self.extractFunction(oLine)
|
||||
if self.case == 'lower':
|
||||
check_function = check.is_lowercase
|
||||
else:
|
||||
check_function = check.is_uppercase
|
||||
words = self.extractFunction(oLine)
|
||||
|
||||
for word in self.words:
|
||||
check_function(self, word, iLineNumber)
|
||||
if self.case == 'lower':
|
||||
check_function = check.is_lowercase
|
||||
else:
|
||||
check_function = check.is_uppercase
|
||||
|
||||
for word in words:
|
||||
if check_function(self, word, iLineNumber) == False:
|
||||
self.words_to_fix.add(word)
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
for iLineNumber in self.violations:
|
||||
print('***')
|
||||
print(self.words)
|
||||
print('***')
|
||||
for word in self.words:
|
||||
print(word)
|
||||
|
||||
for word in self.words_to_fix:
|
||||
if self.case == 'lower':
|
||||
fix_function = fix.lower_case
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -93,6 +93,19 @@ class testFixRuleConstantMethods(unittest.TestCase):
|
|||
self.assertEqual(self.oFile.lines[9].line, 'constant const : STD_LOGIC:=\'0\';')
|
||||
self.assertEqual(self.oFile.lines[10].line, ' constant c_const: std_logic')
|
||||
|
||||
oRule = constant.rule_004()
|
||||
oRule.case = 'upper'
|
||||
dExpected = []
|
||||
oRule.fix(self.oFile)
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
self.assertEqual(self.oFile.lines[5].line, ' constant C_CONST : std_logic := \'1\';')
|
||||
self.assertEqual(self.oFile.lines[6].line, ' constant CONST : std_logic := \'0\';')
|
||||
self.assertEqual(self.oFile.lines[7].line, ' COnstant C_CONST : std_logic := \'1\';')
|
||||
self.assertEqual(self.oFile.lines[8].line, 'Constant C_CONST : std_logic := \'0\';')
|
||||
self.assertEqual(self.oFile.lines[9].line, 'constant CONST : STD_LOGIC:=\'0\';')
|
||||
self.assertEqual(self.oFile.lines[10].line, ' constant C_CONST: std_logic')
|
||||
|
||||
def test_fix_rule_005(self):
|
||||
oRule = constant.rule_005()
|
||||
dExpected = []
|
||||
|
|
|
|||
|
|
@ -98,7 +98,6 @@ def change_word(oLine, sWord, sNewWord, iMax=1):
|
|||
|
||||
sNewWord: (string)
|
||||
'''
|
||||
print('### Changing word ' + sWord + ' to ' + sNewWord + ' ###')
|
||||
sLine = oLine.line
|
||||
tLine = re.subn(r'\b' + sWord + r'\b', sNewWord, sLine, iMax, flags=re.IGNORECASE)
|
||||
sLine = tLine[0]
|
||||
|
|
|
|||
Loading…
Reference in New Issue