Exemplo n.º 1
0
    def test_has_violations_method(self):
        oRule = rule.rule()

        self.assertFalse(oRule.has_violations())

        oRule.add_violation(1)
        self.assertTrue(oRule.has_violations())
Exemplo n.º 2
0
 def test_add_violations_method(self):
     oRule = rule.rule()
     self.assertEqual(oRule.violations, [])
     oRule.add_violation(1)
     self.assertEqual(oRule.violations, [1])
     oRule.add_violation(10)
     oRule.add_violation(33)
     self.assertEqual(oRule.violations, [1, 10, 33])
Exemplo n.º 3
0
    def test_report_violations_w_syntastic_output_method(self, mockStdout):
        oRule = rule.rule()
        oRule.name = 'xyz'
        oRule.identifier = '001'
        oRule.solution = 'Solution'
        oRule.violations = ['1', '2']

        oRule.report_violations(2, 'syntastic', 'File')
        mockStdout.write.assert_has_calls(
            [mock.call('ERROR: File(2)xyz_001 -- Solution'),
             mock.call('\n')])
Exemplo n.º 4
0
    def test_report_violations_w_vsg_output_method(self, mockStdout):
        oRule = rule.rule()
        oRule.name = 'xyz'
        oRule.identifier = '001'
        oRule.solution = 'Solution'
        oRule.violations = ['1', '2']

        oRule.report_violations(1, 'vsg', 'File')
        mockStdout.write.assert_has_calls([
            mock.call('  xyz_001                   |          1 | Solution'),
            mock.call('\n')
        ])
Exemplo n.º 5
0
    def test_report_violations(self):
        oRule = rule.rule()
        oRule.name = 'xyz'
        oRule.identifier = '001'
        oRule.solution = 'This is my solution'
        self.assertEqual(oRule.name,'xyz')
        self.assertEqual(oRule.identifier,'001')
        self.assertEqual(oRule.solution,'This is my solution')
        self.assertEqual(oRule.disable,False)
        self.assertEqual(oRule.indentSize,2)

        self.assertEqual(oRule.report_violations(1, 'vsg', 'filename', True), 0)
        oRule.add_violation(1)
        self.assertEqual(oRule.report_violations(1, 'vsg', 'filename', True), 1)
Exemplo n.º 6
0
 def test_get_configuration(self):
     oRule = rule.rule()
     oRule.name = 'xyz'
     oRule.identifier = '010'
     oRule.phase = 3
     dExpected = {}
     dExpected['disable'] = False
     dExpected['fixable'] = True
     dExpected['indentSize'] = 2
     dExpected['phase'] = 3
     dActual = oRule.get_configuration()
     for sKey in dExpected.keys():
         self.assertEqual(dActual[sKey], dExpected[sKey])
     for sKey in dActual.keys():
         self.assertEqual(dActual[sKey], dExpected[sKey])
Exemplo n.º 7
0
    def test_rule_configure(self):
        oRule = rule.rule()
        oRule.name = 'xyz'
        oRule.identifier = '001'
        oRule.solution = 'This is my solution'
        self.assertEqual(oRule.name, 'xyz')
        self.assertEqual(oRule.identifier, '001')
        self.assertEqual(oRule.solution, 'This is my solution')
        self.assertEqual(oRule.disable, False)
        self.assertEqual(oRule.indentSize, 2)

        dConfiguration = {}
        dConfiguration['rule'] = {}
        dConfiguration['rule']['xyz_001'] = {}
        dConfiguration['rule']['xyz_001']['disable'] = True

        oRule.configure(dConfiguration)

        self.assertEqual(oRule.disable, True)

        dConfiguration['rule']['xyz_002'] = {}
        dConfiguration['rule']['xyz_002']['disable'] = False

        oRule.configure(dConfiguration)

        self.assertEqual(oRule.disable, True)

        dConfiguration['rule']['xyz_001'][
            'solution'] = 'This is the new solution'

        oRule.configure(dConfiguration)

        self.assertEqual(oRule.solution, 'This is the new solution')

        dConfiguration['rule']['global'] = {}
        dConfiguration['rule']['global']['indentSize'] = 4

        oRule.configure(dConfiguration)

        self.assertEqual(oRule.indentSize, 4)

        # Check for attributes that do not exist
        dConfiguration['rule']['xyz_001']['invalidAttribute'] = False
        oRule.configure(dConfiguration)
        self.assertEqual(oRule.disable, True)
        self.assertEqual(oRule.solution, 'This is the new solution')
        self.assertEqual(oRule.indentSize, 4)
