How to use the testtools.matchers.MatchesRegex function in testtools

To help you get started, we’ve selected a few testtools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github snapcore / snapcraft / tests / unit / commands / test_export_login.py View on Github external
["export-login", "exported"], input="user@example.com\nsecret\n123456"
        )

        self.assertThat(result.exit_code, Equals(0))
        self.assertThat(
            result.output, Not(Contains(storeapi.constants.TWO_FACTOR_WARNING))
        )
        self.assertThat(result.output, Contains("Login successfully exported"))
        self.assertThat(
            result.output, MatchesRegex(r".*snaps:.*?No restriction", re.DOTALL)
        )
        self.assertThat(
            result.output, MatchesRegex(r".*channels:.*?['edge']", re.DOTALL)
        )
        self.assertThat(
            result.output, MatchesRegex(r".*permissions:.*?No restriction", re.DOTALL)
        )
        self.assertThat(
            result.output, MatchesRegex(r".*expires:.*?2018-01-01T00:00:00", re.DOTALL)
        )

        self.assertThat(self.fake_store_login.mock.call_count, Equals(2))
        self.fake_store_login.mock.assert_has_calls(
            [
                mock.call(
                    "user@example.com",
                    "secret",
                    acls=None,
                    packages=None,
                    channels=None,
                    expires=None,
                    save=False,
github snapcore / snapcraft / tests / unit / commands / test_login.py View on Github external
)
        self.fake_store_login.mock.side_effect = None

        conf = config.Config()
        conf.set("macaroon", "test-macaroon")
        conf.set("unbound_discharge", "test-unbound-discharge")
        with open("exported-login", "w") as f:
            conf.save(config_fd=f)
            f.flush()

        result = self.run_command(["login", "--with", "exported-login"])

        self.assertThat(result.exit_code, Equals(0))
        self.assertThat(result.output, Contains("Login successful"))
        self.assertThat(
            result.output, MatchesRegex(r".*snaps:.*?No restriction", re.DOTALL)
        )
        self.assertThat(
            result.output, MatchesRegex(r".*channels:.*?No restriction", re.DOTALL)
        )
        self.assertThat(
            result.output, MatchesRegex(r".*permissions:.*?No restriction", re.DOTALL)
        )
        self.assertThat(
            result.output, MatchesRegex(r".*expires:.*?2018-01-01T00:00:00", re.DOTALL)
        )

        self.fake_store_login.mock.assert_called_once_with(
            "",
            "",
            acls=None,
            packages=None,
github snapcore / snapcraft / tests / integration / store / test_store_release.py View on Github external
self.run_snapcraft("snap")

        # Register the snap
        self.register(name)
        # Upload the snap
        snap_file_path = "{}_{}_{}.snap".format(name, version, "all")
        self.assertThat(os.path.join(snap_file_path), FileExists())

        output = self.run_snapcraft(["upload", snap_file_path])
        expected = r".*Ready to release!.*"
        self.assertThat(output, MatchesRegex(expected, flags=re.DOTALL))

        # Release it
        output = self.run_snapcraft(["release", name, "1", "edge"])
        expected = r".*The \'edge\' channel is now open.*"
        self.assertThat(output, MatchesRegex(expected, flags=re.DOTALL))
github snapcore / snapcraft / snaps_tests / __init__.py View on Github external
def assert_command_in_snappy_testbed_with_regex(
        self, command, expected_regex, flags=0, cwd=None
    ):
        if not config.get("skip-install", False):
            output = self.run_command_in_snappy_testbed(command, cwd)
            self.assertThat(output, MatchesRegex(expected_regex, flags=flags))
github openstack / heat / heat_integrationtests / functional / test_instance_group.py View on Github external
# test the number of instances created
        self.assert_instance_count(stack, size)
        # saves info from initial list of instances for comparison later
        init_instances = self.client.resources.list(nested_ident)
        init_names = [inst.resource_name for inst in init_instances]

        # test stack update
        self.update_stack(stack_identifier, updt_template,
                          environment=env, files=files)
        updt_stack = self.client.stacks.get(stack_identifier)

        # test that the launch configuration is replaced
        updt_conf_name = self._stack_output(updt_stack, 'JobServerConfigRef')
        self.assertThat(updt_conf_name,
                        matchers.MatchesRegex(conf_name_pattern))
        self.assertNotEqual(conf_name, updt_conf_name)

        # test that the group size are the same
        updt_instances = self.client.resources.list(nested_ident)
        updt_names = [inst.resource_name for inst in updt_instances]
        self.assertEqual(len(init_names), len(updt_names))
        for res in updt_instances:
            self.assertEqual('UPDATE_COMPLETE', res.resource_status)

        # test that the appropriate number of instance names are the same
        matched_names = set(updt_names) & set(init_names)
        self.assertEqual(num_updates_expected_on_updt, len(matched_names))

        # test that the appropriate number of new instances are created
        self.assertEqual(num_creates_expected_on_updt,
                         len(set(updt_names) - set(init_names)))
github snapcore / snapcraft / integration_tests / store / test_store_push.py View on Github external
version = self.get_unique_version()
        self.copy_project_to_cwd('basic')
        self.update_name_and_version(name, version)

        self.run_snapcraft('snap')

        # Register the snap
        self.register(name)
        # Upload the snap
        snap_file_path = '{}_{}_{}.snap'.format(name, version, 'all')
        self.assertThat(
            os.path.join(snap_file_path), FileExists())

        output = self.run_snapcraft(['upload', snap_file_path])
        expected = r'.*Ready to release!.*'.format(name)
        self.assertThat(output, MatchesRegex(expected, flags=re.DOTALL))
github snapcore / snapcraft / tests / unit / plugins / python / test_python_finder.py View on Github external
def test_host(self):
        """get_python_headers should support the hosts's headers"""

        stage_dir = "stage_dir"

        # Fake out glob so it looks like the headers are installed on the host
        def _fake_glob(pattern):
            if pattern.startswith(os.sep):
                return [os.path.join(os.sep, "usr", "include", "pythontest")]
            return []

        self.mock_glob.side_effect = _fake_glob

        self.assertThat(
            _python_finder.get_python_headers("test", stage_dir=stage_dir),
            MatchesRegex(
                re.escape(os.path.join(os.sep, "usr", "include", "pythontest"))
            ),
github snapcore / snapcraft / tests / unit / pluginhandler / test_pluginhandler.py View on Github external
f.write(file_entry)

        expected = self.expected
        if overwrite:
            with contextlib.suppress(AttributeError):
                expected = self.expected_overwrite
        if isinstance(expected, type) and issubclass(expected, Exception):
            raised = self.assertRaises(
                expected,
                pluginhandler._organize_filesets,
                "part-name",
                self.organize_set,
                base_dir,
                overwrite,
            )
            self.assertThat(str(raised), MatchesRegex(self.expected_message))
        else:
            pluginhandler._organize_filesets(
                "part-name", self.organize_set, base_dir, overwrite
            )
            for expect in expected:
                dir_path = os.path.join(base_dir, expect[1])
                dir_contents = os.listdir(dir_path)
                dir_contents.sort()
                self.assertThat(dir_contents, Equals(expect[0]))
github openstack / python-novaclient / tests / test_shell.py View on Github external
def test_help_on_subcommand(self):
        required = [
            '.*?^usage: nova root-password',
            '.*?^Change the root password',
            '.*?^Positional arguments:',
        ]
        stdout, stderr = self.shell('help root-password')
        for r in required:
            self.assertThat((stdout + stderr),
                            matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
github openstack / python-neutronclient / tests / unit / test_shell.py View on Github external
def test_help(self):
        required = 'usage:'
        help_text = self.shell('help')
        self.assertThat(
            help_text,
            matchers.MatchesRegex(required))