def test_profilepath_trailing_slash(self): good_line_1 = '"/system/hostname" = "foo.example.org";' self.assertEqual(panlint.lint_line(good_line_1, 148, [], False), ([], set(), 0, False)) good_line_2 = "prefix '/software/components/metaconfig/services/{/etc/sysconfig/fetch-crl}';" self.assertEqual(panlint.lint_line(good_line_2, 151, [], False), ([], set(), 0, False)) bad_line_1 = '"/system/hostname/" = "bar.example.org";' bad_diag_1 = [' ^'] bad_msg_1 = ['Unnecessary trailing slash at end of profile path'] self.assertEqual(panlint.lint_line(bad_line_1, 22, [], False), (bad_diag_1, set(bad_msg_1), 1, False)) bad_line_2 = '"/system/hostname////////" = "bob.example.org";' bad_diag_2 = [' ^^^^^^^^'] bad_msg_2 = ['Unnecessary trailing slash at end of profile path'] self.assertEqual(panlint.lint_line(bad_line_2, 77, [], False), (bad_diag_2, set(bad_msg_2), 1, False)) bad_line_3 = "prefix '/software/components/filecopy/services/{/etc/strange/service.conf}/';" bad_diag_3 = [ ' ^' ] bad_msg_3 = ['Unnecessary trailing slash at end of profile path'] self.assertEqual(panlint.lint_line(bad_line_3, 182, [], False), (bad_diag_3, set(bad_msg_3), 1, False))
def test_whitespace_after_semicolons(self): bad_1 = 'foreach(k; v; things) {' dgn_1 = [' ^^'] msg_1 = [ 'Semicolons should be followed exactly one space or end-of-line' ] self.assertEqual(panlint.lint_line(bad_1, 1, [], False), (dgn_1, set(msg_1), 1, False)) bad_2 = 'foreach(k; v; things) {' dgn_2 = [' ^^^^', ' ^^'] msg_2 = [ 'Semicolons should be followed exactly one space or end-of-line' ] self.assertEqual(panlint.lint_line(bad_2, 2, [], False), (dgn_2, set(msg_2), 2, False))
def test_whitespace_after_semicolons(self): bad_1 = 'foreach(k; v; things) {' dgn_1 = [' ^^'] msg_1 = ['Semicolons should be followed exactly one space or end-of-line'] self.assertEqual( panlint.lint_line(bad_1, 1, [], False), (dgn_1, set(msg_1), 1, False) ) bad_2 = 'foreach(k; v; things) {' dgn_2 = [' ^^^^', ' ^^'] msg_2 = ['Semicolons should be followed exactly one space or end-of-line'] self.assertEqual( panlint.lint_line(bad_2, 2, [], False), (dgn_2, set(msg_2), 2, False) )
def test_profilepath_trailing_slash(self): good_line_1 = '"/system/hostname" = "foo.example.org";' self.assertEqual(panlint.lint_line(good_line_1, 148, [], False), ([], set(), 0, False)) good_line_2 = "prefix '/system/network/interfaces/eth0';" self.assertEqual(panlint.lint_line(good_line_2, 151, [], False), ([], set(), 0, False)) good_line_3 = "'/' = dict();" self.assertEqual(panlint.lint_line(good_line_3, 151, [], False), ([], set(), 0, False)) bad_line_1 = '"/system/hostname/" = "bar.example.org";' bad_diag_1 = [' ^'] bad_msg_1 = ['Unnecessary trailing slash at end of profile path'] self.assertEqual(panlint.lint_line(bad_line_1, 22, [], False), (bad_diag_1, set(bad_msg_1), 1, False)) bad_line_2 = '"/system/hostname////////" = "bob.example.org";' bad_diag_2 = [' ^^^^^^^^'] bad_msg_2 = ['Unnecessary trailing slash at end of profile path'] self.assertEqual(panlint.lint_line(bad_line_2, 77, [], False), (bad_diag_2, set(bad_msg_2), 1, False)) bad_line_3 = "prefix '/system/aii/osinstall/ks/';" bad_diag_3 = [' ^'] bad_msg_3 = ['Unnecessary trailing slash at end of profile path'] self.assertEqual(panlint.lint_line(bad_line_3, 182, [], False), (bad_diag_3, set(bad_msg_3), 1, False))
def test_profilepath_trailing_slash(self): good_line_1 = '"/system/hostname" = "foo.example.org";' self.assertEqual( panlint.lint_line(good_line_1, 148, [], False), ([], set(), 0, False) ) good_line_2 = "prefix '/system/network/interfaces/eth0';" self.assertEqual( panlint.lint_line(good_line_2, 151, [], False), ([], set(), 0, False) ) bad_line_1 = '"/system/hostname/" = "bar.example.org";' bad_diag_1 = [' ^'] bad_msg_1 = ['Unnecessary trailing slash at end of profile path'] self.assertEqual( panlint.lint_line(bad_line_1, 22, [], False), (bad_diag_1, set(bad_msg_1), 1, False) ) bad_line_2 = '"/system/hostname////////" = "bob.example.org";' bad_diag_2 = [' ^^^^^^^^'] bad_msg_2 = ['Unnecessary trailing slash at end of profile path'] self.assertEqual( panlint.lint_line(bad_line_2, 77, [], False), (bad_diag_2, set(bad_msg_2), 1, False) ) bad_line_3 = "prefix '/system/aii/osinstall/ks/';" bad_diag_3 = [' ^'] bad_msg_3 = ['Unnecessary trailing slash at end of profile path'] self.assertEqual( panlint.lint_line(bad_line_3, 182, [], False), (bad_diag_3, set(bad_msg_3), 1, False) )
def test_lint_line(self): good_first = 'structure template foo.bar;' bad_first = 'variable foo = "bar";' # Test first line checking self.assertEqual(panlint.lint_line(good_first, 1, [], True), ([], set(), 0, False)) diagnoses, messages, problem_count, first_line = panlint.lint_line( bad_first, 1, [], True) self.assertEqual(diagnoses, ['^' * len(bad_first)]) self.assertNotEqual(messages, set()) self.assertEqual(problem_count, 1) self.assertEqual(first_line, False) # Test component inclusion check diagnoses, messages, problem_count, first_line = panlint.lint_line( '"/software/components/foo/bar" = 42;', 7, [], False) self.assertEqual(diagnoses, [' ^^^']) self.assertNotEqual(messages, set()) self.assertEqual(problem_count, 1) self.assertEqual(first_line, False) # Test pattern based checking diagnoses, messages, problem_count, first_line = panlint.lint_line( ' x = x + 1; # Bad Indentation', 7, [], False) self.assertEqual(diagnoses, ['^^^']) self.assertNotEqual(messages, set()) self.assertEqual(problem_count, 1) self.assertEqual(first_line, False) # Test method based checking diagnoses, messages, problem_count, first_line = panlint.lint_line( 'x = x+1; # Missing space', 7, [], False) self.assertEqual(diagnoses, [' ^^^']) self.assertNotEqual(messages, set()) self.assertEqual(problem_count, 1) self.assertEqual(first_line, False) # Test that all three check types co-exist diagnoses, messages, problem_count, first_line = panlint.lint_line( ' "/software/components/foo/bar" = 42+7;', 7, [], False) self.assertItemsEqual(diagnoses, [ '^^', ' ^^^', ' ^^^' ]) self.assertNotEqual(messages, set()) self.assertEqual(problem_count, 3) self.assertEqual(first_line, False)
def test_lint_line(self): good_first = 'structure template foo.bar;' bad_first = 'variable foo = "bar";' # Test first line checking self.assertEqual(panlint.lint_line(good_first, 1, [], True), ([], [], 0, False)) diagnoses, messages, problem_count, first_line = panlint.lint_line(bad_first, 1, [], True) self.assertEqual(diagnoses, ['^'*len(bad_first)]) self.assertNotEqual(messages, []) self.assertEqual(problem_count, 1) self.assertEqual(first_line, False) # Test component inclusion check diagnoses, messages, problem_count, first_line = panlint.lint_line('"/software/components/foo/bar" = 42;', 7, [], False) self.assertEqual(diagnoses, [' ^^^']) self.assertNotEqual(messages, []) self.assertEqual(problem_count, 1) self.assertEqual(first_line, False) # Test pattern based checking diagnoses, messages, problem_count, first_line = panlint.lint_line(' x = x + 1; # Bad Indentation', 7, [], False) self.assertEqual(diagnoses, ['^^^']) self.assertNotEqual(messages, []) self.assertEqual(problem_count, 1) self.assertEqual(first_line, False) # Test method based checking diagnoses, messages, problem_count, first_line = panlint.lint_line('x = x+1; # Missing space', 7, [], False) self.assertEqual(diagnoses, [' ^^^']) self.assertNotEqual(messages, []) self.assertEqual(problem_count, 1) self.assertEqual(first_line, False) # Test that all three check types co-exist diagnoses, messages, problem_count, first_line = panlint.lint_line(' "/software/components/foo/bar" = 42+7;', 7, [], False) self.assertItemsEqual(diagnoses, ['^^', ' ^^^', ' ^^^']) self.assertNotEqual(messages, []) self.assertEqual(problem_count, 3) self.assertEqual(first_line, False)
def test_component_use(self): # Test a line containing a standard path assignment line_standard = "'/software/components/chkconfig/service/rdma' = dict(" diag_standard = " ^^^^^^^^^" # Test a line setting a path prefix line_prefix = "prefix '/software/components/metaconfig/services/{/etc/sysconfig/fetch-crl}';" diag_prefix = " ^^^^^^^^^^" # Test both lines with components listed as included self.assertEqual( panlint.lint_line(line_standard, 100, ['chkconfig'], False), ([], set(), 0, False) ) self.assertEqual( panlint.lint_line(line_prefix, 200, ['metaconfig'], False), ([], set(), 0, False) ) # Test both lines without components listed as included self.assertEqual( panlint.lint_line(line_standard, 100, [], False), ([diag_standard], set(['Component chkconfig in use, but component config has not been included']), 1, False) ) self.assertEqual( panlint.lint_line(line_prefix, 200, [], False), ([diag_prefix], set(['Component metaconfig in use, but component config has not been included']), 1, False) ) # Test both lines without components listed as included but commented out self.assertEqual( panlint.lint_line('# ' + line_standard, 100, [], False), ([], set(), 0, False) ) self.assertEqual( panlint.lint_line(' #' + line_prefix, 200, [], False), ([], set(), 0, False) )
def test_component_use(self): # Test a line containing a standard path assignment line_standard = "'/software/components/chkconfig/service/rdma' = dict(" diag_standard = " ^^^^^^^^^" # Test a line setting a path prefix line_prefix = "prefix '/software/components/metaconfig/services/{/etc/sysconfig/fetch-crl}';" diag_prefix = " ^^^^^^^^^^" # Test both lines with components listed as included self.assertEqual( panlint.lint_line(line_standard, 100, ['chkconfig'], False), ([], set(), 0, False)) self.assertEqual( panlint.lint_line(line_prefix, 200, ['metaconfig'], False), ([], set(), 0, False)) # Test both lines without components listed as included self.assertEqual(panlint.lint_line(line_standard, 100, [], False), ( [diag_standard], set([ 'Component chkconfig in use, but component config has not been included' ]), 1, False)) self.assertEqual(panlint.lint_line(line_prefix, 200, [], False), ( [diag_prefix], set([ 'Component metaconfig in use, but component config has not been included' ]), 1, False)) # Test both lines without components listed as included but commented out self.assertEqual( panlint.lint_line('# ' + line_standard, 100, [], False), ([], set(), 0, False)) self.assertEqual( panlint.lint_line(' #' + line_prefix, 200, [], False), ([], set(), 0, False))