Exemplo n.º 8
0
    def test_get_violations_w_vsg_output_method(self):
        oRule = rule.rule()
        oRule.name = 'xyz'
        oRule.identifier = '001'
        oRule.solution = 'Solution'
        dViolation = {}
        dViolation['lineNumber'] = 1
        oRule.add_violation(dViolation)
        dViolation = {}
        dViolation['lineNumber'] = 2
        oRule.add_violation(dViolation)
        dViolation = {}
        dViolation['lines']= []
        dLineViolation = {}
        dLineViolation['number'] = 2
        dViolation['lines'].append(dLineViolation)
        dLineViolation = {}
        dLineViolation['number'] = 3
        dViolation['lines'].append(dLineViolation)
        oRule.add_violation(dViolation)

        lExpected = []
        dExpected = {}
        dExpected['rule'] = 'xyz_001'
        dExpected['lineNumber'] = '1'
        dExpected['solution'] = 'Solution'
        lExpected.append(dExpected)

        lActual = oRule.get_violations_at_linenumber(1)
        self.assertEqual(lActual, lExpected)

        lExpected = []
        dExpected = {}
        dExpected['rule'] = 'xyz_001'
        dExpected['lineNumber'] = '2'
        dExpected['solution'] = 'Solution'
        lExpected.append(dExpected)
        dExpected = {}
        dExpected['rule'] = 'xyz_001'
        dExpected['lineNumber'] = '2'
        dExpected['solution'] = 'Solution'
        lExpected.append(dExpected)

        lActual = oRule.get_violations_at_linenumber(2)
        self.assertEqual(lActual, lExpected)
Exemplo n.º 9
0
    def test_configure_rule_attributes_method(self):
        oRule = rule.rule()
        oRule.name = 'xyz'
        oRule.identifier = '001'
        dConfiguration = {}

        oRule.configure(dConfiguration)

        self.assertEqual(oRule.indentSize, 2)
        self.assertEqual(oRule.phase, None)
        self.assertEqual(oRule.disable, False)
        self.assertEqual(oRule.fixable, True)
        self.assertEqual(oRule.configuration,
                         ['indentSize', 'phase', 'disable', 'fixable'])

        dConfiguration['rule'] = {}
        dConfiguration['rule']['xyz_001'] = {}
        dConfiguration['rule']['xyz_001']['indentSize'] = 4
        dConfiguration['rule']['xyz_001']['phase'] = 10
        dConfiguration['rule']['xyz_001']['disable'] = True
        dConfiguration['rule']['xyz_001']['fixable'] = False
        dConfiguration['rule']['xyz_001']['unknown'] = 'New'

        oRule.configure(dConfiguration)

        self.assertEqual(oRule.indentSize, 4)
        self.assertEqual(oRule.phase, 10)
        self.assertEqual(oRule.disable, True)
        self.assertEqual(oRule.fixable, False)
        self.assertEqual(oRule.configuration,
                         ['indentSize', 'phase', 'disable', 'fixable'])

        oRule.configuration.append('unknown')
        oRule.unknown = None
        oRule.configure(dConfiguration)

        self.assertEqual(oRule.indentSize, 4)
        self.assertEqual(oRule.phase, 10)
        self.assertEqual(oRule.disable, True)
        self.assertEqual(oRule.fixable, False)
        self.assertEqual(oRule.unknown, 'New')
        self.assertEqual(
            oRule.configuration,
            ['indentSize', 'phase', 'disable', 'fixable', 'unknown'])
Exemplo n.º 10
0
 def test_rule_name(self):
     oRule = rule.rule()
     self.assertFalse(oRule.name)
     oRule.name = 'sName'
     self.assertEqual(oRule.name, 'sName')
Exemplo n.º 11
0
 def test_rule_exists(self):
     oRule = rule.rule()
     self.assertTrue(oRule)
Exemplo n.º 12
0
 def test_rule_solution(self):
     oRule = rule.rule()
     self.assertFalse(oRule.solution)
     oRule.solution = 'rule solution'
     self.assertEqual(oRule.solution, 'rule solution')
Exemplo n.º 13
0
 def test_rule_id(self):
     oRule = rule.rule()
     self.assertFalse(oRule.identifier)
     oRule.id = 'rule id 001'
     self.assertEqual(oRule.id, 'rule id 001')
Exemplo n.º 14
0
 def test_get_solution(self):
     oRule = rule.rule()
     self.assertEqual(oRule._get_solution(100), None)
     oRule.solution = 'Solution'
     self.assertEqual(oRule._get_solution(100), 'Solution')