How to use the ddt.unpack function in ddt

To help you get started, we’ve selected a few ddt 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 elifesciences / elife-bot / tests / activity / test_activity_ftp_article.py View on Github external
    @unpack
    def test_move_or_repackage_pmc_zip(self, input_zip_file_path, doi_id, workflow,
                                       expected_zip_file, expected_zip_file_contents):
        # create activity directories
        self.activity.make_activity_directories()
        # copy in some sample data
        dest_input_zip_file_path = os.path.join(
            self.activity.directories.get("INPUT_DIR"), input_zip_file_path.split('/')[-1])
        shutil.copy(input_zip_file_path, dest_input_zip_file_path)
        # call the activity function
        self.activity.move_or_repackage_pmc_zip(doi_id, workflow)
        # confirm the output
        ftp_outbox_dir = self.activity.directories.get("FTP_TO_SOMEWHERE_DIR")
        self.assertTrue(expected_zip_file in os.listdir(ftp_outbox_dir))
        with zipfile.ZipFile(os.path.join(ftp_outbox_dir, expected_zip_file)) as zip_file:
            self.assertEqual(sorted(zip_file.namelist()), sorted(expected_zip_file_contents))
github openstack / rally-openstack / tests / unit / scenarios / neutron / test_security_groups.py View on Github external
    @ddt.unpack
    def test_create_and_show_security_group_with_none_group(
            self, security_group_create_args=None):
        scenario = security_groups.CreateAndShowSecurityGroup()
        security_group_data = security_group_create_args or {}
        scenario._create_security_group = mock.Mock()
        scenario._show_security_group = mock.Mock()

        # Negative case: security_group isn't created
        scenario._create_security_group.return_value = None
        self.assertRaises(rally_exceptions.RallyAssertionError,
                          scenario.run, security_group_create_args)
        scenario._create_security_group.assert_called_with(
            **security_group_data)
github openSUSE / py2pack / test / test_py2pack.py View on Github external
    @unpack
    def test_license_from_classifiers(self, value, expected):
        d = {'classifiers': value}
        self.assertEqual(py2pack._license_from_classifiers(d), expected)
github openstack / rally / tests / unit / task / processing / test_charts.py View on Github external
    @ddt.unpack
    def test_views(self, base_size=None, min_value=None, max_value=None,
                   expected=None):
        chart = self.HistogramChart({"total_iteration_count": base_size})
        self.assertEqual(expected, chart._init_views(min_value, max_value))
github bdhowald / hows_my_driving / test / traffic_violations / test_traffic_violations_aggregator.py View on Github external
    @ddt.unpack
    def test_infer_plate_and_state_data(self, plate_tuples, potential_vehicle_data):
        self.assertEqual(
            self.aggregator._infer_plate_and_state_data(plate_tuples),
            [Vehicle(**data) for data in potential_vehicle_data])
github dmytrostriletskyi / pdbe / tests / test_utils.py View on Github external
    @unpack
    def test_is_function_sign_in_line(self, line, expected):
        """
        Case: needs to detect function declaration.
        Expected: only line, that contains `def`, `(` and `):` substring confirmed.
        """
        result = is_function_sign_in_line(line)
        self.assertEqual(expected, result)
github openstack / rally / tests / unit / plugins / openstack / services / identity / test_keystone_v2.py View on Github external
    @ddt.unpack
    def test_update_tenant(self, tenant_id, name, enabled, description):

        self.name_generator.side_effect = ("foo", "bar")
        self.service.update_tenant(tenant_id,
                                   name=name,
                                   description=description,
                                   enabled=enabled)

        name = "foo" if name is True else name
        description = "bar" if description is True else description

        self.kc.tenants.update.assert_called_once_with(
            tenant_id, name=name, description=description, enabled=enabled)
github openstack / rally / tests / unit / plugins / openstack / scenarios / manila / test_shares.py View on Github external
    @ddt.unpack
    def test_create_and_shrink_shares(self, params, new_size):
        size = params.get("size", 2)
        share_group_id = params.get("share_group_id", None)
        snapshot_id = params.get("snapshot_id", None)
        description = params.get("description", None)
        metadata = params.get("metadata", None)
        share_network = params.get("share_network", None)
        share_type = params.get("share_type", None)
        is_public = params.get("is_public", False)
        availability_zone = params.get("availability_zone", None)

        fake_share = mock.MagicMock()
        scenario = shares.CreateAndShrinkShare(self.context)
        scenario._create_share = mock.MagicMock(return_value=fake_share)
        scenario._shrink_share = mock.MagicMock()
github openstack / rally-openstack / tests / unit / scenarios / neutron / test_utils.py View on Github external
    @ddt.unpack
    @mock.patch("random.choice", side_effect=lambda l: l[0])
    def test_get_or_create_network(self, mock_random_choice,
                                   network_create_args=None, context=None):
        self.scenario.context = context
        self.scenario._create_network = mock.Mock(
            return_value={"network": mock.Mock()})

        network = self.scenario._get_or_create_network(network_create_args)

        # ensure that the return value is the proper type either way
        self.assertIn("network", network)

        if "networks" in context["tenant"]:
            self.assertEqual(network,
                             {"network": context["tenant"]["networks"][0]})
            self.assertFalse(self.scenario._create_network.called)
github openstack / rally / tests / unit / plugins / openstack / scenarios / neutron / test_security_groups.py View on Github external
    @ddt.unpack
    def test_create_and_list_security_group_rules_with_fails(
            self, security_group_args=None,
            security_group_rule_args=None):
        scenario = security_groups.CreateAndListSecurityGroupRules()

        security_group_data = security_group_args or {}
        security_group_rule_data = security_group_rule_args or {}

        security_group = mock.MagicMock()
        security_group_rule = {"security_group_rule": {"id": 1, "name": "f1"}}
        scenario._create_security_group = mock.MagicMock()
        scenario._create_security_group_rule = mock.MagicMock()
        scenario._list_security_group_rules = mock.MagicMock()
        scenario._create_security_group_rule.return_value = security_group_rule
        scenario._list_security_group_rules.return_value = {
            "security_group_rules": [{"id": 1, "name": "f1"},