test release

Here are the examples of how to test release in python. These are taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

30 Examples 7

    def test_release(self):
        mocked_close = MagicMock()
        mocked_close.return_value = "magic"

        with patch('gitfs.views.passthrough.os.close', mocked_close):
            view = PassthroughView(repo=self.repo, repo_path=self.repo_path)
            result = view.release("/magic/path", 0)

            assert result == "magic"
            mocked_close.assert_called_once_with(0)

3
File: test_lock.py, Project: silverberg, View license
uses: uuid.uuid1
    def test_release(self):
        lock_uuid = uuid.uuid1()

        lock = BasicLock(self.client, self.table_name, lock_uuid)
        expected = [
            'DELETE FROM lock WHERE "lockId"=:lockId AND "claimId"=:claimId;',
            {'lockId': lock_uuid, 'claimId': lock._claim_id}, 2]

        d = lock.release()

        self.assertFired(d)
        self.client.execute.assert_called_once_with(*expected)

3
File: test_netns.py, Project: pyroute2, View license
uses: os.O_CREAT
    def test_release(self):
        require_user('root')
        nsid = self.alloc_nsname()
        nsp = NSPopen(nsid, ['true'], flags=os.O_CREAT, stdout=subprocess.PIPE)
        nsp.communicate()
        nsp.wait()
        nsp.release()
        try:
            print(nsp.returncode)
        except RuntimeError:
            pass

3
File: test_pools.py, Project: kombu, View license
uses: case.Mock
    def test_release(self):
        p = Mock()
        p.channel = Mock()
        p.__connection__ = Mock()
        self.pool.release(p)
        p.__connection__.release.assert_called_with()
        assert p.channel is None

    def test_release(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    loop=self.loop)

        async def go():
            self.assertEqual(len(pool.pool), 0)
            c1 = await pool.acquire()
            self.assertEqual(len(pool._acquired), 1)
            await pool.release(c1)
            self.assertEqual(len(pool.pool), 1)
            self.assertEqual(len(pool._acquired), 0)
            await c1.close()
        self.loop.run_until_complete(go())

    def test_release(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    loop=self.loop,
                    future_class=Future)

        @asyncio.coroutine
        def go():
            self.assertEqual(len(pool.pool), 0)
            c1 = yield from pool.acquire()
            self.assertEqual(len(pool._acquired), 1)
            yield from pool.release(c1)
            self.assertEqual(len(pool.pool), 1)
            self.assertEqual(len(pool._acquired), 0)

        self.loop.run_until_complete(go())

    def test_release(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    loop=self.loop,
                    future_class=Future)

        async def go():
            self.assertEqual(len(pool.pool), 0)
            c1 = await pool.acquire()
            self.assertEqual(len(pool._acquired), 1)
            await pool.release(c1)
            self.assertEqual(len(pool.pool), 1)
            self.assertEqual(len(pool._acquired), 0)

        self.loop.run_until_complete(go())

    @gen_test
    def test_release(self):
        pool = Pool("ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password")
        self.assertEqual(len(pool.pool), 0)
        c1 = yield pool.acquire()
        self.assertEqual(len(pool._acquired), 1)
        yield pool.release(c1)
        self.assertEqual(len(pool.pool), 1)
        self.assertEqual(len(pool._acquired), 0)

    def test_release(self):
        pool = Pool("ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    loop=self.loop,
                    future_class=Future)

        async def go():
            self.assertEqual(len(pool.pool), 0)
            c1 = await pool.acquire()
            self.assertEqual(len(pool._acquired), 1)
            await pool.release(c1)
            self.assertEqual(len(pool.pool), 1)
            self.assertEqual(len(pool._acquired), 0)

        self.loop.run_sync(go)

    def test_release(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    loop=self.loop,
                    future_class=Future)

        @trollius.coroutine
        def go():
            self.assertEqual(len(pool.pool), 0)
            c1 = yield From(pool.acquire())
            self.assertEqual(len(pool._acquired), 1)
            yield From(pool.release(c1))
            self.assertEqual(len(pool.pool), 1)
            self.assertEqual(len(pool._acquired), 0)

        self.loop.run_until_complete(go())

