Beispiel #1
0
    def test_name_as_unicode(self):
        """Test that the name can be unicode.

        In Python 3, str == unicode. This test is really only interesting in Python 2.
        """
        if tests_base.IS_PY3:
            name = tests_base.make_name()
        else:
            name = tests_base.make_name().decode('ASCII')
        mem = posix_ipc.SharedMemory(name, posix_ipc.O_CREX, size=4096)
        self.assertEqual(name, mem.name)
        mem.close_fd()
        mem.unlink()
    def test_name_as_unicode(self):
        """Test that the name can be unicode.

        In Python 3, str == unicode. This test is really only interesting in Python 2.
        """
        if tests_base.IS_PY3:
            name = tests_base.make_name()
        else:
            name = unicode(tests_base.make_name(), 'ASCII')
        sem = posix_ipc.Semaphore(name, posix_ipc.O_CREX)
        self.assertEqual(name, sem.name)
        sem.unlink()
        sem.close()
        def test_name_as_unicode(self):
            """Test that the name can be unicode.

            In Python 3, str == unicode. This test is really only interesting in Python 2.
            """
            if tests_base.IS_PY3:
                name = tests_base.make_name()
            else:
                name = unicode(tests_base.make_name(), 'ASCII')
            mq = posix_ipc.MessageQueue(name, posix_ipc.O_CREX)
            self.assertEqual(name, mq.name)
            mq.unlink()
            mq.close()
Beispiel #4
0
    def test_name_as_unicode(self):
        """Test that the name can be unicode.

        In Python 3, str == unicode. This test is really only interesting in Python 2.
        """
        if tests_base.IS_PY3:
            name = tests_base.make_name()
        else:
            name = unicode(tests_base.make_name(), 'ASCII')
        mem = posix_ipc.SharedMemory(name, posix_ipc.O_CREX, size=4096)
        self.assertEqual(name, mem.name)
        mem.close_fd()
        mem.unlink()
Beispiel #5
0
    def test_name_as_bytes(self):
        """Test that the name can be bytes.

        In Python 2, bytes == str. This test is really only interesting in Python 3.
        """
        if tests_base.IS_PY3:
            name = bytes(tests_base.make_name(), 'ASCII')
        else:
            name = bytes(tests_base.make_name())
        mem = posix_ipc.SharedMemory(name, posix_ipc.O_CREX, size=4096)
        # No matter what the name is passed as, posix_ipc.name returns the default string type,
        # i.e. str in Python 2 and unicode in Python 3.
        if tests_base.IS_PY3:
            self.assertEqual(name, bytes(mem.name, 'ASCII'))
        else:
            self.assertEqual(name, mem.name)
        mem.close_fd()
        mem.unlink()
        def test_name_as_bytes(self):
            """Test that the name can be bytes.

            In Python 2, bytes == str. This test is really only interesting in Python 3.
            """
            if tests_base.IS_PY3:
                name = bytes(tests_base.make_name(), 'ASCII')
            else:
                name = bytes(tests_base.make_name())
            mq = posix_ipc.MessageQueue(name, posix_ipc.O_CREX)
            # No matter what the name is passed as, posix_ipc.name returns the default string type,
            # i.e. str in Python 2 and unicode in Python 3.
            if tests_base.IS_PY3:
                self.assertEqual(name, bytes(mq.name, 'ASCII'))
            else:
                self.assertEqual(name, mq.name)
            mq.unlink()
            mq.close()
Beispiel #7
0
    def test_o_creat_new(self):
        """tests posix_ipc.O_CREAT to create a new semaphore without O_EXCL"""
        # I can't pass None for the name unless I also pass O_EXCL.
        name = tests_base.make_name()

        # Note: this method of finding an unused name is vulnerable to a race
        # condition. It's good enough for test, but don't copy it for use in
        # production code!
        name_is_available = False
        while not name_is_available:
            try:
                sem = posix_ipc.Semaphore(name)
                sem.close()
            except posix_ipc.ExistentialError:
                name_is_available = True
            else:
                name = tests_base.make_name()

        sem = posix_ipc.Semaphore(name, posix_ipc.O_CREAT)

        self.assertIsNotNone(sem)

        sem.unlink()
        def test_o_creat_new(self):
            """tests posix_ipc.O_CREAT to create a new MessageQueue without
            O_EXCL"""
            # I can't pass None for the name unless I also pass O_EXCL.
            name = tests_base.make_name()

            # Note: this method of finding an unused name is vulnerable to a
            # race condition. It's good enough for test, but don't copy it for
            # use in production code!
            name_is_available = False
            while not name_is_available:
                try:
                    mq = posix_ipc.MessageQueue(name)
                    mq.close()
                except posix_ipc.ExistentialError:
                    name_is_available = True
                else:
                    name = tests_base.make_name()

            mq = posix_ipc.MessageQueue(name, posix_ipc.O_CREAT)
            self.assertIsNotNone(mq)
            mq.close()
            mq.unlink()