How to use the testtools.matchers.Equals 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 open-io / oio-sds / tests / functional / cli / object / test_object.py View on Github external
output = self.openio('container show ' + cname + opts)
        data = self.json_loads(output)
        self.assert_show_fields(data, CONTAINER_FIELDS)

        fake_cname = cname
        if auto:
            fake_cname = '_'
        obj_name = os.path.basename(obj_file)
        opts = self.get_opts([], 'json')
        output = self.openio('object create ' + auto + ' ' + fake_cname +
                             ' ' + obj_file + ' ' + obj_file + ' ' + opts)
        data = self.json_loads(output)
        self.assert_list_fields(data, OBJ_HEADERS)
        self.assertThat(len(data), Equals(2))
        item = data[0]
        self.assertThat(item['Name'], Equals(obj_name))
        self.assertThat(item['Size'], Equals(len(test_content)))
        self.assertThat(item['Hash'], Equals(checksum))

        opts = self.get_opts([], 'json')
        output = self.openio('object list ' + cname + opts)
        listing = self.json_loads(output)
        self.assert_list_fields(listing, OBJ_HEADERS)
        self.assertThat(len(data), Equals(2))
        item = data[0]
        self.assertThat(item['Name'], Equals(obj_name))
        self.assertThat(item['Size'], Equals(len(test_content)))
        self.assertThat(item['Hash'], Equals(checksum))

        output = self.openio('object save ' + cname + ' ' + obj_name)
        self.addCleanup(os.remove, obj_name)
        self.assertOutput('', output)
github snapcore / snapcraft / tests / unit / commands / test_sign_build.py View on Github external
def test_sign_build_nonexisting_snap(self, mock_installed, mock_check_output):
        mock_installed.return_value = True

        result = self.run_command(["sign-build", "nonexisting.snap"])

        self.assertThat(result.exit_code, Equals(2))
        self.assertThat(
            result.output,
            Contains(
                'Error: Invalid value for "": File "nonexisting.snap" does not exist.\n'
            ),
        )
        self.assertThat(mock_check_output.call_count, Equals(0))
