Example #1
0
def check_lib():
    if utils.is_brewblox_cwd() \
        and not utils.path_exists('./brewblox_ctl_lib/__init__.py') \
            and utils.confirm(
                'brewblox-ctl requires extensions that match your Brewblox release. ' +
                'Do you want to download them now?'):
        utils.load_ctl_lib(utils.ContextOpts(dry_run=False, verbose=True))
Example #2
0
def mocked_opts(mocker):
    opts = utils.ContextOpts()
    mocker.patch(TESTED + '.ctx_opts').return_value = opts
    return opts
Example #3
0
def test_sh(mocker):
    m_run = mocker.patch(TESTED + '.run')
    m_secho = mocker.patch(TESTED + '.click.secho')
    m_opts = mocker.patch(TESTED + '.ctx_opts').return_value

    m_opts.dry_run = False
    m_opts.verbose = False

    # Single call
    utils.sh('do things')
    assert m_secho.call_count == 0
    assert m_run.call_count == 1
    m_run.assert_called_with('do things',
                             shell=True,
                             check=True,
                             universal_newlines=False,
                             stdout=None,
                             stderr=STDOUT)

    m_run.reset_mock()
    m_secho.reset_mock()

    # Unchecked call
    utils.sh('do naughty things', check=False)
    assert m_secho.call_count == 0
    assert m_run.call_count == 1
    m_run.assert_called_with('do naughty things',
                             shell=True,
                             check=False,
                             universal_newlines=False,
                             stdout=None,
                             stderr=DEVNULL)

    m_run.reset_mock()
    m_secho.reset_mock()

    # Captured call
    utils.sh('gimme gimme', capture=True)
    assert m_secho.call_count == 0
    assert m_run.call_count == 1
    m_run.assert_called_with('gimme gimme',
                             shell=True,
                             check=True,
                             universal_newlines=True,
                             stdout=PIPE,
                             stderr=STDOUT)

    m_run.reset_mock()
    m_secho.reset_mock()

    # Dry run
    utils.sh('invisible shenannigans', utils.ContextOpts(dry_run=True))
    assert m_secho.call_count == 1
    assert m_run.call_count == 0

    m_run.reset_mock()
    m_secho.reset_mock()

    # List of commands
    utils.sh(['do this', 'and this', 'and that'])
    assert m_secho.call_count == 0
    assert m_run.call_count == 3

    m_run.reset_mock()
    m_secho.reset_mock()

    # Generator
    def generate():
        yield 'first'
        yield 'second'

    m_run.reset_mock()
    utils.sh(generate(), utils.ContextOpts(verbose=True))
    assert m_secho.call_count == 2
    assert m_run.call_count == 2
    m_run.assert_any_call('first',
                          shell=True,
                          check=True,
                          universal_newlines=False,
                          stdout=None,
                          stderr=STDOUT)
    m_run.assert_called_with('second',
                             shell=True,
                             check=True,
                             universal_newlines=False,
                             stdout=None,
                             stderr=STDOUT)