示例#1
0
    def test_flag_basics(self):

        cls = define_enum('FoobarAllFlags', dict(FOO=1, BAR=2, FOOBAR=3).items(), is_flags=True)
        foo = cls.FOO
        bar = cls.BAR

        foobar = foo | bar
        self.assertIs(foobar, cls.FOOBAR)

        foo2 = foobar & foo
        self.assertIs(foo2, foo)

        bar2 = foobar ^ foo
        self.assertIs(bar2, bar)

        bar3 = foobar & ~foo
        self.assertIs(bar3, bar)
示例#2
0
    def test_flag_basics(self):

        cls = define_enum('FoobarAllFlags', dict(FOO=1, BAR=2, FOOBAR=3).items(), is_flags=True)
        foo = cls.FOO
        bar = cls.BAR

        foobar = foo | bar
        self.assertIs(foobar, cls.FOOBAR)

        foo2 = foobar & foo
        self.assertIs(foo2, foo)

        bar2 = foobar ^ foo
        self.assertIs(bar2, bar)

        bar3 = foobar & ~foo
        self.assertIs(bar3, bar)
示例#3
0
    def test_multiple_names(self):

        cls = define_enum('FFooBBar', (
            ('FOO', 1),
            ('F', 1),
            ('BAR', 2),
            ('B', 2),
        ))

        self.assertIs(cls.F, cls.FOO)

        self.assertEqual(cls.F.name, 'FOO')
        self.assertNotEqual(cls.F.name, 'F')  # This is actually the string.

        self.assertEqual(cls.F, 'FOO')
        self.assertEqual(cls.F, 'F')
        self.assertNotEqual(cls.F, 'BAR')
        self.assertNotEqual(cls.F, 'B')
        self.assertRaises(ValueError, lambda: cls.F == 'x')
示例#4
0
文件: test_enums.py 项目: zh217/PyAV
    def test_multiple_names(self):

        cls = define_enum('FFooBBar', (
            ('FOO', 1),
            ('F', 1),
            ('BAR', 2),
            ('B', 2),
        ))

        self.assertIs(cls.F, cls.FOO)

        self.assertEqual(cls.F.name, 'FOO')
        self.assertNotEqual(cls.F.name, 'F')  # This is actually the string.

        self.assertEqual(cls.F, 'FOO')
        self.assertEqual(cls.F, 'F')
        self.assertNotEqual(cls.F, 'BAR')
        self.assertNotEqual(cls.F, 'B')
        self.assertRaises(ValueError, lambda: cls.F == 'x')
示例#5
0
 def define_foobar(self, **kwargs):
     return define_enum('Foobar', (
         ('FOO', 1),
         ('BAR', 2),
     ), **kwargs)
示例#6
0
import pickle

from av.enums import EnumType, define_enum

from .common import TestCase


# This must be at the top-level.
PickleableFooBar = define_enum('PickleableFooBar', [('FOO', 1)])


class TestEnums(TestCase):

    def define_foobar(self, **kwargs):
        return define_enum('Foobar', (
            ('FOO', 1),
            ('BAR', 2),
        ), **kwargs)

    def test_basics(self):

        cls = self.define_foobar()

        self.assertIsInstance(cls, EnumType)

        foo = cls.FOO

        self.assertIsInstance(foo, cls)
        self.assertEqual(foo.name, 'FOO')
        self.assertEqual(foo.value, 1)
示例#7
0
文件: test_enums.py 项目: zh217/PyAV
 def define_foobar(self, **kwargs):
     return define_enum('Foobar', (
         ('FOO', 1),
         ('BAR', 2),
     ), **kwargs)
示例#8
0
文件: test_enums.py 项目: zh217/PyAV
import pickle

from av.enums import EnumType, define_enum

from .common import TestCase

# This must be at the top-level.
PickleableFooBar = define_enum('PickleableFooBar', [('FOO', 1)])


class TestEnums(TestCase):
    def define_foobar(self, **kwargs):
        return define_enum('Foobar', (
            ('FOO', 1),
            ('BAR', 2),
        ), **kwargs)

    def test_basics(self):

        cls = self.define_foobar()

        self.assertIsInstance(cls, EnumType)

        foo = cls.FOO

        self.assertIsInstance(foo, cls)
        self.assertEqual(foo.name, 'FOO')
        self.assertEqual(foo.value, 1)

        self.assertNotIsInstance(foo, PickleableFooBar)