github snapcore / snapcraft / tests / unit / plugins / test_kernel.py View on Github external
modules_dir = os.path.join(
                plugin.builddir, "initrd-staging", "lib", "modules", "4.4.2"
            )
            if os.path.exists(modules_dir):
                return
            os.makedirs(modules_dir)

        self.check_call_mock.side_effect = fake_unpack

        plugin.build()

        self._assert_generic_check_call(
            plugin.builddir, plugin.installdir, plugin.os_snap
        )

        self.assertThat(self.run_mock.call_count, Equals(2))
        self.run_mock.assert_has_calls(
            [
                mock.call(["make", "-j2", "bzImage", "modules"]),
                mock.call(
                    [
                        "make",
                        "-j2",
                        "CONFIG_PREFIX={}".format(plugin.installdir),
                        "modules_install",
                        "INSTALL_MOD_PATH={}".format(plugin.installdir),
                        "firmware_install",
                        "INSTALL_FW_PATH={}".format(
                            os.path.join(plugin.installdir, "lib", "firmware")
                        ),
                    ]
                ),
github snapcore / snapcraft / tests / unit / extractors / test_metadata.py View on Github external
def test_eq(self):
        metadata1 = ExtractedMetadata(summary="summary")
        metadata2 = ExtractedMetadata(summary="summary")
        self.assertThat(metadata1, Equals(metadata2))
github snapcore / snapcraft / tests / unit / test_log.py View on Github external
def test_configure_must_send_errors_to_stderr(self):
        logger_name = self.id()
        log.configure(logger_name)
        logger = logging.getLogger(logger_name)
        # Overwrite the level to log everything.
        logger.setLevel(logging.DEBUG)

        logger.error("Test error")
        logger.critical("Test critical")

        stderr = self.fake_terminal.getvalue(stderr=True)
        expected_error = "{}Test error\033[0m".format(self.error_color)
        self.assertThat(stderr, Contains(expected_error))
        expected_crit = "{}Test critical\033[0m".format(self.critical_color)
        self.assertThat(stderr, Contains(expected_crit))
        self.assertThat(self.fake_terminal.getvalue(), Equals(""))
github snapcore / snapcraft / tests / unit / build_providers / multipass / test_instance_info.py View on Github external
def test_initialize(self):
        instance_info = InstanceInfo(
            name="instance-name",
            state="RUNNING",
            image_release="16.04 LTS",
            mounts=dict(),
        )

        self.assertThat(instance_info.name, Equals("instance-name"))
        self.assertThat(instance_info.state, Equals("RUNNING"))
        self.assertThat(instance_info.image_release, Equals("16.04 LTS"))
        self.assertThat(instance_info.is_stopped(), Equals(False))
github snapcore / snapcraft / tests / unit / states / test_stage.py View on Github external
def test_yaml_conversion(self, init_spy):
        state_string = yaml_utils.dump(self.state)

        # Verify that the dumped tag was correct
        self.assertThat(state_string.splitlines()[0], Equals("!StageState"))

        # Now verify the conversion
        state_from_yaml = yaml_utils.load(state_string)
        self.assertThat(state_from_yaml, Equals(self.state))

        # Verify that init was not called
        init_spy.assert_not_called()
github snapcore / snapcraft / tests / unit / plugins / test_colcon.py View on Github external
plugin.pull()

        self.assert_rosdep_setup(
            plugin.options.colcon_rosdistro,
            os.path.join(plugin.sourcedir, "src"),
            os.path.join(plugin.partdir, "rosdep"),
            self.ubuntu_distro,
            plugin.PLUGIN_STAGE_SOURCES,
            plugin.PLUGIN_STAGE_KEYRINGS,
        )

        # Verify that dependencies were found as expected. TODO: Would really
        # like to use ANY here instead of verifying explicit arguments, but
        # Python issue #25195 won't let me.
        self.assertThat(self.dependencies_mock.call_count, Equals(1))
        self.assertThat(self.dependencies_mock.call_args[0][0], Equals({"my_package"}))

        # Verify that the dependencies were installed
        self.ubuntu_mock.return_value.get.assert_called_with(
            _CompareContainers(self, ["foo", "bar", "baz"])
        )
        self.ubuntu_mock.return_value.unpack.assert_called_with(plugin.installdir)
github snapcore / snapcraft / tests / unit / states / test_stage.py View on Github external
def test_properties_of_interest(self):
        properties = self.state.properties_of_interest(self.part_properties)
        self.assertThat(len(properties), Equals(3))
        self.assertThat(properties["filesets"], Equals({"qux": "quux"}))
        self.assertThat(properties["override-stage"], Equals("touch override-stage"))
        self.assertThat(properties["stage"], Equals(["baz"]))
github snapcore / snapcraft / tests / unit / test_elf.py View on Github external
def test_bin_echo(self):
        # Try parsing a file without the pyelftools logic mocked out
        elf_file = elf.ElfFile(path=sys.executable)

        self.assertThat(elf_file.path, Equals(sys.executable))

        # The arch attribute will be a tuple of three strings
        self.assertTrue(isinstance(elf_file.arch, tuple))
        self.assertThat(len(elf_file.arch), Equals(3))
        self.assertThat(elf_file.arch[0], StartsWith("ELFCLASS"))
        self.assertThat(elf_file.arch[1], StartsWith("ELFDATA"))
        self.assertThat(elf_file.arch[2], StartsWith("EM_"))

        # We expect Python to be a dynamic linked executable with an
        # ELF interpreter.
        self.assertTrue(isinstance(elf_file.interp, str))
        self.assertThat(elf_file.interp, NotEquals(""))

        # Python is not a shared library, so has no soname
        self.assertThat(elf_file.soname, Equals(""))