コード例 #1
0
 def test_matching(self):
     """
     Matches strings that match the pattern, doesn't match other strings.
     """
     matcher = RegexMatcher(r'^foo')
     self.assertTrue(matcher('foobar'))
     self.assertFalse(matcher('barfoo'))
コード例 #2
0
    def test_str(self):
        """
        The string representation is readable and shows which matchers have
        been matched and which are still to be matched.
        """
        matcher = UnorderedLinesMatcher(EqualsMatcher('foo'),
                                        RegexMatcher('^bar'))

        self.assertEqual(
            str(matcher), 'UnorderedLinesMatcher(matched=[], '
            "unmatched=[EqualsMatcher('foo'), RegexMatcher('^bar')])")
        self.assertEqual(repr(matcher), str(matcher))

        self.assertFalse(matcher('foo'))

        self.assertEqual(
            str(matcher),
            "UnorderedLinesMatcher(matched=[EqualsMatcher('foo')], "
            "unmatched=[RegexMatcher('^bar')])")
        self.assertEqual(repr(matcher), str(matcher))

        self.assertTrue(matcher('barfoo'))

        self.assertEqual(
            str(matcher),
            "UnorderedLinesMatcher(matched=[EqualsMatcher('foo'), "
            "RegexMatcher('^bar')], unmatched=[])")
        self.assertEqual(repr(matcher), str(matcher))
コード例 #3
0
    def test_matching(self):
        """
        Applies each matcher sequentially and returns True on the final match.
        """
        matcher = UnorderedLinesMatcher(EqualsMatcher('foo'),
                                        RegexMatcher('^bar'))

        self.assertFalse(matcher('barfoo'))
        self.assertFalse(matcher('baz'))
        self.assertTrue(matcher('foo'))

        matcher = UnorderedLinesMatcher(EqualsMatcher('foo'),
                                        RegexMatcher('^bar'))

        self.assertFalse(matcher('foo'))
        self.assertFalse(matcher('baz'))
        self.assertTrue(matcher('barfoo'))
コード例 #4
0
    def __init__(self,
                 name,
                 image,
                 wait_patterns=None,
                 wait_timeout=None,
                 create_kwargs=None,
                 helper=None):
        """
        :param name:
            The name for the container. The actual name of the container is
            namespaced by ContainerHelper. This name will be used as a network
            alias for the container.
        :param image: image tag to use
        :param list wait_patterns:
            Regex patterns to use when checking that the container has started
            successfully.
        :param wait_timeout:
            Number of seconds to wait for the ``wait_patterns``. Defaults to
            ``self.WAIT_TIMEOUT``.
        :param dict create_kwargs:
            Other kwargs to use when creating the container.
        :param seaworthy.helper.ContainerHelper helper:
            A ContainerHelper instance used to create containers.
        """
        super().__init__(name, create_kwargs=create_kwargs, helper=helper)

        self._create_args = (image, )
        if wait_patterns:
            self.wait_matchers = [RegexMatcher(p) for p in wait_patterns]
        else:
            self.wait_matchers = None
        if wait_timeout is not None:
            self.wait_timeout = wait_timeout
        else:
            self.wait_timeout = self.WAIT_TIMEOUT

        self._http_clients = []
コード例 #5
0
 def test_str(self):
     """ The string representation is readable. """
     matcher = RegexMatcher(r'^bar')
     self.assertEqual(str(matcher), "RegexMatcher('^bar')")
     self.assertEqual(repr(matcher), str(matcher))