示例#1
0
 class BadEnum(MatrixEnum):
     ONE = Member(code=1, description='one',
                  plain_text='plaintext').extra(foo=1)
     TWO = Member(code=2,
                  description='two',
                  plain_text='something else plain').extra(foo=2,
                                                           bar=2)
示例#2
0
 class BadEnum(MatrixEnum):
     ONE = Member(value=1,
                  description='one',
                  plain_text="plaintext")
     TWO = Member(value=2,
                  description='one',
                  plain_text="something else plain")
示例#3
0
    def test_simple_enum(self):
        class WorkingEnum(MatrixEnum):
            ONE = Member(code=1, description='one', plain_text='plaintext')
            TWO = Member(code=2,
                         description='two',
                         plain_text='something else plain')

        assert isinstance(WorkingEnum.ONE, WorkingEnum)

        assert WorkingEnum.ONE is WorkingEnum['ONE']
        assert WorkingEnum(WorkingEnum.ONE) is WorkingEnum.ONE
        assert WorkingEnum('ONE') is WorkingEnum.ONE
        assert WorkingEnum(1) is WorkingEnum.ONE
        assert WorkingEnum(1) == WorkingEnum.ONE
        assert WorkingEnum('one') is WorkingEnum('plaintext')
        assert WorkingEnum.ONE.value != Member(code=1)
        assert WorkingEnum.ONE.description == 'one'
        assert WorkingEnum.ONE.plain_text == 'plaintext'
        assert WorkingEnum.ONE.code == 1
        assert WorkingEnum.ONE.code == WorkingEnum.ONE.value.code
        assert WorkingEnum.ONE != WorkingEnum.TWO
        assert WorkingEnum.ONE.value != WorkingEnum.TWO.value
        assert WorkingEnum(1) != WorkingEnum(2)
        assert WorkingEnum('one') != WorkingEnum('two')
        assert WorkingEnum['ONE'] != WorkingEnum['TWO']

        identical_member = Member(code=1,
                                  description='one',
                                  plain_text="plaintext")
        assert WorkingEnum.ONE.value == identical_member
        assert WorkingEnum.ONE.value is not identical_member
        for item in WorkingEnum:
            assert item in WorkingEnum
示例#4
0
        class MyEnum(MatrixEnum):
            ONE = Member(code=1, description='one').extra(foo='bar')
            TWO = Member(code=2, description='two').extra(foo='baz')

            @classmethod
            def test_func(cls):
                return "Test"
示例#5
0
 class WorkingEnum(MatrixEnum):
     ONE = Member(code=1, description='one',
                  plain_text='plaintext').extra(foo='1')
     TWO = Member(code=2,
                  description='two',
                  plain_text='something else plain').extra(foo='2')
     THREE = Member(code=3,
                    description='three',
                    plain_text='even more plain').extra(foo='1')
示例#6
0
        class WorkingEnum(MatrixEnum):
            ONE = Member(code=1)
            TWO = Member(code=2)

            def code_label(self):
                return "My code is {}".format(self.code)

            @classmethod
            def total_codes(cls):
                return sum(e.code for e in cls)
示例#7
0
 class Enum(MatrixEnum):
     _order_ = 'TWO ONE'
     TWO = Member(code=2)
     ONE = Member(code=1)
示例#8
0
 class BadEnum(MatrixEnum):
     ONE = Member(code=1).extra(foo=1).extra(bar=3)
     TWO = Member(code=2).extra(foo=2).extra(bar=3)
示例#9
0
 class BadEnum(MatrixEnum):
     ONE = Member(foo=1)
     TWO = Member(bar=2)
示例#10
0
 class MyEnum(MatrixEnum):
     ONE = Member(code=1)
     NONE = Member(code=None)
示例#11
0
 class BadEnum(MatrixEnum):
     ONE = Member(code=1)
     code = Member(code=2)
示例#12
0
 class BadEnum(MatrixEnum):
     ONE = Member(code=1, description='foo', plain_text="plaintext")
     TWO = Member(code=2,
                  description='ONE',
                  plain_text="something else plain")
示例#13
0
 class WorkingEnum(MatrixEnum):
     ONE = Member(code=1, description='one', plain_text='plaintext')
     TWO = Member(code=2,
                  description='two',
                  plain_text='something else plain')
示例#14
0
 class BadEnum(MatrixEnum):
     ONE = Member(code=1, description='one')
     TWO = Member(code=2, description='two')
     THREE = (3, "three")
示例#15
0
 class MisorderedEnum(MatrixEnum):
     _order_ = 'TWO ONE'
     ONE = Member(code=1)
     TWO = Member(code=2)
示例#16
0
 class IgnoredEnum(MatrixEnum):
     _ignore_ = 'IGNORE_ME'
     ONE = Member(code=1)
     TWO = Member(code=2)
     IGNORE_ME = Member(code=3)
示例#17
0
 class BadEnum1(MatrixEnum):
     _reversed = Member(code=1)
     _other = Member(code=2)
示例#18
0
 def test_duplicated_attr_values(self):
     with pytest.raises(
             ValueError,
             match=r"Value '1' duplicated within Member specification."):
         Member(code=1, description='one', plain_text=1)
示例#19
0
 def test_invalid_attrs(self):
     with pytest.raises(ValueError,
                        match=r"Member attribute 'extra' is not allowed."):
         Member(
             extra=6)  # 'extra' is a function on Member and cannot be used
示例#20
0
 class MyEnum(MatrixEnum):
     ONE = Member(code=1)
     TWO = Member(code=2)
示例#21
0
 def test_member_hashing(self):
     assert hash(Member(foo=1)) != hash(Member(bar=1))