import os

import unittest

from vsg.rules import if_statement
from vsg import vhdlFile
from vsg import rule_list

# Read in test file used for all tests
oFile = vhdlFile.vhdlFile(
    os.path.join(os.path.dirname(__file__), '..', 'if_statement',
                 'if_test_input.vhd'))
oFileCase = vhdlFile.vhdlFile(
    os.path.join(os.path.dirname(__file__), '..', 'if_statement',
                 'if_case_test_input.vhd'))
oFileCompress = vhdlFile.vhdlFile(
    os.path.join(os.path.dirname(__file__),
                 'if_compressed_line_test_input.vhd'))


class testFixRuleIfMethods(unittest.TestCase):
    def test_fix_rule_001(self):
        oRule = if_statement.rule_001()
        dExpected = []
        oRule.fix(oFile)
        oRule.analyze(oFile)
        self.assertEqual(oRule.violations, dExpected)

    def test_fix_rule_002(self):
        oRule = if_statement.rule_002()
        dExpected = []
Пример #2
0
 def setUp(self):
     self.oFile = vhdlFile.vhdlFile(lFile)
     self.assertIsNone(eError)
Пример #3
0
 def setUp(self):
     self.oFile = vhdlFile.vhdlFile(lFile)
     self.assertIsNone(eError)
     self.oFile.set_indent_map(dIndentMap)
import os

import unittest
from vsg import vhdlFile

sFileLibraryName = os.path.join(os.path.dirname(__file__), '..', 'library',
                                'library_test_input.vhd')
oFileLibrary = vhdlFile.vhdlFile(sFileLibraryName)

oFileProcess = vhdlFile.vhdlFile(
    os.path.join(os.path.dirname(__file__), '..', 'process',
                 'process_test_input.vhd'))


class testVhdlFileMethods(unittest.TestCase):
    def test_comment_assignment(self):
        lExpected = [8, 21, 50, 76, 83, 90, 114, 134, 135, 136, 137, 138]
        # Generic actual list
        lActual = []
        for iIndex, oLine in enumerate(oFileProcess.lines):
            if oLine.isComment:
                lActual.append(iIndex)
        # Compare
        self.assertEqual(lActual, lExpected)

    def test_insideProcess_assignment(self):
        lExpected = [
            6, 7, 8, 9, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 24, 25, 26,
            27, 28, 29, 30, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 46, 47, 48,
            51, 52, 53, 55, 56, 57, 58, 59, 60, 63, 64, 65, 68, 69, 70, 71, 72,
            75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 92, 93,
Пример #5
0
import os

import unittest
import sys
sys.path.append('vsg')

from vsg.rules import after
from vsg import vhdlFile
from vsg.tests import utils

# Read in test file used for all tests
lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'after_test_input.vhd'))
oFile = vhdlFile.vhdlFile(lFile)

class testRuleAfterMethods(unittest.TestCase):

    def test_rule_001(self):
        oRule = after.rule_001()
        self.assertTrue(oRule)
        self.assertEqual(oRule.name, 'after')
        self.assertEqual(oRule.identifier, '001')
        self.assertTrue(oRule.disable)
        self.assertEqual(oRule.magnitude, 1)
        self.assertEqual(oRule.units, 'ns')
        lExpected = [33, 34]
        oRule.analyze(oFile)
        self.assertEqual(oRule.violations, lExpected)

    def test_rule_002(self):
        oRule = after.rule_002()
        self.assertTrue(oRule)
Пример #6
0
import os

import unittest
from vsg import vhdlFile

oFile = vhdlFile.vhdlFile(
    os.path.join(os.path.dirname(__file__), '..', 'variable_assignment',
                 'variable_assignment_test_input.vhd'))


class testVhdlFileVariableAssignmentAssignments(unittest.TestCase):
    def test_isVariableAssignment_assignment(self):
        lExpected = [
            13, 14, 15, 20, 21, 22, 26, 27, 28, 33, 34, 38, 39, 40, 53, 56, 57,
            63, 65, 66, 71, 73, 75, 80, 81, 83, 88, 89, 90, 92, 99
        ]
        # Generic actual list
        lActual = []
        for iIndex, oLine in enumerate(oFile.lines):
            if oLine.isVariableAssignment:
                lActual.append(iIndex)
        # Compare
        self.assertEqual(lActual, lExpected)

    def test_insideVariableAssignment_assignment(self):
        lExpected = [
            13, 14, 15, 20, 21, 22, 26, 27, 28, 33, 34, 38, 39, 40, 53, 54, 55,
            56, 57, 58, 63, 65, 66, 71, 73, 74, 75, 80, 81, 83, 88, 89, 90, 92,
            93, 94, 95, 99, 100
        ]
        # Generic actual list
 def setUp(self):
     self.oFile = vhdlFile.vhdlFile(lFile)
Пример #8
0
import os

import unittest

from vsg.rules import instantiation
from vsg import vhdlFile
from vsg.tests import utils

lFilePort = utils.read_vhdlfile(
    os.path.join(os.path.dirname(__file__), 'instantiation_test_input.vhd'))
oFilePort = vhdlFile.vhdlFile(lFilePort)
lFileGeneric = utils.read_vhdlfile(
    os.path.join(os.path.dirname(__file__),
                 'instantiation_generic_test_input.vhd'))