@pytest.mark.run_loop
def test_release(pool_creator):
    pool = yield from pool_creator()
    conn = yield from pool.acquire()
    assert 0 == pool.freesize
    assert {conn} == pool._used
    pool.release(conn)
    assert 1 == pool.freesize
    assert not pool._used

@vcr.use_cassette('tests/fixtures/cassettes/api/artifact/list.yml')
def test_release(artifact):
    response = artifact.list()

    assert response.is_ok
    assert response.content_type == 'application/json'
    assert len(response.payload) == 3
    assert set(x['name'] for x in response) == set(['cruise-output', 'foo', 'output.txt'])
    foo = next(x for x in response if x['name'] == 'foo')
    assert len(foo['files']) == 2

@vcr.use_cassette('tests/fixtures/cassettes/api/pipeline/release-successful.yml')
def test_release(locked_pipeline):
    response = locked_pipeline.release()

    assert response.is_ok
    assert response.content_type == 'text/html'
    assert response.payload.decode('utf-8') == 'pipeline lock released for {0}\n'.format(
        locked_pipeline.name
    )

    def test_release(self):
        ip = mf.IPv4AddressFactory(userid="user1", floating_ip=True, nic=None)
        with mocked_quotaholder():
            response = self.delete(URL + "/%s" % ip.id, ip.userid)
        self.assertSuccess(response)
        ips_after = floating_ips.filter(id=ip.id)
        self.assertEqual(len(ips_after), 0)

def test_release(connector, key, request, transport, protocol, loop):
    conn = Connection(connector, key, request,
                      transport, protocol, loop)
    assert not conn.closed
    conn.release()
    assert not transport.close.called
    assert conn._transport is None
    connector._release.assert_called_with(
        key, request, transport, protocol,
        should_close=False)
    assert conn.closed

@asyncio.coroutine
def test_release(loop):
    response = ClientResponse('get', URL('http://def-cl-resp.org'))
    response._post_init(loop)
    fut = helpers.create_future(loop)
    fut.set_result(b'')
    content = response.content = mock.Mock()
    content.readany.return_value = fut

    yield from response.release()
    assert response._connection is None

