Exemplo n.º 1
0
    def test_find_dirs_second_passing(self):
        notpassing = [
            augeasparser.AugeasDirectiveNode(name="notpassing",
                                             ancestor=self.block,
                                             filepath="/path/to/whatever",
                                             metadata=self.metadata)
        ]
        passing = [
            augeasparser.AugeasDirectiveNode(name=assertions.PASS,
                                             ancestor=self.block,
                                             filepath=assertions.PASS,
                                             metadata=self.metadata)
        ]
        find_dirs_primary = mock.MagicMock(return_value=notpassing)
        find_dirs_secondary = mock.MagicMock(return_value=passing)
        self.block.primary.find_directives = find_dirs_primary
        self.block.secondary.find_directives = find_dirs_secondary

        directives = self.block.find_directives("something")
        for directive in directives:
            try:
                assertions.assertEqual(directive.primary, directive.secondary)
            except AssertionError:  # pragma: no cover
                self.fail("Assertion should have passed")
            self.assertFalse(assertions.isPassDirective(directive.primary))
            self.assertTrue(assertions.isPassDirective(directive.secondary))
Exemplo n.º 2
0
    def __init__(self, **kwargs: Any):
        """ This initialization implementation allows ordinary initialization
        of DirectiveNode objects as well as creating a DualDirectiveNode object
        using precreated or fetched DirectiveNode objects if provided as optional
        arguments primary and secondary.

        Parameters other than the following are from interfaces.DirectiveNode:

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

        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.AugeasDirectiveNode(**kwargs)
            self.secondary = apacheparser.ApacheDirectiveNode(**kwargs)

        assertions.assertEqual(self.primary, self.secondary)
Exemplo n.º 3
0
    def test_find_dirs_no_pass_equal(self):
        notpassing1 = [augeasparser.AugeasDirectiveNode(name="notpassing",
                                                        ancestor=self.block,
                                                        filepath="/path/to/whatever",
                                                        metadata=self.metadata)]
        notpassing2 = [augeasparser.AugeasDirectiveNode(name="notpassing",
                                                        ancestor=self.block,
                                                        filepath="/path/to/whatever",
                                                        metadata=self.metadata)]
        find_dirs_primary = mock.MagicMock(return_value=notpassing1)
        find_dirs_secondary = mock.MagicMock(return_value=notpassing2)
        self.block.primary.find_directives = find_dirs_primary
        self.block.secondary.find_directives = find_dirs_secondary

        directives = self.block.find_directives("anything")
        for directive in directives:
            with self.subTest(directive=directive):
                self.assertEqual(directive.primary, directive.secondary)
                self.assertIsNot(directive.primary, directive.secondary)
Exemplo n.º 4
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)