当前位置: 首页>>代码示例>>Python>>正文


Python tools.assert_is函数代码示例

本文整理汇总了Python中xblock.test.tools.assert_is函数的典型用法代码示例。如果您正苦于以下问题:Python assert_is函数的具体用法?Python assert_is怎么用?Python assert_is使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了assert_is函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_with_mixins

def test_with_mixins():
    # Testing model metaclass with mixins
    class FieldsMixin(object):
        """Toy class for field testing"""
        field_a = Integer(scope=Scope.settings)

    class BaseClass(object):
        """Toy class for ModelMetaclass testing"""
        __metaclass__ = ModelMetaclass

    class ChildClass(FieldsMixin, BaseClass):
        """Toy class for ModelMetaclass and field testing"""
        pass

    class GrandchildClass(ChildClass):
        """Toy class for ModelMetaclass and field testing"""
        pass

    # `ChildClass` and `GrandchildClass` both obtain the `fields` attribute
    # from the `ModelMetaclass`. Since this is not understood by static analysis,
    # silence this error for the duration of this test.
    # pylint: disable=E1101

    assert hasattr(ChildClass, 'field_a')
    assert_is(ChildClass.field_a, ChildClass.fields['field_a'])

    assert hasattr(GrandchildClass, 'field_a')
    assert_is(GrandchildClass.field_a, GrandchildClass.fields['field_a'])
开发者ID:renzo-orsini,项目名称:XBlock,代码行数:28,代码来源:test_core.py

示例2: student_view

    def student_view(self, _context):
        """Try out some services."""
        # i18n is available, and works.
        def assert_equals_unicode(str1, str2):
            """`str1` equals `str2`, and both are Unicode strings."""
            assert_equals(str1, str2)
            assert isinstance(str1, unicode)
            assert isinstance(str2, unicode)

        i18n = self.runtime.service(self, "i18n")
        assert_equals_unicode(u"Welcome!", i18n.ugettext("Welcome!"))

        assert_equals_unicode(u"Plural", i18n.ungettext("Singular", "Plural", 0))
        assert_equals_unicode(u"Singular", i18n.ungettext("Singular", "Plural", 1))
        assert_equals_unicode(u"Plural", i18n.ungettext("Singular", "Plural", 2))

        when = datetime(2013, 2, 14, 22, 30, 17)
        assert_equals_unicode(u"2013-02-14", i18n.strftime(when, "%Y-%m-%d"))
        assert_equals_unicode(u"Feb 14, 2013", i18n.strftime(when, "SHORT_DATE"))
        assert_equals_unicode(u"Thursday, February 14, 2013", i18n.strftime(when, "LONG_DATE"))
        assert_equals_unicode(u"Feb 14, 2013 at 22:30", i18n.strftime(when, "DATE_TIME"))
        assert_equals_unicode(u"10:30:17 PM", i18n.strftime(when, "TIME"))

        # secret_service is available.
        assert_equals(self.runtime.service(self, "secret_service"), 17)

        # no_such_service is not available, and raises an exception, because we
        # said we needed it.
        with assert_raises_regexp(NoSuchServiceError, "is not available"):
            self.runtime.service(self, "no_such_service")

        # another_not_service is not available, and returns None, because we
        # didn't need it, we only wanted it.
        assert_is(self.runtime.service(self, "another_not_service"), None)
开发者ID:Maqlan,项目名称:XBlock,代码行数:34,代码来源:test_runtime.py

示例3: test_ambiguous_plugins