oFileGeneric = vhdlFile.vhdlFile(lFileGeneric)
lFileComment = utils.read_vhdlfile(
    os.path.join(os.path.dirname(__file__),
                 'instantiation_comment_test_input.vhd'))
oFileComment = vhdlFile.vhdlFile(lFileComment)
lFilePositional = utils.read_vhdlfile(
    os.path.join(os.path.dirname(__file__),
                 'instantiation_positional_test_input.vhd'))
oFilePositional = vhdlFile.vhdlFile(lFilePositional)
lFileDirect = utils.read_vhdlfile(
    os.path.join(os.path.dirname(__file__),
                 'instantiation_direct_test_input.vhd'))
oFileDirect = vhdlFile.vhdlFile(lFileDirect)


class testRuleInstantiationMethods(unittest.TestCase):
    def test_rule_001(self):
import os
import unittest

from vsg.rules import case
from vsg.rules import comment
from vsg import vhdlFile
from vsg.tests import utils

# Read in test file used for all tests
lFile = utils.read_vhdlfile(
    os.path.join(os.path.dirname(__file__), '..', 'case',
                 'case_test_input.vhd'))
oFile = vhdlFile.vhdlFile(lFile)
lFileCase = utils.read_vhdlfile(
    os.path.join(os.path.dirname(__file__), 'comment_case_test_input.vhd'))
oFileCase = vhdlFile.vhdlFile(lFileCase)

lFileSequential = utils.read_vhdlfile(
    os.path.join(os.path.dirname(__file__), '..', 'case',
                 'case_sequential_test_input.vhd'))
oFileSequential = vhdlFile.vhdlFile(lFileSequential)


class testFixRuleCaseMethods(unittest.TestCase):
    def test_fix_rule_001(self):
        oRule = case.rule_001()
        dExpected = []
        oRule.fix(oFile)
        oRule.analyze(oFile)
        self.assertEqual(oRule.violations, dExpected)
Пример #10
0
import os

import unittest

from vsg.rules import port
from vsg import vhdlFile

oFile = vhdlFile.vhdlFile(
    os.path.join(os.path.dirname(__file__), '..', 'port',
                 'port_test_input.vhd'))
oFile_rule_016 = vhdlFile.vhdlFile(
    os.path.join(os.path.dirname(__file__), '..', 'port',
                 'port_test_input.vhd'))


class testFixRulePortMethods(unittest.TestCase):
    def test_fix_rule_001(self):
        oRule = port.rule_001()
        oRule.fix(oFile)
        oRule.analyze(oFile)
        self.assertEqual(oRule.violations, [])

    def test_fix_rule_002(self):
        oRule = port.rule_002()
        oRule.fix(oFile)
        oRule.analyze(oFile)
        self.assertEqual(oRule.violations, [])

    def test_fix_rule_003(self):
        oRule = port.rule_003()
        oRule.fix(oFile)
Пример #11
0
import os

import unittest

from vsg.rules import function
from vsg import vhdlFile
from vsg.tests import utils

# Read in test file used for all tests
lFile = utils.read_vhdlfile(
    os.path.join(os.path.dirname(__file__), 'function_test_input.vhd'))
oFile = vhdlFile.vhdlFile(lFile)
lFileMultiple = utils.read_vhdlfile(
    os.path.join(os.path.dirname(__file__),
                 'function_multiple_parameters_test_input.vhd'))
oFileMultiple = vhdlFile.vhdlFile(lFileMultiple)


class testRuleFunctionMethods(unittest.TestCase):
    def test_rule_001(self):
        oRule = function.rule_001()
        self.assertTrue(oRule)
        self.assertEqual(oRule.name, 'function')
        self.assertEqual(oRule.identifier, '001')
        dExpected = utils.add_violation_list([16, 17, 18, 19, 21, 22, 23, 24])
        oRule.analyze(oFile)
        self.assertEqual(oRule.violations, dExpected)

    def test_rule_002(self):
        oRule = function.rule_002()
        self.assertTrue(oRule)
import os

import unittest
from vsg import vhdlFile

oFile = vhdlFile.vhdlFile(
    os.path.join(os.path.dirname(__file__), '..', 'type_definition',
                 'type_test_input.vhd'))


class testVhdlFileTypeAssignments(unittest.TestCase):
    def test_isTypeKeyword(self):
        lExpected = [4, 6, 11, 13, 27, 29, 34, 36, 43, 54, 57, 69]
        # Generic actual list
        lActual = []
        for iIndex, oLine in enumerate(oFile.lines):
            if oLine.isTypeKeyword:
                lActual.append(iIndex)
        # Compare
        self.assertEqual(lActual, lExpected)

    def test_isTypeEnd(self):
        lExpected = [4, 9, 11, 19, 27, 32, 34, 40, 48, 55, 62, 75]
        # Generic actual list
        lActual = []
        for iIndex, oLine in enumerate(oFile.lines):
            if oLine.isTypeEnd:
                lActual.append(iIndex)
        # Compare
        self.assertEqual(lActual, lExpected)
 def setUp(self):
     self.oFile = vhdlFile.vhdlFile(lFile)
     self.oFileEvent = vhdlFile.vhdlFile(lFileEvent)