Python ddt 模块,ddt() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用ddt.ddt()

项目:edx-enterprise    作者:edx    | 项目源码 | 文件源码
def test_get_paginated_response_correct_query_parameters(self):
        """
        Verify get_paginated_response returns correct response.
        """
        self.data['next'] = '{discovery_uri}?page=3'.format(discovery_uri=DISCOVERY_URI)
        self.data['previous'] = '{discovery_uri}?page=1'.format(discovery_uri=DISCOVERY_URI)
        expected_next = '{enterprise_uri}?page=3'.format(enterprise_uri=ENTERPRISE_URI)
        expected_previous = '{enterprise_uri}?page=1'.format(enterprise_uri=ENTERPRISE_URI)
        request = APIRequestFactory().get(
            reverse('catalogs-list') + "?page=2",
            SERVER_NAME="testserver.enterprise",
        )

        # Update authentication parameters based in ddt data.
        response = get_paginated_response(self.data, request)

        assert response.data.get('next') == expected_next
        assert response.data.get('previous') == expected_previous
项目:deb-python-ddt    作者:openstack    | 项目源码 | 文件源码
def test_ddt_data_name_attribute():
    """
    Test the ``__name__`` attribute handling of ``data`` items with ``ddt``
    """

    def hello():
        pass

    class Myint(int):
        pass

    class Mytest(object):
        pass

    d1 = Myint(1)
    d1.__name__ = 'data1'

    d2 = Myint(2)

    data_hello = data(d1, d2)(hello)
    setattr(Mytest, 'test_hello', data_hello)

    ddt_mytest = ddt(Mytest)
    assert_is_not_none(getattr(ddt_mytest, 'test_hello_1_data1'))
    assert_is_not_none(getattr(ddt_mytest, 'test_hello_2_2'))
项目:deb-python-ddt    作者:openstack    | 项目源码 | 文件源码
def test_load_yaml_without_yaml_support():
    """
    Test that YAML files are not loaded if YAML is not installed.
    """

    @ddt
    class NoYAMLInstalledTest(object):

        @file_data('test_data_dict.yaml')
        def test_file_data_yaml_dict(self, value):
            assert_true(has_three_elements(value))

    tests = filter(_is_test, NoYAMLInstalledTest.__dict__)

    obj = NoYAMLInstalledTest()
    for test in tests:
        method = getattr(obj, test)
        assert_raises(ValueError, method)
项目:edx-enterprise    作者:edx    | 项目源码 | 文件源码
def test_get_paginated_response(self, previous_page, next_page, expected_previous, expected_next):
        """
        Verify get_paginated_response returns correct response.
        """
        self.data['next'] = next_page
        self.data['previous'] = previous_page

        # Update authentication parameters based in ddt data.
        response = get_paginated_response(self.data, self.request)

        assert response.data.get('next') == expected_next
        assert response.data.get('previous') == expected_previous
项目:deb-python-ddt    作者:openstack    | 项目源码 | 文件源码
def test_ddt():
    """
    Test the ``ddt`` class decorator
    """
    tests = len(list(filter(_is_test, Dummy.__dict__)))
    assert_equal(tests, 4)
项目:deb-python-ddt    作者:openstack    | 项目源码 | 文件源码
def test_ddt_data_unicode():
    """
    Test that unicode strings are converted to function names correctly
    """

    def hello():
        pass

    # We test unicode support separately for python 2 and 3

    if six.PY2:

        @ddt
        class Mytest(object):
            @data(u'ascii', u'non-ascii-\N{SNOWMAN}', {u'\N{SNOWMAN}': 'data'})
            def test_hello(self, val):
                pass

        assert_is_not_none(getattr(Mytest, 'test_hello_1_ascii'))
        assert_is_not_none(getattr(Mytest, 'test_hello_2_non_ascii__u2603'))
        assert_is_not_none(getattr(Mytest, 'test_hello_3'))

    elif six.PY3:

        @ddt
        class Mytest(object):
            @data('ascii', 'non-ascii-\N{SNOWMAN}', {'\N{SNOWMAN}': 'data'})
            def test_hello(self, val):
                pass

        assert_is_not_none(getattr(Mytest, 'test_hello_1_ascii'))
        assert_is_not_none(getattr(Mytest, 'test_hello_2_non_ascii__'))
        assert_is_not_none(getattr(Mytest, 'test_hello_3'))
项目:deb-python-ddt    作者:openstack    | 项目源码 | 文件源码
def test_ddt_data_object():
    """
    Test not using value if non-trivial arguments
    """

    @ddt
    class Mytest(object):
        @data(object())
        def test_object(self, val):
            pass

    assert_is_not_none(getattr(Mytest, 'test_object_1'))