def test_ambiguous_plugins():
    # We can load ok blocks even if there are bad blocks.
    cls = XBlock.load_class("good_block")
    assert_is(cls, UnambiguousBlock)

    # Trying to load bad blocks raises an exception.
    expected_msg = (
        "Ambiguous entry points for bad_block: "
        "xblock.test.test_plugin.AmbiguousBlock1, "
        "xblock.test.test_plugin.AmbiguousBlock2"
    )
    with assert_raises_regexp(AmbiguousPluginError, expected_msg):
        XBlock.load_class("bad_block")

    # We can use our own function as the select function.
    class MyOwnException(Exception):
        """We'll raise this from `boom`."""
        pass

    def boom(identifier, entry_points):
        """A select function to prove user-defined functions are called."""
        assert len(entry_points) == 2
        assert identifier == "bad_block"
        raise MyOwnException("This is boom")

    with assert_raises_regexp(MyOwnException, "This is boom"):
        XBlock.load_class("bad_block", select=boom)
开发者ID:Randomwak,项目名称:XBlock,代码行数:27,代码来源:test_plugin.py

示例4: student_view

    def student_view(self, _context):
        """Try out some services."""
        # i18n is available, and works.
        def assert_equals_unicode(str1, str2):
            """`str1` equals `str2`, and both are Unicode strings."""
            assert_equals(str1, str2)
            assert isinstance(str1, unicode)
            assert isinstance(str2, unicode)

        i18n = self.runtime.service(self, "i18n")
        assert_equals_unicode(u"Welcome!", i18n.ugettext("Welcome!"))

        assert_equals_unicode(u"Plural", i18n.ungettext("Singular", "Plural", 0))
        assert_equals_unicode(u"Singular", i18n.ungettext("Singular", "Plural", 1))
        assert_equals_unicode(u"Plural", i18n.ungettext("Singular", "Plural", 2))

        # secret_service is available.
        assert_equals(self.runtime.service(self, "secret_service"), 17)

        # no_such_service is not available, and raises an exception, because we
        # said we needed it.
        with assert_raises(NoSuchServiceError):
            self.runtime.service(self, "no_such_service")

        # another_not_service is not available, and returns None, because we
        # didn't need it, we only wanted it.
        assert_is(self.runtime.service(self, "another_not_service"), None)
开发者ID:cecep-edu,项目名称:XBlock,代码行数:27,代码来源:test_runtime.py

示例5: test_nosuch_plugin

def test_nosuch_plugin():
    # We can provide a default class to return for missing plugins.
    cls = XBlock.load_class("nosuch_block", default=UnambiguousBlock)
    assert_is(cls, UnambiguousBlock)

    # If we don't provide a default class, an exception is raised.
    with assert_raises_regexp(PluginMissingError, "nosuch_block"):
        XBlock.load_class("nosuch_block")
开发者ID:Randomwak,项目名称:XBlock,代码行数:8,代码来源:test_plugin.py

示例6: test_set_with_save_preserves_identity

    def test_set_with_save_preserves_identity(self):
        first_get = self.get()
        self.set(self.new_value)
        self.block.save()
        second_get = self.get()

        assert_is(self.new_value, second_get)
        assert_is_not(first_get, second_get)
开发者ID:AdityaKashyap,项目名称:XBlock,代码行数:8,代码来源:test_fields_api.py

示例7: test_set_preserves_identity

    def test_set_preserves_identity(self):
        first_get = self.get()
        assert_is_not(self.new_value, first_get)
        self.set(self.new_value)
        second_get = self.get()

        assert_is(self.new_value, second_get)
        assert_is_not(first_get, second_get)
开发者ID:AdityaKashyap,项目名称:XBlock,代码行数:8,代码来源:test_fields_api.py

示例8: test_only_generate_classes_once

    def test_only_generate_classes_once(self):
        assert_is(
            self.mixologist.mix(FieldTester),
            self.mixologist.mix(FieldTester),
        )

        assert_is_not(
            self.mixologist.mix(FieldTester),
            self.mixologist.mix(TestXBlock),
        )
开发者ID:Maqlan,项目名称:XBlock,代码行数:10,代码来源:test_runtime.py

示例9: test_model_metaclass

