Updates for issue #213
Adding support for YAML configurations: 1) Added tests 2) Added parsing of YAML files
This commit is contained in:
parent
47e14761f9
commit
643c0a1992
3
setup.py
3
setup.py
|
|
@ -33,6 +33,9 @@ setup(
|
|||
test_suite='nose.collector',
|
||||
tests_require=['nose'],
|
||||
keywords=['vhdl', 'style', 'beautify', 'guide'],
|
||||
install_requires[
|
||||
'PyYAML'
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'vsg = vsg.__main__:main'
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import os
|
|||
import json
|
||||
import shutil
|
||||
import glob
|
||||
import yaml
|
||||
|
||||
from . import rule_list
|
||||
from . import vhdlFile
|
||||
|
|
@ -38,32 +39,44 @@ def parse_command_line_arguments():
|
|||
return parser.parse_args()
|
||||
|
||||
|
||||
def open_configuration_file(sFileName, commandLineArguments):
|
||||
'''Attempts to open a configuration file and read it's contents.'''
|
||||
try:
|
||||
with open(sFileName) as json_file:
|
||||
tempConfiguration = json.load(json_file)
|
||||
except:
|
||||
try:
|
||||
with open(sFileName) as yaml_file:
|
||||
tempConfiguration = yaml.load(yaml_file)
|
||||
except:
|
||||
print('Error in configuration file: ' + sFileName)
|
||||
write_invalid_configuration_junit_file(sFileName, commandLineArguments)
|
||||
exit()
|
||||
return tempConfiguration
|
||||
|
||||
|
||||
def read_configuration_files(commandLineArguments):
|
||||
if commandLineArguments.configuration:
|
||||
dConfiguration = {}
|
||||
for sFileName in commandLineArguments.configuration:
|
||||
try:
|
||||
with open(sFileName) as json_file:
|
||||
tempConfiguration = json.load(json_file)
|
||||
for sKey in tempConfiguration.keys():
|
||||
if sKey == 'file_list':
|
||||
try:
|
||||
dConfiguration['file_list'].extend(tempConfiguration['file_list'])
|
||||
except:
|
||||
dConfiguration['file_list'] = tempConfiguration['file_list']
|
||||
elif sKey == 'rule':
|
||||
for sRule in tempConfiguration[sKey]:
|
||||
try:
|
||||
dConfiguration[sKey][sRule] = tempConfiguration[sKey][sRule]
|
||||
except:
|
||||
dConfiguration[sKey] = {}
|
||||
dConfiguration[sKey][sRule] = tempConfiguration[sKey][sRule]
|
||||
else:
|
||||
dConfiguration[sKey] = tempConfiguration[sKey]
|
||||
except:
|
||||
print('Error in JSON file: ' + sFileName)
|
||||
write_invalid_configuration_junit_file(sFileName, commandLineArguments)
|
||||
exit()
|
||||
|
||||
tempConfiguration = open_configuration_file(sFileName, commandLineArguments)
|
||||
|
||||
for sKey in tempConfiguration.keys():
|
||||
if sKey == 'file_list':
|
||||
try:
|
||||
dConfiguration['file_list'].extend(tempConfiguration['file_list'])
|
||||
except:
|
||||
dConfiguration['file_list'] = tempConfiguration['file_list']
|
||||
elif sKey == 'rule':
|
||||
for sRule in tempConfiguration[sKey]:
|
||||
try:
|
||||
dConfiguration[sKey][sRule] = tempConfiguration[sKey][sRule]
|
||||
except:
|
||||
dConfiguration[sKey] = {}
|
||||
dConfiguration[sKey][sRule] = tempConfiguration[sKey][sRule]
|
||||
else:
|
||||
dConfiguration[sKey] = tempConfiguration[sKey]
|
||||
|
||||
return dConfiguration
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
# Include files to be processed
|
||||
file_list:
|
||||
- vsg/tests/vsg/entity1.vhd
|
||||
...
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"file_list":[
|
||||
"vsg/tests/vsg/entity1.vhd",
|
||||
"file_list":[,
|
||||
"vsg/tests/vsg/entity1.vhd"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class testVsg(unittest.TestCase):
|
|||
def test_invalid_configuration(self):
|
||||
utils.remove_file('vsg/tests/vsg/config_error.actual.xml')
|
||||
lExpected = []
|
||||
lExpected.append('Error in JSON file: vsg/tests/vsg/config_error.json')
|
||||
lExpected.append('Error in configuration file: vsg/tests/vsg/config_error.json')
|
||||
lExpected.append('')
|
||||
|
||||
lActual = subprocess.check_output(['bin/vsg','--configuration','vsg/tests/vsg/config_error.json','--output_format','syntastic','-f','vsg/tests/vsg/entity1.vhd','--junit','vsg/tests/vsg/config_error.actual.xml']).split('\n')
|
||||
|
|
@ -94,3 +94,19 @@ class testVsg(unittest.TestCase):
|
|||
|
||||
lActual = subprocess.check_output(['bin/vsg','--configuration','vsg/tests/vsg/config_glob.json','--output_format','syntastic']).split('\n')
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_single_yaml_configuration_w_filelist(self):
|
||||
lExpected = []
|
||||
lExpected.append('ERROR: vsg/tests/vsg/entity1.vhd(7)port_007 -- Change the number of spaces after the "in" keyword to four spaces.')
|
||||
lExpected.append('')
|
||||
|
||||
lActual = subprocess.check_output(['bin/vsg','--configuration','vsg/tests/vsg/config_1.yaml','--output_format','syntastic']).split('\n')
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
lExpected = []
|
||||
lExpected.append('ERROR: vsg/tests/vsg/entity2.vhd(8)port_008 -- Change the number of spaces after the "out" keyword to three spaces.')
|
||||
lExpected.append('')
|
||||
|
||||
lActual = subprocess.check_output(['bin/vsg','--configuration','vsg/tests/vsg/config_2.json','--output_format','syntastic']).split('\n')
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue