Save
Saving
  • ghr

    Wait for async function to complete (invoke from sync function)

    yield asyncio.wait_for(self.close_session(), timeout=2)
    

    posted in Technology read more
  • ghr

    assert_called_once_with(*args, **kwargs)


    >>> mock = Mock(return_value=None)
    >>> mock('foo', bar='baz')
    >>> mock.assert_called_once_with('foo', bar='baz')
    >>> mock('other', bar='values')
    >>> mock.assert_called_once_with('other', bar='values')
    Traceback (most recent call last):
      ...
    AssertionError: Expected 'mock' to be called once. Called 2 times.
    

    Assert that the mock was called exactly once and that that call was with the specified arguments.

    posted in Technology read more
  • ghr

    Example

    @patch('time.time', MagicMock(return_value=1530667543.3568835))
    

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    from mymodule import rm
    
    import mock
    import unittest
    
    class RmTestCase(unittest.TestCase):
        
        @mock.patch('mymodule.os.path')
        @mock.patch('mymodule.os')
        def test_rm(self, mock_os, mock_path):
            # set up the mock
            mock_path.isfile.return_value = False
            
            rm("any path")
            
            # test that the remove call was NOT called.
            self.assertFalse(mock_os.remove.called, "Failed to not remove the file if not present.")
            
            # make the file 'exist'
            mock_path.isfile.return_value = True
            
            rm("any path")
            
            mock_os.remove.assert_called_with("any path")
    

    posted in Technology read more
  • ghr

    side_effect


    A useful attribute is side_effect. If you set this to an exception class or instance then the exception will be raised when the mock is called.

    >>> mock = Mock(side_effect=Exception('Boom!'))
    >>> mock()
    Traceback (most recent call last):
      ...
    Exception: Boom!
    

    posted in Technology read more
  • ghr

    Mock / MagicMock


    • Patch return value of a function.
    func1 = MagicMock(return=('POST', {} , '/add'}
    
    • Patch return value of object attribute.
    object.age = PropertyMock(return_value=34)
    

    posted in Technology read more
  • ghr

    $ git stash list

    $ git stash show (inspect)

    $ git stash apply (restore)

    $ git reset

    $ git add .

    Add files to staging area.

    $ git commit -m 'committing added changes'

    Commit changes with comment
    eg. git commit -m 'Alice: fix xyz bug. (ALICE-401)'

    $ git branch

    Show the name of current branch

    $ git checkout -b 'name of new branch'

    Create a new branch
    eg. git checkout -b 'alice-add-new-feature'

    $ git push

    git push origin 'alice-add-new-feature'
    git push origin 'alice-add-new-feature'--force

    $ git reset

    unstage all

    $ git commit --amend

    Changing last commit message.

    $ git diff --name-only HEAD~0 HEAD~2

    Display the list of files changed between 2 commits.

    $ git push --force-with-lease origin branch-name

    error: failed to push some refs to 'gitolite@gitlab.grass.corp:p/higgs.git'
    http://movingfast.io/articles/git-force-pushing/

    Check out one file from master.

    $ git checkout -- protobuf/emscentral.proto
    $ git checkout origin/master -- protobuf/emscentral.proto

    posted in Technology read more
  • ghr

    # plugin framework
    def start(self):
        """Start tracker engine.
        """
        if not self._loop.is_running():
            LOGGER.info('Run event loop forever')
            threading.Thread(target=self._loop.run_forever).start()
    
        if not self._is_started:
            self._loop.call_soon_threadsafe(
                asyncio.ensure_future, self._start()
            )
            LOGGER.info("Request progress tracker started")
            self._is_started = True
            return
    
        if self._is_paused:
            self._is_paused = False
        else:
            LOGGER.warning('Request progress tracker already started')
    

    posted in Technology read more

Looks like your connection to ghr was lost, please wait while we try to reconnect.