def test_model_metaclass():
    class ModelMetaclassTester(object):
        """Toy class for ModelMetaclass testing"""
        __metaclass__ = ModelMetaclass

        field_a = Integer(scope=Scope.settings)
        field_b = Integer(scope=Scope.content)

        def __init__(self, field_data):
            self._field_data = field_data

    class ChildClass(ModelMetaclassTester):
        """Toy class for ModelMetaclass testing"""
        pass

    # `ModelMetaclassTester` and `ChildClass` both obtain the `fields` attribute
    # from the `ModelMetaclass`. Since this is not understood by static analysis,
    # silence this error for the duration of this test.
    # pylint: disable=E1101
    assert hasattr(ModelMetaclassTester, 'field_a')
    assert hasattr(ModelMetaclassTester, 'field_b')

    assert_is(ModelMetaclassTester.field_a, ModelMetaclassTester.fields['field_a'])
    assert_is(ModelMetaclassTester.field_b, ModelMetaclassTester.fields['field_b'])

    assert hasattr(ChildClass, 'field_a')
    assert hasattr(ChildClass, 'field_b')

    assert_is(ChildClass.field_a, ChildClass.fields['field_a'])
    assert_is(ChildClass.field_b, ChildClass.fields['field_b'])
开发者ID:renzo-orsini,项目名称:XBlock,代码行数:30,代码来源:test_core.py

示例10: test_multiply_mixed

    def test_multiply_mixed(self):
        mixalot = Mixologist([ThirdMixin, FirstMixin])

        pre_mixed = mixalot.mix(self.mixologist.mix(FieldTester))
        post_mixed = self.mixologist.mix(mixalot.mix(FieldTester))

        assert_is(pre_mixed.fields['field'], FirstMixin.field)
        assert_is(post_mixed.fields['field'], ThirdMixin.field)

        assert_is(FieldTester, pre_mixed.unmixed_class)
        assert_is(FieldTester, post_mixed.unmixed_class)

        assert_equals(4, len(pre_mixed.__bases__))  # 1 for the original class + 3 mixin classes
        assert_equals(4, len(post_mixed.__bases__))
开发者ID:Maqlan,项目名称:XBlock,代码行数:14,代码来源:test_runtime.py

示例11: test_mixin_fields

 def test_mixin_fields(self):
     assert_is(FirstMixin.fields['field'], FirstMixin.field)
开发者ID:Maqlan,项目名称:XBlock,代码行数:2,代码来源:test_runtime.py

示例12: test_get_with_save_preserves_identity

    def test_get_with_save_preserves_identity(self):
        first_get = self.get()
        self.block.save()
        second_get = self.get()

        assert_is(first_get, second_get)
开发者ID:AdityaKashyap,项目名称:XBlock,代码行数:6,代码来源:test_fields_api.py

示例13: test_get_preserves_identity

    def test_get_preserves_identity(self):
        first_get = self.get()
        second_get = self.get()

        assert_is(first_get, second_get)
开发者ID:AdityaKashyap,项目名称:XBlock,代码行数:5,代码来源:test_fields_api.py

示例14: test_duplicate_mixins

 def test_duplicate_mixins(self):
     singly_mixed = self.mixologist.mix(FieldTester)
     doubly_mixed = self.mixologist.mix(singly_mixed)
     assert_is(singly_mixed, doubly_mixed)
     assert_is(FieldTester, singly_mixed.unmixed_class)
开发者ID:Maqlan,项目名称:XBlock,代码行数:5,代码来源:test_runtime.py

示例15: test_mixed_fields

 def test_mixed_fields(self):
     mixed = self.mixologist.mix(FieldTester)
     assert_is(mixed.fields['field'], FirstMixin.field)
     assert_is(mixed.fields['field_a'], FieldTester.field_a)
开发者ID:Maqlan,项目名称:XBlock,代码行数:4,代码来源:test_runtime.py


注:本文中的xblock.test.tools.assert_is函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。