示例#1
0
    def test_find_comments(self):
        pri_comments = [augeasparser.AugeasCommentNode(comment="some comment",
                                                       ancestor=self.block,
                                                       filepath="/path/to/whatever",
                                                       metadata=self.metadata)]
        sec_comments = [augeasparser.AugeasCommentNode(comment=assertions.PASS,
                                                       ancestor=self.block,
                                                       filepath=assertions.PASS,
                                                       metadata=self.metadata)]
        find_coms_primary = mock.MagicMock(return_value=pri_comments)
        find_coms_secondary = mock.MagicMock(return_value=sec_comments)
        self.block.primary.find_comments = find_coms_primary
        self.block.secondary.find_comments = find_coms_secondary

        dcoms = self.block.find_comments("comment")
        p_dcoms = [d.primary for d in dcoms]
        s_dcoms = [d.secondary for d in dcoms]
        p_coms = self.block.primary.find_comments("comment")
        s_coms = self.block.secondary.find_comments("comment")
        # Check that every comment response is represented in the list of
        # DualParserNode instances.
        for p in p_dcoms:
            self.assertIn(p, p_coms)
        for s in s_dcoms:
            self.assertIn(s, s_coms)
示例#2
0
    def test_find_coms_second_passing(self):
        notpassing = [
            augeasparser.AugeasCommentNode(comment="notpassing",
                                           ancestor=self.block,
                                           filepath="/path/to/whatever",
                                           metadata=self.metadata)
        ]
        passing = [
            augeasparser.AugeasCommentNode(comment=assertions.PASS,
                                           ancestor=self.block,
                                           filepath=assertions.PASS,
                                           metadata=self.metadata)
        ]
        find_coms_primary = mock.MagicMock(return_value=notpassing)
        find_coms_secondary = mock.MagicMock(return_value=passing)
        self.block.primary.find_comments = find_coms_primary
        self.block.secondary.find_comments = find_coms_secondary

        comments = self.block.find_comments("something")
        for comment in comments:
            try:
                assertions.assertEqual(comment.primary, comment.secondary)
            except AssertionError:  # pragma: no cover
                self.fail("Assertion should have passed")
            self.assertFalse(assertions.isPassComment(comment.primary))
            self.assertTrue(assertions.isPassComment(comment.secondary))
示例#3
0
    def __init__(self, **kwargs: Any):
        """ This initialization implementation allows ordinary initialization
        of CommentNode objects as well as creating a DualCommentNode object
        using precreated or fetched CommentNode objects if provided as optional
        arguments primary and secondary.

        Parameters other than the following are from interfaces.CommentNode:

        :param CommentNode primary: Primary pre-created CommentNode, mainly
            used when creating new DualParser nodes using add_* methods.
        :param CommentNode secondary: Secondary pre-created CommentNode
        """

        kwargs.setdefault("primary", None)
        kwargs.setdefault("secondary", None)
        primary = kwargs.pop("primary")
        secondary = kwargs.pop("secondary")

        if primary or secondary:
            assert primary and secondary
            self.primary = primary
            self.secondary = secondary
        else:
            self.primary = augeasparser.AugeasCommentNode(**kwargs)
            self.secondary = apacheparser.ApacheCommentNode(**kwargs)

        assertions.assertEqual(self.primary, self.secondary)
示例#4
0
    def test_find_comments_no_pass_equal(self):
        notpassing1 = [augeasparser.AugeasCommentNode(comment="notpassing",
                                                      ancestor=self.block,
                                                      filepath="/path/to/whatever",
                                                      metadata=self.metadata)]
        notpassing2 = [augeasparser.AugeasCommentNode(comment="notpassing",
                                                      ancestor=self.block,
                                                      filepath="/path/to/whatever",
                                                      metadata=self.metadata)]
        find_coms_primary = mock.MagicMock(return_value=notpassing1)
        find_coms_secondary = mock.MagicMock(return_value=notpassing2)
        self.block.primary.find_comments = find_coms_primary
        self.block.secondary.find_comments = find_coms_secondary

        comments = self.block.find_comments("anything")
        for comment in comments:
            with self.subTest(comment=comment):
                self.assertEqual(comment.primary, comment.secondary)
                self.assertIsNot(comment.primary, comment.secondary)
示例#5
0
 def test_parsernode_notequal(self):
     ne_block = augeasparser.AugeasBlockNode(name="different",
                                             ancestor=self.block,
                                             filepath="/path/to/whatever",
                                             metadata=self.metadata)
     ne_directive = augeasparser.AugeasDirectiveNode(name="different",
                                                     ancestor=self.block,
                                                     filepath="/path/to/whatever",
                                                     metadata=self.metadata)
     ne_comment = augeasparser.AugeasCommentNode(comment="different",
                                                 ancestor=self.block,
                                                 filepath="/path/to/whatever",
                                                 metadata=self.metadata)
     self.assertNotEqual(self.block, ne_block)
     self.assertNotEqual(self.directive, ne_directive)
     self.assertNotEqual(self.comment, ne_comment)