def test_release(loop):
    loop.time = mock.Mock(return_value=10)

    conn = aiohttp.BaseConnector(loop=loop)
    conn._start_cleanup_task = unittest.mock.Mock()
    req = unittest.mock.Mock()
    resp = req.response = unittest.mock.Mock()
    resp._should_close = False

    tr, proto = unittest.mock.Mock(), unittest.mock.Mock()
    key = 1
    conn._acquired[key].add(tr)
    conn._release(key, req, tr, proto)
    assert conn._conns[1][0] == (tr, proto, 10)
    assert conn._start_cleanup_task.called
    conn.close()

    def test_release(self):
        lock = SHLock()
        self.assertRaises(LockingError, lock.release)

        def get_lock(shared):
            lock.acquire(shared=shared)
            time.sleep(1)
            lock.release()

        threads = [Thread(target=get_lock, args=(x,)) for x in (True,
            False)]
        for t in threads:
            t.daemon = True
            t.start()
            self.assertRaises(LockingError, lock.release)
            t.join(4)
            self.assertFalse(t.is_alive())
        self.assertFalse(lock.is_shared)
        self.assertFalse(lock.is_exclusive)

    def test_release(self):
        release_id = '0.0.2'
        release = self.json['releases'][release_id]
        release_list = [Release(release_id, r) for r in release]
        self.assertEquals(release_list[0].md5_digest,
                          self.package.release(release_id)[0].md5_digest)
        self.assertEquals(release_list[1].md5_digest,
                          self.package.release(release_id)[1].md5_digest)
        self.assertEquals('3e3098611177c34706de2e10476b3e50',
                          self.package.release(release_id)[0].md5_digest)
        self.assertEquals('be198baa95116c1c9d17874428e3a0c6',
                          self.package.release(release_id)[1].md5_digest)

    def test_release(self):
        with mock.patch.object(self.dbapi, 'release_node',
                               autospec=True) as mock_release:
            node_id = self.fake_node['id']
            fake_tag = 'fake-tag'
            objects.Node.release(self.context, fake_tag, node_id)
            mock_release.assert_called_once_with(fake_tag, node_id)

    def test_release(self, get_lock_mock):
        node_info = node_cache.NodeInfo(self.uuid)
        node_info.acquire_lock()
        self.assertTrue(node_info._locked)
        node_info.release_lock()
        self.assertFalse(node_info._locked)
        node_info.release_lock()
        self.assertFalse(node_info._locked)
        get_lock_mock.return_value.acquire.assert_called_once_with(True)
        get_lock_mock.return_value.release.assert_called_once_with()

    def test_release(self):
        res = platform.release()

    def test_release(self):
        lock = sherlock.RedisLock(self.lock_name)
        lock._acquire()
        lock._release()
        self.assertEqual(self.client.get(self.lock_name), None)

    def test_release(self):
        lock = sherlock.EtcdLock(self.lock_name)
        lock._acquire()
        lock._release()
        self.assertRaises(etcd.EtcdKeyNotFound, self.client.get, self.lock_name)

    def test_release(self):
        lock = sherlock.MCLock(self.lock_name)
        lock._acquire()
        lock._release()
        self.assertEqual(self.client.get(self.lock_name), None)

    def test_release(self, fcntl_mock, tmpdir):
        """
        Tests for release method
        """

        # Test 1: normal release

        # Use a lock file inside the testing tempdir
        lock_file_path = tmpdir.join("test_lock_file1")
        # set flock to not raise
        _prepare_fnctl_mock(fcntl_mock)
        lock_file = LockFile(lock_file_path.strpath,
                             raise_if_fail=False,
                             wait=False)
        assert lock_file.acquire()

        # set flock to not raise
        _prepare_fnctl_mock(fcntl_mock)
        # Release the lock
        lock_file.release()
        # Check that the fcntl.flock() have been called using the flag LOCK_UN
        fcntl_mock.flock.assert_called_once_with(ANY, fcntl.LOCK_UN)

        # Test 2: release an already released lock

        # set flock to not raise
        _prepare_fnctl_mock(fcntl_mock)
        # Try to release the lock again
        lock_file.release()
        # The release method should not have called fcntl.flock()
        assert not fcntl_mock.flock.called

        # Test 3: exceptions during release

        # set flock to not raise
        _prepare_fnctl_mock(fcntl_mock)
        lock_file = LockFile(lock_file_path.strpath,
                             raise_if_fail=False,
                             wait=False)
        assert lock_file.acquire()

        # set flock to raise an OSError (no matter what)
        _prepare_fnctl_mock(fcntl_mock, OSError(errno.EBADF, '', ''))
        # Release the lock (should not raise any error)
        lock_file.release()
        # Check that the fcntl.flock() have been called using the flag LOCK_UN
        fcntl_mock.flock.assert_called_once_with(ANY, fcntl.LOCK_UN)

    def test_release(self):
        self.assertTrue(models.Lock.grab("cb", "i-1234"))
        self.assertTrue(models.Lock.release("cb", "i-1234"))
        self.assertTrue(models.Lock.grab("cb", "i-7890"))

    def test_release(self):
        embed_video.VERSION = ('a', 'b', 'c', 'd')
        self.assertEqual('a.b.c-d', embed_video.get_release())

    def test_release(self):
        aserver_api = mock.MagicMock()
        aserver_api.release.return_value = 'release'
        uploader = Uploader(aserver_api, 'notebook')
        self.assertEqual(uploader.release, 'release')

    def test_release(self):
        version = '0.2.4'
        self.assertTrue(is_release_version(version))